1. 2015/8/4
2. 2
3. Michael DeHaan 3
4. LinuxPython SSH Python 2.6 or 2.7 Python 3 Ansible 2.x
Windows Cygwin Python 2.4 or later 2.5 python-simplejson 4
5. 5 1. ssh 3. execute command 2. sftp (send task) 4. result
[control machine] [managed node]
6. 6 [control machine] [managed nodes]
7.
8. (PIP) Mac OS X, BSDs $ sudo easy_install pip Python 2.7.9
and later include pip by default $ sudo pip install ansible 8
9. (YUM) CentOS, RHEL, or Scientific Linux $ sudo yum install
ansible 9
10. (APT) Ubuntu $ sudo apt-get install
software-properties-common $ sudo apt-add-repository
ppa:ansible/ansible $ sudo apt-get update $ sudo apt-get install
ansible 10
11. $ ansible version ansible 1.9.2 11
12. Inventory Playbook 12
13. /etc/ansible/hosts ANSIBLE_HOSTS (-i) YAML INI INI
(Behavioral Inventory Parameters) 13
14. [webservers] foo.example.com bar.example.com [dbservers]
one.example.com two.example.com three.example.com 14 [webservers]
www[01:50].example.com [databases] db-[a:f].example.com
15. (ANSIBLE) Synopsis: $ ansible [-f forks] [-m module_name]
[-a args] example: $ ansible all -m ping $ ansible webserver* -m
ping $ ansible webservers:dbservers -m ping $ ansible
webservers:!webserver01 -m ping 15
16. (ANSIBLE) $ ansible webserver01 -m ping webserver01 |
success >> { "changed": false, "ping": "pong" } 16
17. 17 Python PythonShellScript YAML YAML plays
18. target hosts vars tasks 18
19. --- - hosts: dbservers user: root tasks: - name: install
mysql yum: name=mysql state=installed 19
20. (ANSIBLE-PLAYBOOK) Synopsis: $ ansible-playbook [-f forks]
[-i inventory] [--check] [--check] : dry-run option
[--syntax-check] : YAML syntax check option $ ansible-playbook
mysql.yml 20
21. (ANSIBLE-PLAYBOOK) $ ansible-playbook mysql.yml PLAY
[dbservers]
********************************************************* GATHERING
FACTS ******************************************************* ok:
[192.168.100.101] TASK: [install mysql]
******************************************************* changed:
[192.168.100.101] PLAY RECAP
**************************************************************
192.168.100.101 : ok=2 changed=1 unreachable=0 failed=0 21
22. --- - hosts: dbservers user: root tasks: - name: install
mysql yum: name=mysql state=installed - name: install mysql-server
yum: name=mysql-server state=installed - name: install mysql-devel
yum: name=mysql-devel state=installed 22
23. --- - hosts: dbservers user: root tasks: - name: install
mysql packages yum: name=$item state=installed with_items: - mysql
- mysql-server - mysql-devel 23
24. include roles conditionals when loop 24 tags prompts error
handling
25.
26. Core Modules Extras Modules Core 26
27. Cloud Modules Clustering Modules Commands Modules Database
Modules Files Modules Inventory Modules Messaging Modules 27
Monitoring Modules Network Modules Notification Modules Packaging
Modules Source Control Modules System Modules Utilities Modules Web
Infrastructure Modules Windows Modules
28. copy file yum yumtemplate synchronize rsync 28
29. service servicecommand shell , | , & shellshell
(/bin/sh)mysql_db MySQL mysql_user MySQL 29
30. --- - name: be sure mysql-server is installed yum: name={{
item }} state=installed with_items: - mysql-server - MySQL-python
tags: mysqld - name: be sure mysqld is running and enabled service:
name=mysqld state=running enabled=yes tags: mysqld 30 - name:
Create database mysql_db: db={{ dbname }} state=present
encoding=utf8 tags: mysqld - name: Create database user mysql_user:
> name={{ dbuser }} password="{{ dbpassword }}" priv={{ dbname
}}.*:ALL state=present tags: mysqld
31. Python Python key=valueJSON 31
32. #!/usr/bin/python import datetime import json date =
str(datetime.datetime.now()) print json.dumps({ "time" : date })
32
33.
34. Puppet Chef Salt Fabric + Cuisine Ansible 34
35. 35 author or
36. 36 2005Luke Kanies Ruby Puppet Labs DSLRuby Puppet
Forge
37. 37 2009Adam Jacob Ruby chef-client Erlang Erchef Chef
Opescode DSLRuby Chef Supermarket
38. 38 PythonChef 2011Thomas S Hatch Python Saltstack YAML or
DSLPython
39. 39 Fabric 2011Jeff Forcier, FabricSbastien Pierre, Cuisine
Ruby DSLPythonFabric
40. 2012Michael DeHaan Python Ansible YAML Ansible Galaxy
40
41. 41 CONFIGURATION MANAGEMENT
42.
43. Ansible is used by Atlassian, Twitter, OneKingsLane,
Evernote, TrunkClub, edX, hootsuite, GoPro, NewsCred, and Care.com,
among others. (from wikipedia) 43
44. Lightweight Language, Python, Perl, PHP, Ruby DSL (Domain
Specific Language) DSL YAML JSON JSON 44
45. Disposable Infrastructure Immutable Infrastructure
Infrastructure as Code SOASOA 45
46.
47. An ansible is a fictional machine capable of instantaneous
or superluminal communication. S.F. Ursula K. Le Guin in her 1966
novel Rocannons World 1st of Hainish Cycle series Welcome to
Ansible Galaxy https://galaxy.ansible.com/ 47
48. ANSIBLE http://docs.ansible.com/ 1.9.2 "Dancing In the
Street" - Jun 26, 2015 Release Van Halen 1.8 "You Really Got Me,
1.7 "Summer Nights, 1.6 "And the Cradle Will Rock, 1.0 "Eruption"
48
49. Jinja2 Python Temple, Shinto shrine Welcome to Jinja2
http://jinja.pocoo.org/docs/dev/ 49
LOAD MORE