This presentation is a fairly brief introduction to ansible including some minor details around WP Engine's implementation, variable precedence, a sample playbook, and some of the core concepts around what makes ansible tick.
2. Uh… What are we talking about?
• Configuration Management Utility
• Automation Utility
• Easily extensible and pluggable framework
• Michael DeHaan, 2012 (developer of cobbler)
3. Please sir, may I have some
more?
• Written in Python
• Used for server config management
• Used for auditing of environment
10. Why is the inventory important?
• Groups are managed by dynamic inventory
• Skipping dynamic inventory means no groups
• No groups means incorrect variables set
• Systems will be configured incorrectly
11. Why do we need a custom
inventory?
• Multi-vendor strategy
• Custom data
requirements
• Assurance of
environment isolation
13. Access The Servers You Want!
• ‘pod-*’ # All pods
• ‘utility-*’ # All servers
with utility in the name
• ‘cluster-*:!dbmaster*’ #
All servers in each
cluster excluding
dbmaster
• ‘vendor:&pod-*’ # All
pods that exist in vendor
17. What is idempotence?
f(x) = f(f(x)) = f(f(f(f(f(f(x))))))
• property of certain
operations in
mathematics and
computer science, that
can be applied multiple
times without changing
the result beyond the
initial application
•f(x) = f(f(x))
18. Okay… why do we care?
• Less accident prone
• We don’t break things
• Playbook is repeatable
• Helps to ensure same state, each time
31. One-Off Playbooks
• build-server.yml
• Handles build server provisioning
• fire_and_forget_pull.yml
• Similar to nas2-prefetch.yml
• prepare-loadtest.yml
• Stages the droid install on a server
• remove_user.yml
• Removes user from our infrastructure
33. Introduction to Ansible Variables
• Regular variables:
Variables that are
explicitly defined either
via register or various
files / CLI options
• Magic variables:
Variables that are
defined automatically
35. Variable Precedence
• Defined on the CLI (-e, --extra-vars)
• Connection variables
• “Most everything else”
• Inventory variables
• Discovered facts
• Role defaults
36. Wait… “most everything else…?”
• Included variables
• Host variables
• Group Variables
• Child group
• Parent group
• “All” variables, the super parent
• Define a variable as few times as possible
37. Using Lookup Plugins for
Variables
• with_items - Iterate through a list of items
• with_dict - Iterate through a dictionary
• with_fileglob - Iterate through a glob of files
• with_first_found - Iterate through files until one
is found
• Create your own!
40. How to Loop in Templates
roles/common/templates/etc/hosts:
{% for ip in ansible_all_ipv4_addresses | sort %}
{{ ip }} {{ ansible_fqdn }}
{% endfor %}
roles/common/templates/etc/ansible_groups:
{% for name in group_names | sort %}
{{ name }}
{% endfor %}
44. Possible to Extend Upon
• Additional plugins can easily be dropped in
• Researching sample plugins goes a long way
• Several different plugin types currently
available
• Return results in JSON or hook however you
choose