How to use .each in site.pp

My environment:

Oracle Linux V6.7 Puppet Agent 4.2.3 Puppet Server 2.1.2 Facter 3.1.1

I'm fairly new to Puppet and still finding my way through things.

I am using structured facts via key=value pairs in /opt/puppetlabs/facter/facts.d/myfacts.txt. This is working and I'm able to parse the local client facts as needed. However...I have one situation where I'm not being successful - when one fact will contain one or more values.

I have a local fact: my_role=["A", "B", "C"]

In my site.pp I am trying to do this:

$my_role.each |$specialrole| {
case $specialrole { 'A': { file {"/tmp/special_A": ensure => present, } } 'B': { file {"/tmp/special_B": ensure => present, } } 'C': { file {"/tmp/special_C": ensure => present, } } } }  I've tried several different permutations of the above setup but all without success. I'm not getting any syntax errors or any errors at all from puppet agent --test.....but I'm also not getting the results. Nothing happens. Note: the exact actions in each case are not all just a file/ensure action...I'm using the above only as an example of my end goal. A more realistic example would be a server that is both a database server and a web server. I want to do certain things for a db server; and other certain things for a web server. Any suggestions are quite welcome. There's probably a better way of achieving the desired results - I'm just not familiar enough with Puppet to know what else to do. Any suggestions or guidance is very welcome. Thank you. edit retag close merge delete 1 Answer Sort by » oldest newest most voted I finally figured it out. The local fact "my_role" needed to be explicitly converted to an array first. So my solution was to do this: $my_specialrole = split($my_role, ',')$my_specialrole.each |\$specialrole| {
and so forth


and it worked perfectly.

Not entirely sure this is 100% the "best" way to achieve my end goal but it works and I understand it.

more