Why Ansible?
- Easy to Read (YAML)
- Easy to Use (Modules Support)
- Smooth Learning Curve
- Lower Complexity, Higher Productivity
- Agentless, NO AGENT, 100% Clean
- Written in Python (Friendly to Linux Systems)
- Supported by RedHat and Communities
Comparison
Language Agent Configuration Communication Difficulty
Ansible Python No YAML OpenSSH ★☆
Chef Ruby, Erlang Yes Ruby SSL ★★★★
Puppet Ruby Yes Puppet DSL SSL ★★★☆
SaltStack Python Yes YAML ZeroMQ ★★☆
The Basic Knowledge You Should Have
Operation System
- Debian, Ubuntu, CentOS, RedHat
- Windows / Windows Server
Scripting Languages
- Bash or Native Shell for Linux-Based System
- PowerShell or BatchScript for Windows System
How does it work?
Variables
Inventories
Playbooks
Compile
OpenSSH
or WinRM
Target ServersResources
Inventory
An INI-like configuration file for Host/Group definition
[webapp]
web1.example.com
web2.example.com
[mysql]
mysql1.example.com
mysql2.example.com
[postgres]
psql1.example.com
[mysql]
mysql1.example.com
mysql2.example.com
[postgres]
psql1.example.com
[database:children]
mysql
postgres
[database:vars]
foo=bar
Variable
Host/Group specific settings for the target defined in inventory
<top-dir>
host_vars/
- mysql1.example.com
group_vars/
- mysql
- postgres
ansible_user=ubuntu
ansible_port=2222
ansible_private_key_file=private_key
# ansible_ssh_private_key_file=private_key
Setup Ansible on Control Node
$ add-apt-repository ppa:ansible/ansible
$ apt-get update
$ apt-get install ansible
OR
$ pip install ansible
Limitation for Control Node
Control Node is recommend to be Linux, or Windows Subsystem for Linux (WSL)
- http://docs.ansible.com/ansible/intro_windows.html#using-a-windows-control-machine
Additional Setup for Controlling Windows
To control Windows Slave with local User Account, no additional setup required
To control Windows Slave with AD Account, the easiest way is to setup Kerberos
$ apt-get install python-dev libkrb5-dev krb5-user
$ pip install pywinrm[kerberos] # include “brackets”
$ vim /etc/krb5.conf
http://docs.ansible.com/ansible/intro_windows.html#kerberos
Additional Setup for the Windows Slave Nodes
The older Windows require extra setup to meet basic requirements
1. Windows 7, 8, Windows Server 2008 R2
a. .Net Framework >= 4.0 (reboot required)
b. PowerShell >= 3.0 (reboot required)
2. Windows Remote Management (WinRM)
3. Apply Hotfix for Windows 7, 8, Windows Server 2008 R2, 2012
http://docs.ansible.com/ansible/intro_windows.html#windows-system-prep
What About Linux Slave?
Nope… there’s no prerequisites for Linux slave, except login user account… :-)
Ansible Ad-hoc Mode (Linux)
$ ansible linux -m ping
$ ansible linux -m shell -a 'echo hello-world'
$ ansible linux -m stat -a 'path=/etc/passwd'
Ansible Ad-hoc Mode (Windows)
$ ansible windows -m win_ping
$ ansible windows -m win_shell -a 'echo hello-world'
$ ansible windows -m win_stat -a 'path=C:Users'
Gathering Facts
$ ansible all -m setup
$ ansible linux -m setup
$ ansible windows -m setup
$ ansible all -m setup -a 'filter=ansible_*'
$ ansible all -m setup -a 'gather_subset=network'
http://docs.ansible.com/ansible/setup_module.html
Playbook
Define the behaviour of the “role” - playbook/
- tasks/
- main.yml
- defaults/
- main.yml
- handlers/
- main.yml
- templates/
Modules Supoprt
All Modules
- http://docs.ansible.com/ansible/modules_by_category.html
Windows Specific Modules
- http://docs.ansible.com/ansible/list_of_windows_modules.html
Ansible Galaxy - Playbooks by Community
https://galaxy.ansible.com/list#/roles