Ansible 2014 8 2014 8 1
1 3 1.1 Ansible..................................... 4 1.2 Ansible................................... 7 1.3 Chef Puppet... 7 1.4 Ansible Better Shell Script............................. 8 2 Ansible 9 2.1... 9 2.2 inventory................................... 12 2.3 (module)... 15 3 playbook 16 3.1 YAML... 16 3.2 playbook................................. 19 3.3 playbook... 20 3.4 task... 23 3.5 handler......................................... 24 3.6... 25 4 playbook 34 4.1 with_items................................. 34 4.2 register......................... 36 4.3 when... 36 4.4 until............................. 38 4.5 lookup... 38 4.6 filter................................. 39 4.7 vars_prompt... 39 4.8 local_action......................... 40 4.9 action.................... 40 4.10 - environment........................... 41 4.11 - ignore_errors... 41 4.12 task async........................... 42 5 playbook 44 5.1 playbook include... 44 5.2.................... 45 5.3 role................................. 46 5.4 fork..................................... 49 5.5 serial... 49 i
5.6 AWS EC2................................... 50 5.7 dynamic inventory.................. 51 6 53 6.1 ssh......................................... 53 6.2 limit............................. 54 6.3 task tag............................. 54 6.4 dry-run check... 55 6.5 task step... 55 6.6 diff..................................... 55 7 ansible-vault 57 7.1 ansible-vault................................. 57 7.2... 59 8 role Ansible Galaxy 60 8.1 Ansible Galaxy... 60 8.2 role..................................... 60 8.3 role... 61 8.4 role... 63 9 64 9.1... 64 9.2 ControlPath too long....................... 64 9.3... 65 9.4 inventory....................... 65 9.5 playbook....................... 65 9.6 python not found......................... 65 9.7 Windows... 66 9.8 ansible-playbook... 66 9.9 ansible... 66 9.10 invalid type <type list >............................. 66 9.11 Syntax Error...................... 67 9.12 ---................................. 67 9.13 Ansible............................. 67 10 68 A 69 A.1................................... 69 A.2................................... 70 A.3................................. 71 A.4 Python... 71 A.5................................. 72 B plugin 73 B.1 plugin... 73 ii
B.2 lookup plugin... 73 B.3 filter plugin....................................... 74 B.4 callback plugin..................................... 75 B.5 action plugin... 76 B.6 connection type plugin................................. 77 B.7 vars plugin... 77 C ansible config 78 C.1 default................................... 78 C.2 paramiko... 80 C.3 ssh_connection............................... 80 C.4 accelerate... 81 82 iii
Ansible Ansible Ansible Ansible Ansible Ansible 1 Ansible 2 Ansible Ansible ansible 3 playbook playbook ansible-playbook 4 playbook 3 5 playbook role 6 7 ansible-vault ansible-vault 8 role Ansible Galaxy role Ansible Galaxy Ansible 1
tboffice futoase 2
1 Ansible Ansible Ansible Ansible : Ansible GitHub (GPL v3) Ansible ( ) 300 GitHub 6000 GitHub 3
1.1 Ansible Ansible 1.1.1 ssh Chef Puppet Ansible ssh ( Python OS ) ssh UNIX OS Ansible ssh Ansible 1.1.2 Ansible 1 inventory 192.168.0.1 192.168.0.2 IP $ ansible all -m command -a "uptime" intenvory uptime playbook inventory 1.1. Ansible 4
1.1.3 Ansible Ansible 1.1.4 (Idempotency) spam 2 spam Ansible Ansible 1.1.5 shell script Ansible script shell script shell script 1.1.6 Ansible Python Python 2 inventory playbook YAML 1.1. Ansible 5
--- - hosts: all tasks: - name: yum yum: name={{ item }} state=present with_items: - python - ruby - name: foo.sh script: foo.sh - name UTF-8 1.1.7 Ansible Batteries included( : ) htpasswd Google Computing Engine Amazon Route53 nagios ( / ) arista ( ) apache2 / Ansible HTTP Ansible Ansible 1.1.8 Ansible Ansible 1.1. Ansible 6
Chef Puppet Capistrano Fabric Ansible Ansible 1.2 Ansible Ansible Ansible Ansible 5 Simply Clear ( ) Simply Fast ( ) Simply Complete ( ) Simply Efficient (ssh ) Simply Secure (ssh ) Simply 1.3 Chef Puppet CFEngine Puppet Chef Ansible 1.1: Chef Puppet UI Chef Ruby Puppet DSL Ansible ssh YAML (Ansible Tower) Ansible ssh Chef chef-solo Ansible ssh 1.2. Ansible 7
Chef Ansible Ansible dynamic inventory Chef UI Amazon AWS CloudFormation Chef Amazon EC2 Chef Ansible Ansible Shell Script Ruby 1.4 Ansible Better Shell Script Ansible Better Shell Script Chef Puppet Ansible playbook shell script playbook playbook Ansible shell script Ansible Ansible 1.4. Ansible Better Shell Script 8
2 Ansible 1. Ansible 2. inventory 3. module 3 2.1 Ansible Ansible 2.1.1 Ansible Python 2.6 OS Python : Ansible Python3 Ansible 1.6.6 2.1.2 Ansible OS Ansible 9
ansible ansible ansible-playbook Playbook ansible-vault ansible-galaxy playbook ansible-playbook yum EPEL RPM EPEL $ sudo yum install ansible RPM $ git clone git://github.com/ansible/ansible.git $ cd./ansible $ make rpm $ sudo rpm -Uvh ~/rpmbuild/ansible-*.noarch.rpm rpm-build python2-devel apt PPA $ sudo apt-add-repository ppa:rquillo/ansible $ sudo apt-get update $ sudo apt-get install ansible deb $ make deb pkg FreeBSD $ sudo pkg install ansible 2.1. 10
Homebrew Mac OS X Homebrew $ brew update $ brew install ansible pip Ansible Python Python pip $ pip install ansible : OS X Mavericks $ sudo CFLAGS=-Qunused-arguments CPPFLAGS=-Qunused-arguments \ pip install ansible 2.1.3 Ansible Python 2.6 2.4 2.4 # CentOS $ sudo yum install python-simplejson # Debian $ sudo apt-get install python-simplejson # FreeBSD $ sudo pkg install py27-simplejson Ansible raw Ansible $ ansible all -m raw -a yum -y install python-simplejson Ansible Ansible 2.1. 11
1. inventory 2. playbook task 3. ansible.cfg Ansible Ansible inventory inventory 2.2 inventory inventory ini ( ini ) /etc/ansible/hosts Ansible mail.example.com [web] web01.example.com web02.example.com web03.example.com [db] db01.example.com db02.example.com [webservers] [db] web01 db01 web web01.example.com web02.example.com web03.example.com 3 mail.example.com ansible ( ssh ) $ ansible all -m command -a "uptime" mail.example.com success rc=0 >> 23:51:40 up 33 days, 1:55, 2 users, load average: 1.17, 1.21, 1.20 web01.example.com success rc=0 >> 23:51:41 up 29 days, 12:22, 2 users, load averages: 0.36, 0.28, 0.18 ( ) uptime 2.2. inventory 12
db $ ansible db -m command -a "uptime" db01.example.com success rc=0 >> 23:55:11 up 33 days, 1:55, 2 users, load averages: 0.41, 0.30, 0.20 db01.example.com success rc=0 >> 23:55:11 up 29 days, 12:22, 2 users, load averages: 1.11, 1.07, 1.09 db $ ansible web02.example.com -m command -a "uptime" web02.example.com success rc=0 >> 23:58:32 up 29 days, 1:55, 2 users, load averages: 0.13, 0.20, 0.17 : www*.example.com www www[01:50].example.com www01 www50 web:db web db (or ) web!ng web ng (not ) web:&prod web prod (and ) web:!{{excluded}}:&{{required}} 2.2.1 web01.example.com ansible_ssh_port=2222 ansible_ssh_host=192.168.1.50 web01 192.168.1.50 2222 ansible_ssh_user ssh ansible_ssh_private_key_file 2.2. inventory 13
ansible_connection ssh : Linux Ansible Python /usr/bin/python FreeBSD /usr/local/bin/python ansible_python_interpreter freebsd_host ansible_python_interpreter=/usr/local/bin/python 2.2.2 ansible_ssh_port :vars [web] web01.example.com [web:vars] ansible_ssh_port=2222 ansible_ssh_user=admin web 2.2.3 children [eggservice:children] eggweb eggdb [eggweb] web01.example.com web02.example.com [eggdb] db01.example.com db02.example.com eggservice eggweb * web01 * web02 2.2. inventory 14
eggdb * db01 * db02 2.3 (module) inventory (module) setup setup IP setup inventory $ ansible all -m setup web02.example.com success >> { "ansible_facts": { "ansible_all_ipv4_addresses": [ "192.168.122.1" ], "ansible_all_ipv6_addresses": [ "fe80::a00:27ff:fe99:ebc3", ], "ansible_architecture": "x86_64", "ansible_bios_date": "12/01/2006", "ansible_bios_version": "VirtualBox", ansible_all_ipv4_addresses IP inventory module ansible-playbook 2.3. (module) 15