Ansible Overview
Ansible Overview
Ansible Overview
Agenda
INFRASTRUCTURE AS A CODE...
Ansible is an open source configuration management, deployment, and orchestration tool,
based on Python.
It’s a simple automation language that can perfectly describe an IT application
infrastructure in Ansible Playbooks.
SIMPLE POWERFUL AGENTLESS
• Inventories
• Modules
• Variables
• Facts
• Playbooks
• Configuration Files
INVENTORIES
DEFINES WHICH HOSTS ANSIBLE MANAGES
• Static - Defined in simple text files, a host can be member of more than one
group, which is useful to identify the hosts' role in the datacenter.
• Dynamic - Generated for outside providers, some examples include
pulling* inventory from a cloud provider (OpenStack, AWS, etc.), LDAP, Cobbler,
or a piece of expensive enterprise CMDB software.
MODULES
SMALL PROGRAMS THAT COMES (BUILT-IN) WITH ANSIBLE
“Ansible Modules” are written to be resource models of the desired state of the system.
Ansible then executes these modules (over SSH by default), and removes them when
finished.
The preinstalled library has 500+ modules available that allows us to manage from basic
systems resources to sophisticated ones. For example, to manage users, packages,
network*, files, services, as well provision cloud instances, create databases, and many
more.
Ansible has four modules in to this category and provide us the options to choose from
while running system commands or scripts:
• Raw - Do not require Python on target/managed host
• Command - Most recommended module for executing commands on target nodes
• Shell - Runs the command through the '/ bin/sh ' shell on the target host. It is less
secure than a command module
• Script - copy and execute a script in one step on remote host
VARIABLES
A CONVENIENT WAY TO MANAGE DYNAMIC VALUES FOR A GIVEN ENVIRONMENT
Ansible supports variables that can be used to store values that can be reused
throughout files in an entire Ansible project.
Variables must start with a letter and can only contain letters, numbers, and underscores.
• Global scope: Variables set from the command line or Ansible configuration
• Play scope: Variables set in the play and related structures
• Host scope: Variables set on host groups and individual hosts by the inventory, fact
gathering, or registered tasks
Note: Must start with a letter and can only contain letters, numbers, and underscores.
Ansible facts are variables that are automatically discovered by Ansible from a managed
host.
Facts are pulled by the setup module and contain useful information stored into
variables that administrators can reuse.
Fact variables can be used as part of playbooks, in conditionals, loops, or any other
dynamic statement that depends on a value for a managed host.
Display facts from all hosts and store them indexed by I(hostname) at C(/tmp/facts):
YAML format - a simple, human-readable, and familiar way to blueprint the infrastructure
Users of this tool need not learn any special programming language to get started with,
Ansible code is self-explanatory and self-documenting in nature.
Plays also define the order in which tasks are configured. This allows us to orchestrate
multitier deployments.
Roles - While it is possible to write a playbook in one very large file (and you might start
out learning playbooks this way), eventually you’ll want to reuse files and start to
organize things.
the apache config file template: src: /srv/httpd.j2 dest: /etc/httpd.conf notify: - restart apache - name: ensure apache is runni
PLAYBOOKS
ANSIBLE VAULT
PROTECTING SENSITIVE DATA IN YOUR PLAYBOOKS
Sensible data like passwords and API keys can be encrypted and decrypted using Ansible
Vault.