warsztaty ansible
DESCRIPTION
Introduction to Ansible workshopsTRANSCRIPT
![Page 1: Warsztaty ansible](https://reader034.vdocuments.site/reader034/viewer/2022051111/554bb653b4c90530298b47cc/html5/thumbnails/1.jpg)
Wiktor Kołodziej
Automatyzacja z Ansiblemczyli jak zrobić żeby zrobić i się nie narobić
Grzegorz Nosek
![Page 2: Warsztaty ansible](https://reader034.vdocuments.site/reader034/viewer/2022051111/554bb653b4c90530298b47cc/html5/thumbnails/2.jpg)
„the three great virtues
of a programmer:
lazinessimpatiencehubris
— Larry Wall
![Page 3: Warsztaty ansible](https://reader034.vdocuments.site/reader034/viewer/2022051111/554bb653b4c90530298b47cc/html5/thumbnails/3.jpg)
laziness
http://www.flickr.com
/pho
tos/snakph
otograph
y/5004775320
![Page 4: Warsztaty ansible](https://reader034.vdocuments.site/reader034/viewer/2022051111/554bb653b4c90530298b47cc/html5/thumbnails/4.jpg)
Load balancer
App server App server
Database server
nginx
flask/gunicorn
postgresql
![Page 5: Warsztaty ansible](https://reader034.vdocuments.site/reader034/viewer/2022051111/554bb653b4c90530298b47cc/html5/thumbnails/5.jpg)
deployment
configurationmanagementfabric
capistrano
puppetchef
ansible
![Page 6: Warsztaty ansible](https://reader034.vdocuments.site/reader034/viewer/2022051111/554bb653b4c90530298b47cc/html5/thumbnails/6.jpg)
ansible
vpn
provision
config db
repo
template
vm
instance
ca
http://www.flickr.com/photos/dullhunk/6827669146
66playbooks
232templates
85Kof yaml
![Page 7: Warsztaty ansible](https://reader034.vdocuments.site/reader034/viewer/2022051111/554bb653b4c90530298b47cc/html5/thumbnails/7.jpg)
pip install ansible
TADA.*
*modules may have extra dependencies
![Page 8: Warsztaty ansible](https://reader034.vdocuments.site/reader034/viewer/2022051111/554bb653b4c90530298b47cc/html5/thumbnails/8.jpg)
faster and light
ansible
python 2.6+ansible
target host
sshdpython 2.6+module deps
2.5.x + simplejsonif you really have to
ssh
use keys tokeep you sane
![Page 9: Warsztaty ansible](https://reader034.vdocuments.site/reader034/viewer/2022051111/554bb653b4c90530298b47cc/html5/thumbnails/9.jpg)
inventory
/etc/ansible/hosts-i <path-to-inventory>ANSIBLE_HOSTS=<path-to-inv>
![Page 10: Warsztaty ansible](https://reader034.vdocuments.site/reader034/viewer/2022051111/554bb653b4c90530298b47cc/html5/thumbnails/10.jpg)
inventory
localhost
[some_group]host1.example.comhost2 ansible_ssh_host=10.2.3.4host3 any_key=any_value
![Page 11: Warsztaty ansible](https://reader034.vdocuments.site/reader034/viewer/2022051111/554bb653b4c90530298b47cc/html5/thumbnails/11.jpg)
hello, world!
ansible localhost -m pinglocalhost | success >> { "changed": false, "ping": "pong"}
![Page 12: Warsztaty ansible](https://reader034.vdocuments.site/reader034/viewer/2022051111/554bb653b4c90530298b47cc/html5/thumbnails/12.jpg)
hello, world!
ansible localhost -m file \ -a "path=/etc/ansible state=directory"
host pattern
module name
module args
![Page 13: Warsztaty ansible](https://reader034.vdocuments.site/reader034/viewer/2022051111/554bb653b4c90530298b47cc/html5/thumbnails/13.jpg)
basic modules
apt/yum/…file/copy/templatecommand/shell/scriptservice
![Page 14: Warsztaty ansible](https://reader034.vdocuments.site/reader034/viewer/2022051111/554bb653b4c90530298b47cc/html5/thumbnails/14.jpg)
http://www.ansibleworks.com/docs/modules.html
136 default modulesand counting
![Page 15: Warsztaty ansible](https://reader034.vdocuments.site/reader034/viewer/2022051111/554bb653b4c90530298b47cc/html5/thumbnails/15.jpg)
facts
ansible localhost -m setuplocalhost | success >> { "ansible_facts": { "ansible_all_ipv4_addresses": [ "172.16.0.150", "192.168.1.132", ... ], ... }
![Page 16: Warsztaty ansible](https://reader034.vdocuments.site/reader034/viewer/2022051111/554bb653b4c90530298b47cc/html5/thumbnails/16.jpg)
playbooks
---- hosts: localhost vars: - greeting: Hello tasks: - command: echo "{{greeting}}, {{inventory_hostname}}"
ansible-playbook hello.yml
![Page 17: Warsztaty ansible](https://reader034.vdocuments.site/reader034/viewer/2022051111/554bb653b4c90530298b47cc/html5/thumbnails/17.jpg)
playbooks
---- hosts: localhost vars: - greeting: Hello tasks: - command: echo "{{greeting}}, {{inventory_hostname}}"
ansible-playbook hello.yml
gather_facts: true
variables
facts
![Page 18: Warsztaty ansible](https://reader034.vdocuments.site/reader034/viewer/2022051111/554bb653b4c90530298b47cc/html5/thumbnails/18.jpg)
idempotence
f(f(x)) = f(x)
![Page 19: Warsztaty ansible](https://reader034.vdocuments.site/reader034/viewer/2022051111/554bb653b4c90530298b47cc/html5/thumbnails/19.jpg)
idempotence
---- hosts: localhost tasks: - template: src=... dest=... notify: restart mysql
handlers: - name: restart mysql service: name=mysql state=restarted
![Page 20: Warsztaty ansible](https://reader034.vdocuments.site/reader034/viewer/2022051111/554bb653b4c90530298b47cc/html5/thumbnails/20.jpg)
idempotence
---- hosts: localhost tasks: - template: src=... dest=... register: mysql_conf - service: name=mysql state=restarted when: mysql_conf.changed
![Page 21: Warsztaty ansible](https://reader034.vdocuments.site/reader034/viewer/2022051111/554bb653b4c90530298b47cc/html5/thumbnails/21.jpg)
idempotence
---- hosts: localhost tasks: - command: touch /foo creates=/foo - command: rm /bar removes=/bar
![Page 22: Warsztaty ansible](https://reader034.vdocuments.site/reader034/viewer/2022051111/554bb653b4c90530298b47cc/html5/thumbnails/22.jpg)
http://www.flickr.com/photos/botheredbybees/353571858
gotcha!
![Page 23: Warsztaty ansible](https://reader034.vdocuments.site/reader034/viewer/2022051111/554bb653b4c90530298b47cc/html5/thumbnails/23.jpg)
yaml 101
---- hosts: localhost user: "{{some_variable}}" tasks: - debug: msg="hello, {{item}}" with_items: - ansible - world - debug: msg="another task"
- list item
dict key: value
"quotes sometimesmandatory"
![Page 24: Warsztaty ansible](https://reader034.vdocuments.site/reader034/viewer/2022051111/554bb653b4c90530298b47cc/html5/thumbnails/24.jpg)
yaml 101
---[{ "hosts": "localhost", "user": "{{some_variable}}", "tasks": [{ "debug": "msg=hello, {{item}}", "with_items": ["ansible", "world"] }, { "debug": "msg=another task" }]}]
yaml is a json superset(rly!)
![Page 25: Warsztaty ansible](https://reader034.vdocuments.site/reader034/viewer/2022051111/554bb653b4c90530298b47cc/html5/thumbnails/25.jpg)
questions so far?
Let's rock!http://bit.ly/ansible-warsztaty