Upload
gnosek
View
3.665
Download
0
Embed Size (px)
DESCRIPTION
Introduction to Ansible workshops
Citation preview
Wiktor Kołodziej
Automatyzacja z Ansiblemczyli jak zrobić żeby zrobić i się nie narobić
Grzegorz Nosek
„the three great virtues
of a programmer:
lazinessimpatiencehubris
— Larry Wall
laziness
http://www.flickr.com
/pho
tos/snakph
otograph
y/5004775320
Load balancer
App server App server
Database server
nginx
flask/gunicorn
postgresql
deployment
configurationmanagementfabric
capistrano
puppetchef
ansible
ansible
vpn
provision
config db
repo
template
vm
instance
ca
http://www.flickr.com/photos/dullhunk/6827669146
66playbooks
232templates
85Kof yaml
pip install ansible
TADA.*
*modules may have extra dependencies
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
inventory
/etc/ansible/hosts-i <path-to-inventory>ANSIBLE_HOSTS=<path-to-inv>
inventory
localhost
[some_group]host1.example.comhost2 ansible_ssh_host=10.2.3.4host3 any_key=any_value
hello, world!
ansible localhost -m pinglocalhost | success >> { "changed": false, "ping": "pong"}
hello, world!
ansible localhost -m file \ -a "path=/etc/ansible state=directory"
host pattern
module name
module args
basic modules
apt/yum/…file/copy/templatecommand/shell/scriptservice
http://www.ansibleworks.com/docs/modules.html
136 default modulesand counting
facts
ansible localhost -m setuplocalhost | success >> { "ansible_facts": { "ansible_all_ipv4_addresses": [ "172.16.0.150", "192.168.1.132", ... ], ... }
playbooks
---- hosts: localhost vars: - greeting: Hello tasks: - command: echo "{{greeting}}, {{inventory_hostname}}"
ansible-playbook hello.yml
playbooks
---- hosts: localhost vars: - greeting: Hello tasks: - command: echo "{{greeting}}, {{inventory_hostname}}"
ansible-playbook hello.yml
gather_facts: true
variables
facts
idempotence
f(f(x)) = f(x)
idempotence
---- hosts: localhost tasks: - template: src=... dest=... notify: restart mysql
handlers: - name: restart mysql service: name=mysql state=restarted
idempotence
---- hosts: localhost tasks: - template: src=... dest=... register: mysql_conf - service: name=mysql state=restarted when: mysql_conf.changed
idempotence
---- hosts: localhost tasks: - command: touch /foo creates=/foo - command: rm /bar removes=/bar
http://www.flickr.com/photos/botheredbybees/353571858
gotcha!
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"
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!)
questions so far?
Let's rock!http://bit.ly/ansible-warsztaty