Ordering dependencies Puppet

Carlos Gómez
devops and cross platform development
1 min readMar 4, 2016

--

Puppet helps us to model a system state through a set of resources, including files, packages, and cron jobs, among others. But we should always be in control of all the configurations and one important thing among this is to handle the dependencies order in the correct way, Puppet DSL(domain-specific language) is declarative, which means that the manifest declares a set of resources that are expected to have certain properties, these resources are put into a catalog which describe what you expect the end result to be. To clarify this, let’s take a look at an example:

exec { 'apt-update':                    
command => '/usr/bin/apt-get update'
}
package { 'apache2':
ensure => installed,
}
service { 'apache2':
ensure => running,
}
With this manifest, Puppet will make sure that the following state is reached:
  • Execute apt-update.
  • The apache2 is installed.
  • The apache2 is started.
This steps must be performed in order because for example we can’t start a service without having it installed.

There are three ways to chaining resources:

  • Simple arrow between steps:
  • exec { ‘apt-update’:
    command => ‘/usr/bin/apt-get update’
    }
    ->
    package { ‘apache2’:
    ensure => installed,
    }
    ->
    service { ‘apache2’:
    ensure => running,
    }
  • Require metaparameter:
  • exec { ‘apt-update’:
    command => ‘/usr/bin/apt-get update’
    }
  • package { ‘apache2’:
    require => Exec[‘apt-update’],
    ensure => installed,
    }
  • service { ‘apache2’:
    ensure => running,
    }
  • Before metaparameter:
  • exec { ‘apt-update’:
    command => ‘/usr/bin/apt-get update’,
    before => Package[‘apache2’]
    }
  • package { ‘apache2’:
    ensure => installed,
    }
  • service { ‘apache2’:
    ensure => running,
    }

--

--

Cloud/Software Architect and DevOps learning about #devops, #cloud, #netcore, #microservices and #newtech