This is a short presentation on the reasons why you would augment your Vagrant installation with a full-fledged provisioner like Puppet and some examples of basic things you can do with it.
2. What Vagrant is and what it isn’t
● Vagrant is a wrapper for Virtual Machine providers (VirtualBox, VMWare,
etc) .
● Vagrant can use provisioners, including shell scripts, puppet, chef and
others.
● Puppet (which we’ll cover here) is but one option of provisioners supported by
Vagrant; there are others like Chef, Ansible, Salt, etc.
● Vagrant is no configuration management tool.
3. What is Puppet and where does it fit in?
● Puppet can be seen series of system-level asserts. Puppet resources are
meant to be idempotent, i.e. stateless (just like HTTP).
● Puppet is a declarative language. In other words, it does not specify steps,
but states your system must be in.
● Couldn’t I just do everything Puppet does using shell provisioners?
○ Well, yeah but: You would have to write distribution-specific code for each
box (think apt-get vs yum, deb vs rpm, etc).
○ Things will quickly get messy if you need complex provisioning steps that
depend on each other, files to include, third-party modules, etc.
○ Your code would be order-dependent (stateful).
4. Manifest files - I
● These are the config files for Puppet: This is where you define resources
for your system.
● The main manifest file (entry script) must be pointed to in your
Vagrantfile
● Puppet is a Ruby-inspired DSL.
● Resources are not necessarily applied to the target system in the order
they are written in the manifests. If a resource must be applied before or
after some other resource, you must explicitly say so.
5. Manifest files - II
Example manifest file - Clone project rails/rails from github:
Exec {
path => [ "/bin/", "/sbin/" , "/usr/bin/", "/usr/sbin/","/usr/local/bin" ]
}
exec { 'sys_update':
command => 'apt-get update --fix-missing',
}
package { 'git-core':
require => Exec['sys_update'],
ensure => 'installed',
}
exec{ 'clone rails project':
command => 'git clone https://github.com/rails/rails.git',
cwd => '/home/foo/',
require => Package['git-core'],
}
define a command
install a package but only after system
update (this is the command you’ve
define above)
set defaults for a
resource (in this case,
default path for Execs)
clone a project using git
but first make sure the
git package is installed
6. Resources
● Resources are the basic building blocks in Puppet.
● Resources are state definitions. They are not commands that get run, but
assertions that get verified. They should not have side-effects.
● A resource looks like this:
type {'title':
attribute => 'value',
}
● Common resource types are Exec, Package, File and Service.
● Official docs entry for resources.
7. Resource types: Package I
● This resource type is used to assert that a package is in a given state.
● Attribute provider is used to define what kind of package will be used (it
defaults to your system’s default package manager but others can be
used, including things like pip, gem and npm.
● install a package using default provider (depending on your OS):
package {'apache2':
ensure => 'installed',
}
8. Resource types: Package II
● Making sure a pip package is updated:
package {'Django':
ensure => 'latest',
provider => 'pip',
}
More info: Puppet Docs for Package Resource
9. Resource types: Exec
● This resource type defines a shell command to be run in your virtual machine.
● The command must be idempotent or stateless: it should be able to run
multiple times with no errors. Use attributes like onlyif, unless and
creates to control when they run.
● example:
exec {'install chrome browser':
command => 'dpkg -i google-chrome-stable_current_i386.deb',
cwd => "/home/username/Downloads",
creates => "/usr/bin/google-chrome",
}
this command creates a
file, so Puppet knows it
shouldn’t be run if the
file already exists
10. Resource types: File
● It merely asserts that a file exists. So if it doesn’t exist, it is created; if it already
exists, nothing is done.
● Assert that a file exists and is owned by a given user:
file {'make sure my-file exists':
path => '/path/to/my-file',
ensure => 'present',
owner => 'johndoe',
}
11. Resource types: File II
● Make sure a directory exists and has given mode
file {'settings-directory',
ensure => 'directory',
path => '/path/to/settings-directory',
mode => 755,
recurse => true,
}
all child files will
have given
mode as well
12. Classes
● Just a simple way to group resources together, introducing modularization
and reuse:
class python {
package{'python-dev':
ensure => 'installed',
}
package{'python-pip':
ensure =>'installed',
require => Package['python-dev'],
}
}
include python
enforce ordering
between resources
don’t forget to
include what you
have defined
13. Heads-up
● In order to be able to launch 64-bit boxes, make sure you have
‘Virtualization Support’ enabled in your computer BIOS.
● You need to include all classes you want to be able to use, even though
they are not your ‘entry point’.
14. Links and References
● Latest Docs (version 3.6)
● Visual Index for all Syntax Elements in the Puppet DSL
● Resource types full reference.
● Wikipedia Article comparing Configuration Management engines