Complete Ansible Automation Training
Introduction
Complete Ansible DevOps Automation Training
Course Overview
Section 1 thru 10
By: Imran Afzal
[Link]
Introduction
• Course overview
• What is Ansible?
• History of Ansible
• Benefits
Section 1
• Terminologies in Ansible
• How Ansible works?
• Other Automation tools
• Free source Ansible and Red Hat Ansible
• Handouts
• Quiz
By: Imran Afzal
[Link]
Lab Design and Setup
• Lab design
• Installing virtualization software
• Creating a VM and Installing Linux
• Creating Ansible Clients
Section 2
• Installing Ansible
• Handouts
• Quiz
By: Imran Afzal
[Link]
Ansible Automation with
Simple Playbooks
• YAML file syntax
• YAML file syntax example
• Creating first playbook
• Output playbook
Section 3
• Multiple tasks playbook
• Playbook for installing and starting a service
• Handouts
• Quiz
By: Imran Afzal
[Link]
Ansible Automation for Remote Clients
• Remote Clients hosts File Syntax
• Establish Connection to Remote Clients
• Playbook
• Check Remote Clients Connectivity
• Copy Files to Remote Clients
• Change File Permissions
Section 4
• Setup Apache and Open Firewall Port
• Run Shell Scripts on Remote Clients
• Schedule a job (crontab)
• User Account Management
• Add or Update User Password
• Download Package from a URL
• Kill a Running Process
• Pick and Choose Steps
• Handouts
• Quiz By: Imran Afzal
[Link]
Ansible Automation with Ad-hoc Tasks
• Ansible Ad-Hoc Commands (Part 1)
• Ansible Ad-Hoc Commands (Part 2)
• Ansible Ad-Hoc Commands (Part 3)
• Handouts
Section 5
• Quiz
By: Imran Afzal
[Link]
Advance Ansible Automation Features
• Roles
• Roles by Application
• Roles on Ansible Galaxy
• Tags
Section 6
• Variables
• Variables in Inventory File
• Handouts
• Quiz
By: Imran Afzal
[Link]
Additional Features in Ansible
• Handlers
• Conditions
• Loops
• Handouts
Section 7
• Quiz
By: Imran Afzal
[Link]
Securing Ansible
• Ansible Vault
• Encrypt Strings within a Playbook
• Handouts
• Quiz
Section 8
By: Imran Afzal
[Link]
Ansible Management Tools
• Ansible AWX
• Ansible Tower
• Handouts
• Quiz
Section 9
By: Imran Afzal
[Link]
Ansible Resources
• Ansible Additional Commands
• ansible
• ansible-playbook
• ansible-vault
• ansible-config
Section 10
• ansible-connection
• ansible-console
• ansible-doc
• ansible-galaxy
• ansible-inventory
• ansible-pull
• Ansible Documentation
• Community Help
By: Imran Afzal
[Link]
What is Ansible?
• Ansible is an open-source software provisioning, configuration management, and application-
deployment tool enabling infrastructure as code. It runs on many Unix-like systems, and can
configure both Unix-like systems as well as Microsoft Windows (Wikipedia)
• In simple words: Ansible is a free automation tool that can automate IT tasks on local machine
where it is running and on remote machines
SSH
1 1 4 7 10 ……
SSH
2
SSH
2 5 8 11 ……
SSH Ansible Server
3 3 6 9 12 ……
Aka: Control Node
• Please note: Ansible is written in python language, but it does not mean you need python
knowledge to use Ansible
By: Imran Afzal
[Link]
What is Ansible?
• Ansible can be used to:
Provision system Configure system
Deploy Apps Manage system and Apps
By: Imran Afzal
[Link]
What is Ansible?
• Example of Tasks
• Provisioning
• Bare-metal serves
• Virtualization systems
• Network devices
• Storage systems
• Cloud platform
• System Configuration Management
• Updates or upgrades
• Package installation
• Service configuration
• Stop|Start|Restart of services
• User or groups
• Assigning permissions to files and directories
• Application deployment
• Backups
• Weekly or monthly system reboots
• Orchestration. By: Imran Afzal
[Link]
Brief History of Ansible
• The Ansible project was started in 2012 by Michael DeHaan
• It is open source and community driven
• Ansible Inc was purchased by Red Hat in 2015
• It is available for most of the Linux distributions such as, Red Hat, CentOS,
Fedora, Ubuntu, Debian and SUSE
• Need?
• Infrastructure management (specially virtualization)
• Configuration management (System or Application configuration)
• Multi-tier application automation (e.g. app, web and db servers)
• Single point of automation (having scripts on each system vs. one
automation management platform).
By: Imran Afzal
[Link]
Benefits of Ansible
• Agentless!!!
• Open-source
• Avoid human errors
• Saves time by automating repetitive or tedious tasks
• Increase productivity
• Easy to use
• Simple (human readable text files)
• Flexible
• Secure (over SSH).
By: Imran Afzal
[Link]
Benefits of Ansible
• Provides pre-written modules
• Easy to learn (as long as you have a good instructor) ☺
• Great product for Orchestration
• Ansible can be used not only for systems but also for network, storage, cloud etc.
• Provides approx. 1300 modules out of the box and about 4000 modules on galaxy
• Huge online Ansible resources
• [Link]
• [Link]
• [Link]
• [Link]
• A big plus + for job seekers and those who want to level up their career
By: Imran Afzal
[Link]
Terminologies in Ansible
• Control node or Ansible Server
• Server which runs Ansible application
• Modules
• Module is a command meant to be executed on the client-side
• Most of the IT tasks modules are already created and can be found on Ansible website
• [Link] → search for module index
• [Link]
• Example of modules:
1. Install http
2. Enable http service Task
3. Start http service
• Task
• A task is a section that consists of a single procedure to be completed. A task can have
multiple modules
By: Imran Afzal
[Link]
Terminologies in Ansible
• Playbook
• Automation file with step-by-step execution of multiple tasks
• YAML
• A Playbook written in YAML language (Yet another markup language)
• Inventory
• File that has information about remote clients where tasks are executed
• Tag
• A reference or alias to a specific task
• Variable
• Variables are like containers that holds the defined value which can be used repetitively
• Role
• Splitting of Playbook into smaller groups. Roles let you automatically load related vars, files, tasks,
handlers, and other Ansible artifacts based on a known file structure. After you group your content in
roles, you can easily reuse them and share them with other users
By: Imran Afzal
[Link]
How Ansible Works?
• Each specific Task in Ansible is written through a Module(s)
• Multiple Modules are written in sequential order
• Multiple Modules for related Tasks is called a Play
• All Plays together makes a Playbook
• Playbook is written as a file format called YAML
Web-servers YAML file
• Install httpd Module
• Enable httpd Module Play
• Start httpd
Task Module
• Enable http port Play
on firewall Module Playbook
Database-servers
• Login to db Module
Task • Create a table Module Play
• restart db Module
By: Imran Afzal
[Link]
How Ansible Works?
Commands examples:
To run modules through yaml file:
# ansible-playbook [Link]
To run module independently
# ansible myservers –m ping
Ansible configuration files:
• /etc/ansible/[Link]
• /etc/ansible/hosts
• /etc/ansible/roles
By: Imran Afzal
[Link]
Other Automation Tools
• Puppet and Chef
• Uses Ruby language which is more difficult to learn, and their support is
declining day by day
• These tools require agents to be installed on clients
• The installation process is very complex
• Lack of documentation
• Ansible
• Uses simple YAML
• Agentless (Only requires SSH access)
• Easy installation
• Well documented product
By: Imran Afzal
[Link]
Open Source Ansible vs. Red Hat Ansible
• Ansible is an open-source software
• It was purchased by Red Hat in 2015
• Ansible software itself is free even though it is owned by Red Hat
• Ansible is the same software across all platforms
• The only difference is, Red Hat provides additional product Ansible Tower and
Consulting or Technical Support for Ansible
• Learn more about Red Hat Ansible at [Link]
• Red Hat Ansible Tower • Ansible AWX
• Red Hat provides Ansible tower which is • Open source
GUI based tool to manage Ansible • Free software.
automation
• Ansible tower is a paid product by Red Hat
• Manages multiple Ansible servers for large
enterprise environment
By: Imran Afzal
[Link]