Skip to content

service.pp

Kevin Chang edited this page Aug 9, 2016 · 1 revision

service.pp

service.pp runs the examples with variables passed from init.pp.

$ilo_ip       = $ilorest::ilo_ip
$ilo_username = $ilorest::ilo_username
$ilo_password = $ilorest::ilo_password

service.pp takes variables from init.pp since it is the top-level $ilorest. This way we can ensure it is taking the variables passed when a class is declared in the node definition.

Again, there is a check for operating system with a conditional to ensure that directory structure is correct.

if $osfamily == 'Debian' {

We set a template for future exec commands by declaring all the parameters first in Exec[]. We ensure that python can be run by point to the path, incase environmental variables were not set. Additionally, the cwd points to the directory we just copied the ilorest files to. Setting require forces the required command to be run first before this can be executed. In this case, we can requiring the dependancies to be present before attempting to execute the examples.

Exec {
  path      => '/usr/bin',
  cwd       => '/etc/puppetlabs/code/environments/production/modules/ilorest/files',
  logoutput => true,
  loglevel  => notice,
  require   => File['/etc/puppetlabs/code/environments/production/modules/ilorest/files'],
}

Lastly, we run the examples by calling them. We must use double quotes in this command line to allow the usage of variables. They are written in ${variablename} format. The -> is an ordering arrow, telling Puppet what order to execute commands. By default, Puppet will run in the order the resources are declared, but it is still best practice to declare an order.

exec { 'ex09':
  command   => "python ex09_find_ilo_mac_address.py ${ilo_ip} ${ilo_username} ${ilo_password}",
} ->
Clone this wiki locally