2. Agenda
What is Ansible?
How is it different?
how does it work?
Installation
The ansible tools
Running some adhoc commands
What is Playbooks?
Basic playbook
Handlers
Roles
Demo: Playbook for Apache
3. What is Ansible?
Ansible is a radically simple IT automation engine that automates cloud
provisioning, configuration management, application deployment, intra-
service orchestration Ansible’s goals are foremost those of simplicity and
maximum ease of use.
Ansible manages machines in an agentless manner.
There is never a question of how to upgrade remote daemons or the problem
of not being able to manage systems because daemons are uninstalled.
It uses a very simple language (YAML, in the form of Ansible Playbooks) that
allow you to describe your automation jobs in a way that approaches plain
English.
4. How is it different?
Agent-less architecture
Configuration as data, not code
Betterires-included(module).
Full configuration management, orechestration, deployment.
6. Installation
Installation RHEL/CentOS/Fedora
1. Enable EPL on RedHat
## RHEL/CentOS 6 64-Bit ##
# rpm -ivh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
# yum repolist # verify the EPL Repo
2. Install ansible
#yum install ansible -y
# ansible --version # verify the ansible installation
3. Preparing ssh keys to connect to remote hosts
# ssh-keygen -t rsa -b 4096
4. Agent setup
cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys
Note : Please make sure .ssh has 700 and authorized_keys has 400 permission
7. Ansible comes with several command-line tools. The first one is simply
called… ansible.
The purpose of the ansible tool is mainly to execute a command over selected
groups of an inventory.
Creating Inventory file for remote hosts:
vim /etc/ansible/hosts
The ansible tool:
Installation
8. Running some commands:
Verify all the remote hosts are getting pinged from our ansible server using
ping module(-m ping)
ansible -m ping 10.20.30.40
ansible -m ping all
ansible -m ping web-servers
ansible -m command -a "df -h" 10.20.30.40
File Management:
ansible web-servers -m copy -a "src=/etc/hosts dest=/tmp/hosts"
ansible web-servers -m file -a "dest=/srv/foo/a.txt mode=600"
ansible web-servers -m file -a "dest=/srv/foo/b.txt mode=600 owner=afroz
group=afroz
9. Running some commands(contd..)
Package management
ansible web-servers -m yum -a "name=httpd state=present"
ansible web-servers -m yum -a "name=httpd state=latest"
User and Group
ansible all -m user -a "name=hssain upassword=hussain"
ansible all -m user -a "name=hussain state=absent"
Managing Services:
ansible web-servers -m service -a "name=httpd state=started"
ansible web-servers -m service -a "name=httpd state=restarted"
ansible web-servers -m service -a "name=httpd state=stopped“
Gathering the facts(node info)
ansible all -m setup
10. Playbooks
Playbooks are Ansible’s configuration, deployment, and orchestration
language.
They can describe a policy you want your remote systems to enforce, or a set
of steps in a general IT process.
It runs multiple Tasks and provide some more advanced functionality that we
would miss out on using ad-hoc commands.
Playboooks contains plays.
plays contains tasks
tasks contains modules
Modules: The actual work done by modules such
file,yum,host,service,ping,command etc.
12. Handlers
A Handler is exactly the same as a Task (it can do anything a Task can), but it
will run when called by another Task.
We can think of it as part of an Event system; A Handler will take an action
when called by an event it listens for.
13. Roles
Roles are good for organizing multiple, related Tasks and encapsulating data
needed to accomplish those Tasks.
The configuration portion often requires extra data such as variables, files,
dynamic templates and more.
Roles have a directory structure like this: