Created
April 4, 2019 12:28
-
-
Save b4ldr/3e972e86b522a53d5baf8fc305564d48 to your computer and use it in GitHub Desktop.
iterating lists in puppet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%- | |
@allow_parameters = { | |
'ALLOWDEVFILE' => '/dev/.udev/rules.d/root.rules', | |
'ALLOWIPCPROC' => '/usr/sbin/zabbix_agentd', | |
'ALLOWHIDDENFILE' => ['/dev/.initramfs', '/dev/.blkid.tab', '/dev/.blkid.tab.old'] | |
} | |
-%> | |
<%- @allow_parameters.each_pair do |key, value| -%> | |
<%- if value.kind_of?(String) -%> | |
<%= key %>=<%= value %> | |
<%- elsif value.kind_of?(Array) -%> | |
<%- value.each do |v| -%> | |
<%= key %>=<%= v %> | |
<%- end -%> | |
<%- end -%> | |
<%- end -%> | |
################## output ################ | |
erb -T '-' test.erb | |
ALLOWDEVFILE=/dev/.udev/rules.d/root.rules | |
ALLOWIPCPROC=/usr/sbin/zabbix_agentd | |
ALLOWHIDDENFILE=/dev/.initramfs | |
ALLOWHIDDENFILE=/dev/.blkid.tab | |
ALLOWHIDDENFILE=/dev/.blkid.tab.old |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$allow_parameters = { | |
'ALLOWDEVFILE' => '/dev/.udev/rules.d/root.rules', | |
'ALLOWIPCPROC' => '/usr/sbin/zabbix_agentd', | |
'ALLOWHIDDENFILE' => ['/dev/.initramfs', '/dev/.blkid.tab', '/dev/.blkid.tab.old'], | |
} | |
$allow_parameters.each |$key, $value| { | |
if $value =~ String { | |
notify {"${key}=${value}": } | |
} elsif $value =~ Array { | |
$value.each |$v| { | |
notify {"${key}=${v}": } | |
} | |
} | |
} | |
################## output ################ | |
puppet apply test.pp | |
Notice: Compiled catalog for work-laptop.home.arpa in environment production in 0.06 seconds | |
Notice: ALLOWDEVFILE=/dev/.udev/rules.d/root.rules | |
Notice: /Stage[main]/Main/Notify[ALLOWDEVFILE=/dev/.udev/rules.d/root.rules]/message: defined 'message' as 'ALLOWDEVFILE=/dev/.udev/rules.d/root.rules' | |
Notice: ALLOWIPCPROC=/usr/sbin/zabbix_agentd | |
Notice: /Stage[main]/Main/Notify[ALLOWIPCPROC=/usr/sbin/zabbix_agentd]/message: defined 'message' as 'ALLOWIPCPROC=/usr/sbin/zabbix_agentd' | |
Notice: ALLOWHIDDENFILE=/dev/.initramfs | |
Notice: /Stage[main]/Main/Notify[ALLOWHIDDENFILE=/dev/.initramfs]/message: defined 'message' as 'ALLOWHIDDENFILE=/dev/.initramfs' | |
Notice: ALLOWHIDDENFILE=/dev/.blkid.tab | |
Notice: /Stage[main]/Main/Notify[ALLOWHIDDENFILE=/dev/.blkid.tab]/message: defined 'message' as 'ALLOWHIDDENFILE=/dev/.blkid.tab' | |
Notice: ALLOWHIDDENFILE=/dev/.blkid.tab.old | |
Notice: /Stage[main]/Main/Notify[ALLOWHIDDENFILE=/dev/.blkid.tab.old]/message: defined 'message' as 'ALLOWHIDDENFILE=/dev/.blkid.tab.old' | |
Notice: Applied catalog in 0.02 seconds |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@allow_parameters = { | |
'ALLOWDEVFILE' => '/dev/.udev/rules.d/root.rules', | |
'ALLOWIPCPROC' => '/usr/sbin/zabbix_agentd', | |
'ALLOWHIDDENFILE' => ['/dev/.initramfs', '/dev/.blkid.tab', '/dev/.blkid.tab.old'], | |
} | |
@allow_parameters.each_pair do |key, value| | |
if value.kind_of?(String) | |
puts("#{key}=#{value}") | |
elsif value.kind_of?(Array) | |
value.each do |v| | |
puts("#{key}=#{v}") | |
end | |
end | |
end | |
################## output ################ | |
ruby test.rb | |
ALLOWDEVFILE=/dev/.udev/rules.d/root.rules | |
ALLOWIPCPROC=/usr/sbin/zabbix_agentd | |
ALLOWHIDDENFILE=/dev/.initramfs | |
ALLOWHIDDENFILE=/dev/.blkid.tab | |
ALLOWHIDDENFILE=/dev/.blkid.tab.old |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment