Neil Millard describes the components required to run puppet in a masterless configuration. This allows you to boot immutable servers quickly, and the option of tearing them down and replacing/rebuilding quickly.
This was presented at Puppetcamp London 2017
7. What is Masterless
• Puppet without a master
• Without a master, the automation needs to ‘provide’
all the configuration the
Master gives us
• The master and node
in one
16. Bootstrapping
• Preparing to run puppet
Tru-strap https://github.com/MSMFG/tru-strap
Args: Provisioning or configuration repository
Role + Environment Facts, for hiera lookup
echo “init_role=${value}" > /etc/facter/facts.d/init-role.txt
20. hieradata
• Separation of data from code
• Code reuse with lookups
profile::docker_containers::containers:
eyamld:
image: "nginx"
ports:
- "80:80"
env:
- NGINX_HOST=foobar.com
- NGINX_PORT=80
use_name: true
# profile::docker_containers
class profile::docker_containers
($containers={}) {
create_resources (
'profile::docker_container', $containers )
}
21. hieradata
• Separation of data from code
Like pilot from the helicopter
• Code reuse with lookups
• Automatic parameter lookup
# In this example, $parameter's value gets set
# when `myclass` is eventually declared.
# Class definition:
class myclass ($parameter_one = "default text") {
file {'/tmp/foo':
ensure => file,
content => $parameter_one,
}
}
23. Roles and Profiles
• Business Layer (Roles)
only includes profiles
no logic
one server, one role
• Implementation Layer (Profiles)
Includes classes
Modules and Resources
create_resources{}
Craig Dunn - http://www.slideshare.net/PuppetLabs/roles-talk
Puppet - https://docs.puppet.com/pe/2016.2/r_n_p_intro.html
http://www.slideshare.net/DaeHyung/learning-puppet-basic-thing #64
25. Modules
Librarian or r10k from Puppetfile
forge "https://forgeapi.puppetlabs.com"
# Base modules
mod "saz/timezone", "3.0.1"
mod "saz/rsyslog", "4.0.2"
29. Hiera Lookups
• Under the Hieradata folder
• ::init_role == dockerhost
• Example code
• https://github.com/neilmillard/puppet-dockerhost
echo “init_role=${value}" > /etc/facter/facts.d/init-role.txt
30. Classes and role
• Classes:
# hieradata/dockerhost.yaml
---
classes:
- role::dockerhost
31. Roles and Profiles
• Defined as classes within either Roles Module or Profiles Module
• Roles contain Profiles
• Use include, require or class
class role::dockerhost {
include ::profile::base
include ::profile::os_limits
include ::profile::docker_base
include ::profile::docker_containers
class { '::profile::swapfile':
before => Class['profile::base']
}
}
# profile::docker_containers
class profile::docker_containers
($containers={}) {
create_resources (
'profile::docker_container', $containers )
}
32. Data file flow summary
Role fact
hieradata
site.pp
role.yaml classes
Role::
Profile::
Profile::
34. ordering
• Puppet execution is in parallel
• Dependencies need order
anchor { 'ntp::begin': } ->
class { '::ntp::install': } ->
class { '::ntp::config': } ~>
class { '::ntp::service': } ->
anchor { 'ntp::end': }
35. ordering
• before, require
class { ‘install-ssl':
installdir => "$installdir",
require => Exec['unarchive-source'],
before => File['copy-init-file'],
}
36. ordering
• ->
• Everything else is attempted at the same time
->
class { ‘install-ssl':
installdir => "$installdir",
}
->
37. Ordering - stages
• main
• WARNING – use with care.
Can cause dependency cycles
38. Ordering - stages
• Catalog compiles
• Runs each stage based on order
• Ordering across stages WILL break
Notice: Compiled catalog for ip-10-96-4-130.internal in environment production in 2.10
Notice: /Stage[swapfile]/Profile::Swapfile/Exec[Create swap file /mnt/swap.1]/returns:
Notice: /Stage[swapfile]/Profile::Swapfile/File[/mnt/swap.1]/mode: mode changed '0644'
...
Notice: /Stage[main]/Profile::Docker_base/Exec[yum install -y docker-io]/returns:
Notice: /Stage[main]/Docker::Service/File[/etc/sysconfig/docker]/content: content
39. Ordering - stages
• Simple manifests best
• swapfile stage
stage { 'swapfile':
before => Stage['main'],
}
class { '::profile::swapfile':
stage => swapfile
before => Class['profile::base']
}
40. What we covered
• Masterless puppet
• Bootstrap
• Modules
• Hieradata
• Roles and Profiles
• Ordering
• Stages
Good lunch, break?
Raise your hand if you use AWS
Raise if you are a developer
Raise if you are operations or infrastructure
Raise your hand if you use AWS
Raise if you are a developer
Raise if you are operations or infrastructure
Would you describe yourself as DevOps,
Raise your hand if you use AWS
Raise if you are a developer
Raise if you are operations or infrastructure
Would you describe yourself as DevOps,
Raise your hand if you use AWS
Raise if you are a developer
Raise if you are operations or infrastructure
Would you describe yourself as DevOps,
My focus is on deploying Infrastructure, applications with monitoring those deployment. All facilitated by Automation, with tools such as puppet, with support from Git
Does your infrastructure currently use Puppet?
What masterless puppet is and why you would use it.
Bootstrapping an instance,
Other components before we run puppet apply.
Why, flexibility and scaling
Pets:
They are unique, loved and cared for.When they become ill, they are nursed back to health and you hope they will stay well for a long time.You couldn’t possibly imagine getting rid of or decommissioning the server.Long life
Cattle:
They are name more like a number – S02343They are pretty much identical to the othersWhen they get ill, you just get another one.As the server is so easily replace, you wouldn’t think twice about removing any you don’t need, at night for instance.
Elastic capacity if you are using a cloud provider.
Why, flexibility and scaling
Pets:
They are unique, loved and cared for.When they become ill, they are nursed back to health and you hope they will stay well for a long time.You couldn’t possibly imagine getting rid of or decommissioning the server.Long life
Cattle:
They are name more like a number – S02343They are pretty much identical to the othersWhen they get ill, you just get another one.As the server is so easily replace, you wouldn’t think twice about removing any you don’t need, at night for instance.
Elastic capacity if you are using a cloud provider.
Build play destroy
Build play destroy
Autoscaling config
Teraform
Need an image to start from.
Most linux distros now include Cloud-init -
Cloud-init: Scott Moser - Ubuntu Server Team
Your boot image can contain as much or as little as you want.
affects startup time,
Creates an overhead if things in the image change often
Your boot image can contain as much or as little as you want.
affects startup time,
Creates an overhead if things in the image change often
Either way, we need Puppet prereqs
Creates an overhead if things in the image change often
Your boot image can contain as much or as little as you want.
affects startup time,
Creates an overhead if things in the image change often
Puppet needs components to build the server.
Loads configuration via hieradata and our roles and profiles
Without hardcoding values, we can provide defaults instead.
Your hieradata is then merged with the defaults to provide the actual config
This makes your code reusable.
In this case, it’s a define that can run multiple containers from a small set of hieradata
This is where in the code the merge happens with lookups
Automatic lookups simplifies code further
This is where we can see the tru-strap arguments for environment and role.
Avoid spaghetti code.
Reusable profiles
Lib contains custom Types and Providers
Facts:
External Data/ENC: in our case Hieradata
Puppet manifests and modules
Back at our hieradata again. Notice the hierarchy bit.
The ::init_env and ::init_role are Facts, that are passed to hiera from puppet during the run
The boot script sets these up using facter.
Loads configuration via hieradata and our roles and profiles
A server only has ONE role
Profiles include modules, classes or define usages
Puppet needs components to build the server.
Self contained modules
Does your infrastructure currently use Puppet?
What masterless puppet is and why you would use it.
Bootstrapping an instance,
Other components before we run puppet apply.