introduction to ansible

23

Upload: michael-bahr

Post on 12-Jan-2017

4.413 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Introduction to Ansible
Page 2: Introduction to Ansible

Works on my machine!

“Everybody has a testing evironment. Some people are lucky enough they have a different one for production.”

Page 3: Introduction to Ansible

Manual installation

• Not reproducible

• Hard to maintain

• Expensive

• Bugs, bugs, bugs!

Page 4: Introduction to Ansible

Easy & documentation on the fly

Page 5: Introduction to Ansible

No master, no agents

You

Server

Server

ServerSSH

Page 6: Introduction to Ansible
Page 7: Introduction to Ansible

Playbooks

Plays

Tasks

Inventories

Page 8: Introduction to Ansible

Inventory

[web]

192.168.10.1

192.168.10.2

[db]

192.168.11.1

[cluster]

web

db

[web]

plas-web-[1:20]

[db]

plas-db-[a:c]

[east]

plas-web-[1:10]

{{database_east}}

Page 9: Introduction to Ansible

Tasks

- name: ensure apache is at the latest version

yum: pkg=httpd state=latest

- shell: echo “Hello World!“

Modules!module: param=arg [, ...]

Page 10: Introduction to Ansible

Modules• Cloud Modules

• Clustering Modules

• Commands Modules

• Database Modules

• Files Modules

• Inventory Modules

• Messaging Modules

• Monitoring Modules

• Network Modules

• Notification Modules

• Packaging Modules

• Source Control Modules

• System Modules

• Utilities Modules

• Web Infrastructure Modules

• Windows Modules

425 core modules!(September 2015)

Page 11: Introduction to Ansible

Not enough?

• Create your own!

http://docs.ansible.com/ansible/developing_modules.html

• Use the shell module:- name: do what you want

shell: ./do_all_the_things.sh

Page 12: Introduction to Ansible

Play

- name: ensure apache is at the latest version

yum: pkg=httpd state=latest

- name: write the apache config file

template: src=httpd.j2 dest=/etc/httpd.conf

notify:

- restart apache

- name: ensure apache is running

service: name=httpd state=started

Page 13: Introduction to Ansible

Playbook---

- hosts: web

remote_user: root

vars:

http_proxy=http://main-proxy.eu.company.corp:8080

tasks:

[...]

hosts: db

remote_user: root

tasks:

[...]

Page 14: Introduction to Ansible

File structureinventory

site.yml

roles/

common/

tasks/

main.yml

files/

foo.sh

vars/

web/

db/

Page 15: Introduction to Ansible

Files

common/files/foo.sh

common/tasks/main.yml

- name: copy skript to server

copy: src=foo.sh dest=/tmp/foo.sh

Page 16: Introduction to Ansible

Variables

common/vars/main.yml

app_dir:/my/app/dir

common/tasks/main.yml

- name: copy skript to server

command: mkdir –p {{ app_dir }}

Page 17: Introduction to Ansible

Handlers

common/handlers/main.yml

- name: restart apache

service: name=httpd state=restarted

common/tasks/main.yml

- name: copy configuration

copy: src=httpd.conf dest=/etc/httpd.conf

notify: restart apache

Page 18: Introduction to Ansible

Demo

Page 19: Introduction to Ansible

Demo

Control Machine Requirements

• Python 2.6 or 2.7 (Windows isn’t supported for the control machine)

Managed Node Requirements

• Take Python 2.5 or newer

Page 20: Introduction to Ansible

Demo

Adhoc-Command(https://docs.ansible.com/ansible/intro_adhoc.html)

ansible web –m ping

Playbook-Command(http://docs.ansible.com/ansible/playbooks_intro.html)

ansible-playbook ./playbook.yml

Examples

https://github.com/ansible/ansible-examples

Page 21: Introduction to Ansible

Ansible Tower

http://www.ansible.com/tower

Page 22: Introduction to Ansible

Ansible Galaxy

https://galaxy.ansible.com/

Page 23: Introduction to Ansible

Summary

• Easy to learn

• Easy to read

• Minimal requirements

• Everything you can imagine

• Documentation on the fly

• Works together with Docker