From Ansible's website: "Ansible is a radically simple IT automation engine that automates cloud provisioning, configuration management, application deployment, intra-service orchestration, and many other IT needs."
This introduction is based on ansible official docs, capturing most important information to make it easy to understand Ansible main concepts.
2. SOFTWARE CRAFTSMANSHIP TOLEDO
Software Craftsmanship Toledo
• Pasión por la ingeniería software y el desarrollo de
software en la comunidad de Castilla-La Mancha.
• Clara vocación por aprender, fomentar y compartir las
metodologías ágiles en la región.
• Grupo totalmente abierto: http://www.meetup.com/es/
Software-Craftsmanship-Toledo-ES
• Miembros profesionales y/o apasionados del desarrollo
software.
• Tenemos un canal de Slack… Apúntante!
3.
4. SOFTWARE CRAFTSMANSHIP TOLEDO
Meet me
• Manuel de la Peña
• @mdelapenya
• Support >
Engineering >
Testing > IT … at
Liferay, Inc.
• DEVOPS?
15. SOFTWARE CRAFTSMANSHIP TOLEDO
How it works
• It uses a very simple language (YAML, in the form
of Ansible Playbooks)
• Plain English!
• By default manages machines over the SSH
protocol.
• It uses no agents and no additional custom
security infrastructure.
16. SOFTWARE CRAFTSMANSHIP TOLEDO
SSH Keys
• SSH keys with ssh-agent are
recommended.
• Root logins are not required, you can
login as any user, and then su or
sudo to any user.
17. SOFTWARE CRAFTSMANSHIP TOLEDO
Installation
• No database, and no running daemons!
• Install it on only one machine (a laptop?) as central
point.
• It does not leave software installed or running on
remote machines —> upgrades super easy :D
18. SOFTWARE CRAFTSMANSHIP TOLEDO
Control Machine
• “Any” machine with Python 2.6 or 2.7 installed.
• This includes Red Hat, Debian, CentOS, OS X, any
of the BSDs, and so on.
• Windows isn’t supported for the control machine.
19. SOFTWARE CRAFTSMANSHIP TOLEDO
Managed Nodes
• You need a way to communicate, normally ssh.
• SSH uses sftp. If not available, switch to scp.
• Python 2.4 or later. (If Python < 2.5 also need
python-simplejson)
20. SOFTWARE CRAFTSMANSHIP TOLEDO
Remote connection
• Native OpenSSH for remote communication when
possible.
• If OpenSSH is too old in control machine
(Enterprise Linux 6 OS)—> Fallback to Paramiko:
a Python implementation.
• SSH keys are encouraged but password
authentication can also be used (--ask-pass).
23. SOFTWARE CRAFTSMANSHIP TOLEDO
Inventory
• What machines/hosts you are
managing using a very simple INI file.
• Managed machines/hosts in groups of
your own choosing.
• Define variables by scope.
38. SOFTWARE CRAFTSMANSHIP TOLEDO
Variables
• Should be letters, numbers, and
underscores.
• Variables should always start with a letter.
• YAML also supports dictionaries which
map keys to values.
• There are reserved Python-related
keywords.
44. SOFTWARE CRAFTSMANSHIP TOLEDO
Variables: precedence
• role defaults < inventory vars < inventory
group_vars < inventory host_vars <
playbook group_vars < playbook host_vars
< host facts < registered vars < set_facts <
play vars < play vars_prompt < play
vars_files < role and include vars < block
vars (only for tasks in block) < task vars
(only for the task) < extra vars
46. SOFTWARE CRAFTSMANSHIP TOLEDO
Playbooks
• Orchestrate steps/tasks of any
manual ordered process.
• Executed a/synchronously.
• YAML format.
• Minimum syntax —> not a language
but a model.
47. SOFTWARE CRAFTSMANSHIP TOLEDO
Playbooks: Tasks
• Should have a name: included in
output and readable by humans.
• Accept variables:
template: src=somefile.j2 dest=/etc/
httpd/conf.d/{{ vhost }}
48. SOFTWARE CRAFTSMANSHIP TOLEDO
Playbooks: Tasks lists
• Each play contains a list of tasks.
• Tasks are executed in order, one at a time,
against all machines matched by the host
pattern.
• Important! Same task directives to all hosts.
• Tasks goal? execute a module, with arguments.
• Modules are idempotent.
49. SOFTWARE CRAFTSMANSHIP TOLEDO
Playbooks:Hosts&Users
• For each play, choose machines to
target and remote user to complete
the steps/tasks as.
• Define remote users per task.
• Use sudo on a particular task
instead of the whole play.
50. SOFTWARE CRAFTSMANSHIP TOLEDO
Playbooks: Handlers
• Playbooks respond to change.
• Can notify at the end of each block of
tasks.
• Triggered only once, even if notified by
multiple tasks.
• Best used to restart services and trigger
reboots.
54. SOFTWARE CRAFTSMANSHIP TOLEDO
Roles
• Reuse playbooks.
• Combine files to form clean,
reusable abstractions.
• Grouping allows easy sharing of
roles with other users.
• include directive —> Include files.
55. SOFTWARE CRAFTSMANSHIP TOLEDO
Roles: structure
• Automatically loads certain
vars_files, tasks, and handlers based
on a known file structure.
• Where is the magic? Improvements
to search paths for referenced files.
57. SOFTWARE CRAFTSMANSHIP TOLEDO
Roles: main.yml
• roles/x/tasks/main.yml —> Add tasks to the
play.
• roles/x/handlers/main.yml —> Add handlers
to the play.
• roles/x/vars/main.yml —> Add variables to
the play.
• roles/x/meta/main.yml —>, Add roles as
dependency (1.3 and later).
58. SOFTWARE CRAFTSMANSHIP TOLEDO
Roles: paths
• Any copy, script, template or include
tasks (in the role) can reference files
in roles/x/{files,templates,tasks}/
without having to path them
relatively or absolutely
60. SOFTWARE CRAFTSMANSHIP TOLEDO
Roles:defaults
• Add a defaults/main.yml file in your role
directory.
• Set default variables for included or
dependent roles.
• Lowest priority of any variables
available, so they are easily overridden,
including inventory variables!
61. SOFTWARE CRAFTSMANSHIP TOLEDO
Roles:dependencies
• A list of roles and parameters to
insert and execute before the
specified role.
• Automatically pull in other roles.
• meta/main.yml within the role.
• Executed recursively.
75. SOFTWARE CRAFTSMANSHIP TOLEDO
LELK Next??
• Applied logstash-forwarder role to
more machines, setting log_paths
and tags variable to the desired file.
• Add more client types —> Apache
Server, Firewall