Ansible Basics
Ansible Basics
1
Agenda
2
What isAnsible?
“ Simple, agentless and powerful open
source IT automation tool
Provisioning
Configuration Management
Application Deployment
Continuous Delivery Security &
Compliance Orchestration
11
What are theoptions?
12
What are theoptions?
13
Why Ansible?
14
How SSH is achieved
Key generation (public and private key) is performed using the ssh-keygen
command.
This generates the private key, ~/.ssh/id_rsa, and the public key,
~/.ssh/id_rsa.pub.
Trust will be initiated between client and server with the help of ssh-copy-id <IP-
Address>
Life before Ansible
Multiple ssh, control panels, editing config filesmanually.
25
Building Blocks
An Ansible solution is composed of one or more items listed
on the leftside.
26
Building Blocks - Inventory
Tells Ansible about hosts it shouldmanage
Hostnames, IPs, ports, SSHparameters
Server specific variables
27
Building Blocks - Inventory
• Example for Inventory file
28
Building Blocks - Module
• Modules provide Ansible means to control ormanage
resources on local or remoteservers.
management: service
30
Building Blocks - Task
Tasks are responsible for calling a module with aspecific set of
parameters.
31
Building Blocks - Variable
• Variables in Ansible are very useful forreusing
information. Sources for variablesare:
• Inventory: We can assign variables to hostsor groups
(group vars, host vars).
• YAML files: We can include files containing variables. Task
results: Result of a task can be assigned to a variable using the
register keyword as shown in the previous slide.
• Playbooks: We can define variables inAnsible
playbooks (more on that later).
•Command line: (-e means extra variable //-e
"uservar=gulcin")
32
Building Blocks - Playbook
34
Building Blocks - Role
In Ansible,
playbooks organize tasks
roles organize playbooks
35
Building Blocks - Role
Here you can see a dependency graph andthe
corresponding role directory structure:
36
Howto Invoke Ansible?
1. Running ad-hoccommands
2. Runningplaybooks
37
Ad-hoc Commands
We can call any Ansible module from the command line,anytime.
The ansible CLI tool works like a single task. It requires an inventory, a module
name, and module parameters.
[dbservers]
db.example.com
38
Ad-hoc Commands
We can check uptimes of all hosts in dbserversusing:
39
How to Run Playbooks?
---
- hosts: dbservers
tasks:
- name: retrieve the uptime
command: uptime
register: command_result # Store this command's result in this variable
41
Playbook control
--tags / --skip-tags
Runs or skips tasks with specifiedtags
--limit
Manages only specified hosts or groups
--start-at-task
Start execution from a specifictask
--step
Executes step-by-step and asks for confirmation tocontinue
43
with_items
- name: with_items
debug:
msg: "{{ item }}"
with_items: "{{ items }}"
44
w ith_ indexed items
45
with_flattened
name: with_flattened
debug:
msg: "{{ item }}"
with_flattened: "{{ items }}"
46
w ith_file
---
- hosts: all
tasks:
47
Questions?
Huge Thanks!
48