Skip to content

Commit bcca8dd

Browse files
committed
fix validate_cmd for yaml, update tests and add validate file name.
1 parent a8f1a48 commit bcca8dd

4 files changed

Lines changed: 19 additions & 3 deletions

File tree

manifests/fact.pp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
include ::puppet::defaults
1111
$facterbasepath = $::puppet::defaults::facterbasepath
1212

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

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

manifests/facts.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
owner => 'root',
2222
group => 'puppet',
2323
mode => '0640',
24-
validate_cmd => "/usr/bin/env ruby -ryaml -e \"YAML.load_file '<afile>'\"",
24+
validate_cmd => "/usr/bin/env ruby -ryaml -e \"YAML.load_file '%'\"",
2525
content => template('puppet/local_facts.yaml.erb'),
2626
}
2727

spec/classes/puppet_facts_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@
9494
/facts for my.client.cert/
9595
).with_content(
9696
/FQDN my.fq.hostname/
97+
).with_validate_cmd(
98+
"/usr/bin/env ruby -ryaml -e \"YAML.load_file '%'\""
9799
)#.with_content(
98100
# /Environment production/
99101
#)
@@ -106,6 +108,8 @@
106108
/FQDN my.fq.hostname/
107109
).with_content(
108110
/Environment production/
111+
).with_validate_cmd(
112+
"/usr/bin/env ruby -ryaml -e \"YAML.load_file '%'\""
109113
)
110114
end
111115
end
@@ -119,6 +123,8 @@
119123
/key1: val1/
120124
).with_content(
121125
/key2: val2/
126+
).with_validate_cmd(
127+
"/usr/bin/env ruby -ryaml -e \"YAML.load_file '%'\""
122128
)
123129
end
124130
end#custom_facts set key values is string
@@ -139,6 +145,8 @@
139145
/- val21/
140146
).with_content(
141147
/- val22/
148+
).with_validate_cmd(
149+
"/usr/bin/env ruby -ryaml -e \"YAML.load_file '%'\""
142150
)
143151
end
144152
end#custom_facts set key values is array
@@ -155,6 +163,8 @@
155163
/key2:/
156164
).with_content(
157165
/key21: val21/
166+
).with_validate_cmd(
167+
"/usr/bin/env ruby -ryaml -e \"YAML.load_file '%'\""
158168
)
159169
end
160170
end#custom_facts set key values is hash

spec/defines/fact_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@
109109
/---/
110110
).with_content(
111111
/my_fact: my_val/
112+
).with_validate_cmd(
113+
"/usr/bin/env ruby -ryaml -e \"YAML.load_file '%'\""
112114
)
113115
end
114116
end
@@ -132,6 +134,8 @@
132134
/- my_val0/
133135
).with_content(
134136
/- my_val1/
137+
).with_validate_cmd(
138+
"/usr/bin/env ruby -ryaml -e \"YAML.load_file '%'\""
135139
)
136140
end
137141
end
@@ -155,6 +159,8 @@
155159
/my_key0: my_val0/
156160
).with_content(
157161
/my_key1: my_val1/
162+
).with_validate_cmd(
163+
"/usr/bin/env ruby -ryaml -e \"YAML.load_file '%'\""
158164
)
159165
end
160166
end

0 commit comments

Comments
 (0)