13.07.2015 Views

Linux System Administration Recipes A Problem-Solution Approach

Linux System Administration Recipes A Problem-Solution Approach

Linux System Administration Recipes A Problem-Solution Approach

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 3 ■ MONITORING AND UPDATINGThere are three types of conditionals in Puppet:• Selectors, which are used within a statement:package {"krb-clients":ensure => $operatingsystem ? {ubuntu => absent,debian => installed,default => undef};}Here, if the $operatingsystem fact is set to ubuntu, the package is not installed; ifit’s set to debian, it is installed. The default is to not do anything at all. Note thelack of comma on the final line.• case statements provide a way of conditionally applying classes:case $operatingsystem {ubuntu: { include ubuntu }debian: { include debian }default: { include basic }}In this snippet, the class specific to each operating system is included dependingagain on the value of the $operatingsystem fact. Multiple conditions can bespecified using a comma.• A simple if/else structure:if $needexample {file { "/usr/local/example": ensure => present }}else {file { "/usr/local/test": ensure => present }}Currently it is possible to determine only whether the variable is or is not set, notto distinguish between particular values of a variable—for that, you must use thecase or selector statements.A template uses Ruby to put variables into a source file. In other words, it’s like providing a centralfile that can vary machine by machine.A good example of using a fact in a template is to set an ipchains policy. The following file,iptables.erb (ERB is the Ruby template syntax), uses $ipaddress:*filter:INPUT DROP [0:0]:FORWARD DROP [0:0]:OUTPUT ACCEPT [0:0]-A INPUT -d 127.0.0.0/255.0.0.0 -i ! lo -p tcp -j DROP-A INPUT -d -m state --state RELATED,ESTABLISHED -j ACCEPT-A INPUT -i lo -j ACCEPT89Download at WoweBook.Com

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!