Presentation by TheodorosPloumis / @theoploumis
Date 13 May 2015, Ansible Version 1.9.1
Source on GitHub
Image by devopsreactions
// Can also use apt, yum, brew, compile from source etc
// We are installing version 1.9.1
$sudo easy_install pip
$sudo pip install ansible==1.9.1
Image by sysadmincasts.com
Find more in the Ansible Docs.
Execute a quick command to a machine using /usr/bin/ansible.
$ansible localhost -m setup -i hosts
$ansible localhost -m service -a "name=apache2 state=started" -i hosts
File (INI format) that describes Hosts and Groups
[webservers]
192.168.1.50
aserver.example.org
bserver.example.org
[dbservers]
localhost
Used with {{ variable }} replacement.
---
project_name: myproject
project_root: /var/projects/myproject
project_repo: git@bitbucket.org:myuser/myproject.git
system_packages:
- build-essential
- git
- nginx
- postgresql
- redis-server
- postfix
Accomplish dedicated Tasks (set values, use templates etc)
The "mini tools" of Ansible!
YAML formatted files orchestrate steps sequentially
This is where you love Ansible!
---
- hosts: webservers
sudo: yes
tasks:
- name: install nginx
apt: name=nginx state=installed update_cache=yes
- name: write our nginx.conf
template: src=tpl/nginx.conf.j2 dest=/etc/nginx/nginx.conf
notify: restart nginx
- name: start nginx proccess
service: name=nginx state=started
---
# Comments start with "#"
# All yaml files are jinja2 template
name: Example Developer
job: Developer
skill: Elite
employed: True
# Each list item starts with a "-"
foods:
- Apple
- Orange
- Strawberry
# Spaces and tabs matter!
languages:
ruby: Elite
python: Elite
dotnet: Lame
$ansible-doc [options] [module...]
$ansible-vault encrypt foo.yml
- name: add several users
user: name={{ item }} state=present groups=wheel
with_items:
- testuser1
- testuser2
# Example that prints the loopback address and gateway for each host
- debug: msg="System {{ inventory_host }} has uuid {{ ansible_product_uuid }}"
- debug: msg="System {{ inventory_host }} has gateway {{ ansible_ipv4.gateway }}"
when: ansible_ipv4.gateway is defined
- shell: /usr/bin/uptime
register: result
- debug: var=result
- name: Display all variables/facts known for a host
debug: var=hostvars[inventory_hostname]
$ansible-galaxy init roles/myrole
tasks:
- name: "shutdown Debian flavored systems"
command: /sbin/shutdown -t now
when: ansible_os_family == "Debian"
tasks:
- yum: name={{ item }} state=installed
with_items:
- httpd
- memcached
tags:
- packages
- template: src=templates/src.j2 dest=/etc/foo.conf
tags:
- configuration
$ansible-playbook example.yml --tags "configuration,packages"
$ansible-playbook foo.yml --check --diff
$ansible-galaxy [command]
$ansible-pull [options] [playbook.yml]
Tool | Ansible | Puppet | Chef | Salt |
---|---|---|---|---|
Release | 2009 | 2005 | 2009 | 2011 |
Lang. | Python | Ruby | Ruby | Python |
Agentless | Yes! | No | No | Both |
Data from Wikipedia
Order of this list is important...
Source on GitHub