Ansible
Ansible
Configuration management is a
process for maintaining computer
systems, servers, and software in a
desired, consistent state. It’s a way
to make sure that a system
performs as it’s expected to as
changes are made over time.
Why CM?
Configuration Management
Provisioning
Application Deployment
Orchestration
Uptime and Site Reliability
CM Tools
What do we cover
▪ Introduction
• What & Why Ansible
• How Ansible works
• Pre-requisites to start
▪ Prepare Ansible lab environment
• Ansible lab setup
• Install Ansible
• Setup managed nodes
What do we cover
▪ Ansible components
• Inventory
• Modules
• Playbooks
• Ansible configuration file
▪ Ansible playbooks
▪ Ansible syntax
▪ Write first ansible playbook
What do we cover
▪ Modules
• Yum
• File
• Copy
▪ Conditions
▪ When
▪ With_items
▪ Notify & handlers
What do we cover
▪ Ansible Variables
▪ Additional concepts
▪ Converting a shell script into a playbook
▪ Gather facts
▪ Error handling
▪ Tags
▪ Multitask Ansible Playbooks
▪ Install apache on Managed nodes
What do we cover
▪ Ansible Vault
• Ansible vault introduction
• Using vault with git
▪ Ansible Roles
• Roles introduction
• Converting a playbook into a role
• Push changes onto git
What is Ansible
Radically simple open-source IT automation engine.
Ansible Automates:
Configuration Management
Provisioning
Application Deployment
Orchestration
What do we cover
▪ Ansible Variables
▪ Ansible Vault
• Ansible vault introduction
• Using vault with git
▪ Additional concepts
▪ Converting a shell script into a playbook
▪ Gather facts
▪ Error handling
▪ Tags
Human readable Configuration Use OpenSSH
No special code skills App Deployment Secure
Tasks executed in order Provisioning
Orchestration
Efficient
Open Source
Flexible
How Ansible works
Node 1
Inventory
ssh
Modules
Node 3
Ansible Terminology
▪ Control node
▪ Any machine with Ansible installed.
▪ Managed nodes
▪ The network devices (servers) you manage with Ansible
▪ Inventory
▪ A list of managed nodes. An inventory file is also
sometimes called a “hostfile”.
Ansible Terminology
▪ Modules
▪ The units of code Ansible executes. Each module has a
particular functionality.
▪ Tasks
▪ The units of action in Ansible.
▪ Playbooks
▪ Ordered lists of tasks.
Ansible lab setup
Control node
(Amazon Linux)
Prepare ansible server
1. Setup EC2 instance
2. Setup hostname
3. Create ansadmin user
4. Add user to sudoers file
5. Generate ssh keys
6. Enable password based login
7. Install ansible
Setup managed nodes
▪ Inventory / Hosts
▪ Tasks
▪ Playbooks
▪ Modules
Ansible basics
▪ All ansible commands start with “ansible”
The ansible* commands will use a different host inventory file when they are
used with the --inventory PATHNAME option, -i PATHNAME for short
https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html#intro-
inventory
Ansible modules
A module is a reusable, standalone script that Ansible runs on your behalf, either locally or
remotely.
Modules interact with your local machine, an API, or a remote system to perform specific
tasks like
Creating users
Installing packages
Updating configurations
Spinning up instances Etc...
Modules are the programs that perform the actual work of the tasks of a play
Core modules are the modules that come bundled with Ansible, There are
over 400 core modules.
tasks:
The goal of a play is to map a group of hosts to some well defined roles,
represented by things ansible calls tasks. At a basic level, a task is nothing more
than a call to an ansible module
What do we cover
▪ Ansible Variables
▪ Ansible Vault
• Ansible vault introduction
• Using vault with git
▪ Additional concepts
▪ Converting a shell script into a playbook
▪ Gather facts
▪ Error handling
▪ Tags
Ansible Variables