Skip to content

Commit

Permalink
fix validate_cmd for yaml, update tests and add validate file name.
Browse files Browse the repository at this point in the history
  • Loading branch information
MemberIT committed Aug 11, 2016
1 parent a8f1a48 commit bcca8dd
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
4 changes: 2 additions & 2 deletions manifests/fact.pp
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
include ::puppet::defaults
$facterbasepath = $::puppet::defaults::facterbasepath

validate_string($title)
validate_re($title, '^[0-9A-Za-z_\-]+$', 'The $title fact does not match ^[0-9A-Za-z_\-]+$')
$facter_data = { "${title}" => $value }

file { "${facterbasepath}/facts.d/${title}.yaml":
ensure => $ensure,
owner => 'root',
group => 'puppet',
mode => '0640',
validate_cmd => "/usr/bin/env ruby -ryaml -e \"YAML.load_file '<afile>'\"",
validate_cmd => "/usr/bin/env ruby -ryaml -e \"YAML.load_file '%'\"",
content => template('puppet/fact.yaml.erb'),
}

Expand Down
2 changes: 1 addition & 1 deletion manifests/facts.pp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
owner => 'root',
group => 'puppet',
mode => '0640',
validate_cmd => "/usr/bin/env ruby -ryaml -e \"YAML.load_file '<afile>'\"",
validate_cmd => "/usr/bin/env ruby -ryaml -e \"YAML.load_file '%'\"",
content => template('puppet/local_facts.yaml.erb'),
}

Expand Down
10 changes: 10 additions & 0 deletions spec/classes/puppet_facts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@
/facts for my.client.cert/
).with_content(
/FQDN my.fq.hostname/
).with_validate_cmd(
"/usr/bin/env ruby -ryaml -e \"YAML.load_file '%'\""
)#.with_content(
# /Environment production/
#)
Expand All @@ -106,6 +108,8 @@
/FQDN my.fq.hostname/
).with_content(
/Environment production/
).with_validate_cmd(
"/usr/bin/env ruby -ryaml -e \"YAML.load_file '%'\""
)
end
end
Expand All @@ -119,6 +123,8 @@
/key1: val1/
).with_content(
/key2: val2/
).with_validate_cmd(
"/usr/bin/env ruby -ryaml -e \"YAML.load_file '%'\""
)
end
end#custom_facts set key values is string
Expand All @@ -139,6 +145,8 @@
/- val21/
).with_content(
/- val22/
).with_validate_cmd(
"/usr/bin/env ruby -ryaml -e \"YAML.load_file '%'\""
)
end
end#custom_facts set key values is array
Expand All @@ -155,6 +163,8 @@
/key2:/
).with_content(
/key21: val21/
).with_validate_cmd(
"/usr/bin/env ruby -ryaml -e \"YAML.load_file '%'\""
)
end
end#custom_facts set key values is hash
Expand Down
6 changes: 6 additions & 0 deletions spec/defines/fact_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@
/---/
).with_content(
/my_fact: my_val/
).with_validate_cmd(
"/usr/bin/env ruby -ryaml -e \"YAML.load_file '%'\""
)
end
end
Expand All @@ -132,6 +134,8 @@
/- my_val0/
).with_content(
/- my_val1/
).with_validate_cmd(
"/usr/bin/env ruby -ryaml -e \"YAML.load_file '%'\""
)
end
end
Expand All @@ -155,6 +159,8 @@
/my_key0: my_val0/
).with_content(
/my_key1: my_val1/
).with_validate_cmd(
"/usr/bin/env ruby -ryaml -e \"YAML.load_file '%'\""
)
end
end
Expand Down

0 comments on commit bcca8dd

Please sign in to comment.