How can I accomplish the following in puppet? If /etc/file1 contains string abc then copy SSHTemplate1 to /etc/ssh/ssh_config && copy SSHDTemplate1 to /etc/ssh/sshd_config else if /etc/file1 contains string xyz then copy SSHtemplate2 to /etc/ssh/ssh_config && copy SSHDTemplate2 to /etc/ssh/sshd_config else copy SSHtemplate3 to /etc/ssh/ssh_config && copy SSHDTemplate3 to /etc/ssh/sshd_config I have to apply this logic multiple operating systems in a Puppet script So far this is what I have... class ssh { case $::operatingsystem { ''AIX'': { $owner = ''root'' $group = ''system'' } ''FreeBSD'': { $owner = ''root'' $group = ''wheel'' } default: { $owner = ''root'' $group = ''root'' } } file { ''/etc/ssh/sshd_config'': ensure => present, owner => $owner, group => $group, mode => ''0644'', backup => false, content => template("ssh/etc/ssh/sshd_config.erb"), } file { ''/etc/ssh/ssh_config'': ensure => present, owner => $owner, group => $group, mode => ''0644'', backup => false, content => template("ssh/etc/ssh/ssh_config.erb"), } file { ''/etc/issue.net'': ensure => present, owner => $owner, group => $group, mode => ''0644'', backup => false, content => template("motd/etc/issue.erb"), } } Does that look right? And how to add the the conditional logic above to this template? Thanks in advance!! -- 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+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
Sneha More
2013-Sep-20 10:08 UTC
[Puppet Users] Re: Puppet multiple conditional statement...
Hi John, For conditional logic, you can use facts. In your case, you need to create a fact for reading file /etc/file1. you can create a fact in your fact directory, file_content.rb -> Facter.add("file_content") do setcode do Facter::Util::Resolution.exec(''cat /etc/file1'') end end But this file "/etc/file1" should be present on your client also, so transfer this file first. Now you can add this in your manifest, if $file_content == "abc" { file { ''/etc/ssh/sshd_config'': ensure => present, owner => $owner, group => $group, mode => ''0644'', backup => false, content => template("SSHDT Template1"), } file { ''/etc/ssh/ssh_config'': ensure => present, owner => $owner, group => $group, mode => ''0644'', backup => false, content => template("SSHT Template 1"), } } elsif $file_content == "xyz" { file { ''/etc/ssh/sshd_config'': ensure => present, owner => $owner, group => $group, mode => ''0644'', backup => false, content => template("SSHDT Template2"), } file { ''/etc/ssh/ssh_config'': ensure => present, owner => $owner, group => $group, mode => ''0644'', backup => false, content => template("SSHT Template 2"), } } else { file { ''/etc/ssh/sshd_config'': ensure => present, owner => $owner, group => $group, mode => ''0644'', backup => false, content => template("SSHDT Template3"), } file { ''/etc/ssh/ssh_config'': ensure => present, owner => $owner, group => $group, mode => ''0644'', backup => false, content => template("SSHT Template 3"), } } I hope this will help you. Thanks & Regards, Sneha More, NTT DATA GTS, OSS Centre, India (Pune). On Thursday, September 19, 2013 8:04:38 PM UTC+5:30, John wrote:> > How can I accomplish the following in puppet? > > If /etc/file1 contains string abc > then copy SSHTemplate1 to /etc/ssh/ssh_config && copy SSHDTemplate1 to > /etc/ssh/sshd_config > else if /etc/file1 contains string xyz > then copy SSHtemplate2 to /etc/ssh/ssh_config && copy SSHDTemplate2 to > /etc/ssh/sshd_config > else copy SSHtemplate3 to /etc/ssh/ssh_config && copy SSHDTemplate3 to > /etc/ssh/sshd_config > > I have to apply this logic multiple operating systems in a Puppet script > > So far this is what I have... > > class ssh { > case $::operatingsystem { > ''AIX'': { > $owner = ''root'' > $group = ''system'' > } > ''FreeBSD'': { > $owner = ''root'' > $group = ''wheel'' > } > default: { > $owner = ''root'' > $group = ''root'' > } > } > > file { ''/etc/ssh/sshd_config'': > ensure => present, > owner => $owner, > group => $group, > mode => ''0644'', > backup => false, > content => template("ssh/etc/ssh/sshd_config.erb"), > } > > file { ''/etc/ssh/ssh_config'': > ensure => present, > owner => $owner, > group => $group, > mode => ''0644'', > backup => false, > content => template("ssh/etc/ssh/ssh_config.erb"), > } > > file { ''/etc/issue.net'': > ensure => present, > owner => $owner, > group => $group, > mode => ''0644'', > backup => false, > content => template("motd/etc/issue.erb"), > } > } > > Does that look right? And how to add the the conditional logic above to > this template? Thanks in advance!! >-- 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+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.