introduction to ansible

Post on 12-Jan-2017

4.413 Views

Category:

Software

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Works on my machine!

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

Manual installation

• Not reproducible

• Hard to maintain

• Expensive

• Bugs, bugs, bugs!

Easy & documentation on the fly

No master, no agents

You

Server

Server

ServerSSH

Playbooks

Plays

Tasks

Inventories

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}}

Tasks

- name: ensure apache is at the latest version

yum: pkg=httpd state=latest

- shell: echo “Hello World!“

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

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)

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

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

Playbook---

- hosts: web

remote_user: root

vars:

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

tasks:

[...]

hosts: db

remote_user: root

tasks:

[...]

File structureinventory

site.yml

roles/

common/

tasks/

main.yml

files/

foo.sh

vars/

web/

db/

Files

common/files/foo.sh

common/tasks/main.yml

- name: copy skript to server

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

Variables

common/vars/main.yml

app_dir:/my/app/dir

common/tasks/main.yml

- name: copy skript to server

command: mkdir –p {{ app_dir }}

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

Demo

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

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

Ansible Tower

http://www.ansible.com/tower

Ansible Galaxy

https://galaxy.ansible.com/

Summary

• Easy to learn

• Easy to read

• Minimal requirements

• Everything you can imagine

• Documentation on the fly

• Works together with Docker

top related