You can build agnostic code in Puppet and pull operating system specifics from Hiera. For example:
#ls -l hieradata/ total 4 -rw-r--r-- 1 root root 872 Feb 12 18:28 common.yaml drwxr-xr-x 1 root root 0 Feb 28 12:31 nodes drwxr-xr-x 1 root root 68 Feb 28 12:31 os #ls -lR hieradata/os hieradata/os: total 0 drwxr-xr-x 1 root root 20 Feb 28 12:33 arch -rw-r--r-- 1 root root 0 Feb 28 12:31 debian.yaml -rw-r--r-- 1 root root 0 Feb 28 12:31 redhat.yaml -rw-r--r-- 1 root root 0 Feb 28 12:31 windows.yaml hieradata/os/arch: total 0 drwxr-xr-x 1 root root 0 Feb 28 12:33 i386 drwxr-xr-x 1 root root 22 Feb 28 12:35 amd64 hieradata/os/arch/i386: total 0 hieradata/os/arch/amd64: total 0 -rw-r--r-- 1 root root 0 Feb 28 12:34 redhat.yaml #cat hieradata/os/arch/x86_64/redhat.yaml --- ssh::server::sftppath: '/usr/lib64/ssh/sftp-server' Then create your hiera.yaml file: --- version: 5 default: datadir: "hieradata" data_hash: yaml_data hierarchy: - name: "Node specifics" path: "nodes/%{::trusted.certname}.yaml" - name: "Operating system specifics" paths: - "os/%{facts.os.family}.yaml" - "os/arch/%{facts.os.architecture}/%{facts.os.family}.yaml" - name: "Common defaults" path: "common.yaml" You'll want to verify a few items: - You may want to use different facts. Take a look at the os map <https://docs.puppet.com/facter/latest/core_facts.html#os> (or any other fact for that matter). - Make sure the values of the facts are correct. I just pulled those after some very quick checking. Run "puppet facts" on each machine type and match up the actual value that returns. - Make sure your merge strategy is appropriate to what you want. In the example above I can specify ssh::server::sftppath at the ./os/redhat.yaml and ./os/arch/amd64/redhat.yaml version. You can define a default for all redhat operating systems at the higher level and then a specific architecture path at the lower level. based on your merge strategy puppet will return different values. Then just call lookup in your code: lookup('ssh::server::sftppath', String, 'unique', '/usr/lib/ssh/sftp-server' ) One last note, even with this strategy it can still be tricky to write agnostic code that will work between Windows and Linux as the environments between those two operating systems are so different, but you can modularize at least some of the code. On Friday, September 30, 2011 at 12:33:50 PM UTC-6, Jeff Falgout wrote: > > We're in the situation of dealing with multiple operating systems (and > will likely add another) and I'm quickly realizing that building logic in > the manifest to deal with the differences in Red Hat i386 vs Red Hat x86_64 > vs SuSE i586 vs SuSE x86_64 vs Mac is getting tedious. For instance, in the > sshd_config: > > SLES i586 has the sftp-server binary in a different path than the x86_64 > version and it's different than RHEL - so I end up with logic as such: > > # Set the SFTP Path > if $lsbdistid == 'SUSE LINUX' { > if $architecture == 'x86_64' { > $sftppath = '/usr/lib64/ssh/sftp-server' > } else { > $sftppath = '/usr/lib/ssh/sftp-server' > } > } else { > $sftppath = "/usr/libexec/openssh/sftp-server" > } > > > Is there a better way to deal with different OS's or is the long and > winding road of config mgmt? > > Do people do something like: > > include ssh::server::$operatingsystem > > class ssh::server::RedHat { > blah > } > > class ssh::server::SLES { > blah > } > > > Different modulepath? Different puppet servers based on OS? > > Cheers, > > Jeff > -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/404c613c-c9b5-4d3e-b88b-eaf34c8212b3%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.