Top Banner
Wiktor Kołodziej Automatyzacja z Ansiblem czyli jak zrobić żeby zrobić i się nie narobić Grzegorz Nosek
25

Warsztaty ansible

May 08, 2015

Download

Technology

gnosek

Introduction to Ansible workshops
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Warsztaty ansible

Wiktor Kołodziej

Automatyzacja z Ansiblemczyli jak zrobić żeby zrobić i się nie narobić

Grzegorz Nosek

Page 2: Warsztaty ansible

„the three great virtues

of a programmer:

lazinessimpatiencehubris

— Larry Wall

Page 3: Warsztaty ansible

laziness

http://www.flickr.com

/pho

tos/snakph

otograph

y/5004775320

Page 4: Warsztaty ansible

Load balancer

App server App server

Database server

nginx

flask/gunicorn

postgresql

Page 5: Warsztaty ansible

deployment

configurationmanagementfabric

capistrano

puppetchef

ansible

Page 6: Warsztaty ansible

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

pip install ansible

TADA.*

*modules may have extra dependencies

Page 8: Warsztaty ansible

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

inventory

/etc/ansible/hosts-i <path-to-inventory>ANSIBLE_HOSTS=<path-to-inv>

Page 10: Warsztaty ansible

inventory

localhost

[some_group]host1.example.comhost2 ansible_ssh_host=10.2.3.4host3 any_key=any_value

Page 11: Warsztaty ansible

hello, world!

ansible localhost -m pinglocalhost | success >> { "changed": false, "ping": "pong"}

Page 12: Warsztaty ansible

hello, world!

ansible localhost -m file \ -a "path=/etc/ansible state=directory"

host pattern

module name

module args

Page 13: Warsztaty ansible

basic modules

apt/yum/…file/copy/templatecommand/shell/scriptservice

Page 14: Warsztaty ansible

http://www.ansibleworks.com/docs/modules.html

136 default modulesand counting

Page 15: Warsztaty ansible

facts

ansible localhost -m setuplocalhost | success >> { "ansible_facts": { "ansible_all_ipv4_addresses": [ "172.16.0.150", "192.168.1.132", ... ], ... }

Page 16: Warsztaty ansible

playbooks

---- hosts: localhost vars: - greeting: Hello tasks: - command: echo "{{greeting}}, {{inventory_hostname}}"

ansible-playbook hello.yml

Page 17: Warsztaty ansible

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

idempotence

f(f(x)) = f(x)

Page 19: Warsztaty ansible

idempotence

---- hosts: localhost tasks: - template: src=... dest=... notify: restart mysql

handlers: - name: restart mysql service: name=mysql state=restarted

Page 20: Warsztaty ansible

idempotence

---- hosts: localhost tasks: - template: src=... dest=... register: mysql_conf - service: name=mysql state=restarted when: mysql_conf.changed

Page 21: Warsztaty ansible

idempotence

---- hosts: localhost tasks: - command: touch /foo creates=/foo - command: rm /bar removes=/bar

Page 22: Warsztaty ansible

http://www.flickr.com/photos/botheredbybees/353571858

gotcha!

Page 23: Warsztaty ansible

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

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

questions so far?

Let's rock!http://bit.ly/ansible-warsztaty