Skip to content

Instantly share code, notes, and snippets.

@three18ti
Created May 23, 2012 02:17
Show Gist options
  • Save three18ti/2772865 to your computer and use it in GitHub Desktop.
Save three18ti/2772865 to your computer and use it in GitHub Desktop.
puppet-configserver-firewall
Facter.add("configserver_firewall") do
has_weight 100
setcode do
if File.exist? "/etc/init.d/csf"
"true"
else
"false"
end
end
end
root@puppet:~# grep configserver /var/lib/puppet/yaml/node/sidious.yaml
configserver_firewall: "false"
root@puppet:~# ssh sidious puppet agent --test
stdin: is not a tty
info: Retrieving plugin
info: Loading facts in /var/lib/puppet/lib/facter/cpanel.rb
info: Loading facts in /var/lib/puppet/lib/facter/configserver_firewall.rb
info: Caching catalog for sidious
info: Applying configuration version '1337739347'
notice: /Stage[main]/Cpanel/Exec[disable_selinux]/returns: executed successfully
notice: /Stage[main]/Configserver-firewall/Exec[enter-class-configserver-firewall]/returns: false fact: false
notice: /Stage[main]/Configserver-firewall/Exec[enter-class-configserver-firewall]/returns: executed successfully
notice: Finished catalog run in 0.23 seconds
class configserver-firewall {
exec { 'enter-class-configserver-firewall':
command => "echo $configserver_firewall fact: ${configserver_firewall}",
path => '/bin',
logoutput => true,
}
if ! $configserver_firewall {
exec { 'enter-if-block':
command => "echo Didn't get here ${configserver_firewall}",
path => '/bin',
logoutput => true,
}
exec { 'download_csf':
command => 'wget http://www.configserver.com/free/csf.tgz -O /root/csf.tgz',
path => '/usr/bin',
creates => '/root/csf.tgs',
logoutput => true,
}
exec { 'unzip_csf':
command => 'tar vxzf /root/csf.tgz',
path => '/bin/',
creates => '/root/csf/',
require => Exec['download_csf'],
logoutput => true,
}
exec { 'install_csf':
command => 'sh /root/csf/install.sh',
cwd => '/root/csf/',
path => '/bin/',
require => Exec['unzip_csf'],
creates => '/etc/init.d/csf',
logoutput => true,
}
exec { 'cleanup_install_files':
command => 'rm -rf /root/csf/ /root/csf.tgz',
path => '/bin/',
require => Exec['install_csf'],
logoutput => true,
}
}
}
@BipinXavier
Copy link

The above code doesn't work for me, some logical mistakes as well as syntax issue. The modified code is give below.

class configserver_firewall {
exec { 'enter-class-configserver_firewall':
command => "echo $configserver_firewall fact: ${configserver_firewall}",
path => '/bin',
logoutput => true,
}

if ! $configserver_firewall {                                               
    exec { 'enter-if-block':                                                
        command => "echo Didnt get here ${configserver_firewall}",          
        path    => '/bin',                                                  
        logoutput => true,                                                  
    }                                                                       
  }                                                                         

if $configserver_firewall == 'false' {

exec { 'download_csf':
        command => 'wget http://www.configserver.com/free/csf.tgz -O /tmp/csf.tgz',
        path    => '/usr/bin',
        creates => '/tmp/csf.tgz',
        logoutput => true,
    }

exec { 'unzip_csf':
        command => 'tar vxzf /tmp/csf.tgz -C /tmp',
        path    => '/bin/',
        creates => '/tmp/csf/',
        require => Exec['download_csf'],
        logoutput => true,
    }

exec { 'install_csf':
        command => 'sh /tmp/csf/install.sh',
        cwd     => '/tmp/csf/',
        path    => '/bin/',
        require => Exec['unzip_csf'],
        creates => '/etc/init.d/csf',
        logoutput => true,
    }

exec { 'cleanup_install_files':
        command => 'rm -rf /tmp/csf/ /tmp/csf.tgz',
        path    => '/bin/',
        require => Exec['install_csf'],
        logoutput => true,
    }
}

}

include configserver_firewall

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment