27
Vagrant & Ansible for local dev and production deployment Christoffer Kaalund : Everplaces @ChrisKaalund

Vagrant and ansible

Embed Size (px)

DESCRIPTION

hh

Citation preview

Page 1: Vagrant and ansible

Vagrant & Ansible for local dev and production

deployment

Christoffer Kaalund : Everplaces@ChrisKaalund

Page 2: Vagrant and ansible
Page 3: Vagrant and ansible

= Local development tool

Page 4: Vagrant and ansible

• Super simple to setup dev env

• Fully reproducible

• Having a setup that is as close to prod as possible

• Works with Chef, Puppet, Ansible & Shell Scripts to

provision your dev env

Page 5: Vagrant and ansible

Vagrant, VirtualBox, Ansible

Page 6: Vagrant and ansible
Page 7: Vagrant and ansible

Application deployment &

Configuration Management

Page 8: Vagrant and ansible

• Agentless - push not pull

• Simple to setup, read and understand

• Wildly powerful

• Easy to extent

• Python

Page 9: Vagrant and ansible

ansible-playbook -i production webserver.yml

Page 10: Vagrant and ansible

ansible-playbook -i production webserver.ymlWHERE

stagingdev

Page 11: Vagrant and ansible

ansible-playbook -i production webserver.ymlWHAT

database.ymlsite.yml (all)

Page 12: Vagrant and ansible

inventories/ dev production

group_vars/ all/ main.yml keys.yml database dev production

host_vars/ ...

site.ymldeploy.yml

roles/ database/ tasks/ main.yml handlers/ main.yml files/ foo.txt templates/ bar.j2 vars/ main.yml web/ ... memcached/ ...

Page 13: Vagrant and ansible

Inventories

Playbooks

inventories/ dev production

group_vars/ all/ main.yml keys.yml database dev production

host_vars/ ...

site.ymldeploy.yml

roles/ database/ tasks/ main.yml handlers/ main.yml files/ foo.txt templates/ bar.j2 vars/ main.yml web/ ... memcached/ ...

Page 14: Vagrant and ansible

Inventories

inventories/ dev production

group_vars/ all/ main.yml keys.yml database dev production

host_vars/ ...

# file: inventories/production

[web]4.2.2.14.2.2.2

[database]8.8.8.8

[production:children]webdatabase

Page 15: Vagrant and ansible

Inventories

inventories/ dev production

group_vars/ all/ main.yml keys.yml database dev production

host_vars/ ...

# file: inventories/production

[web]4.2.2.14.2.2.2

[database]8.8.8.8

[production:children]webdatabase

# file: inventories/dev

[web]192.168.33.16

[database]192.168.33.16

[dev:children]webdatabase

Page 16: Vagrant and ansible

Inventories

inventories/ dev production

group_vars/ all/ main.yml keys.yml database dev production

host_vars/ ...

# file: inventories/production

[web]4.2.2.14.2.2.2

[database]8.8.8.8

[production:children]webdatabase

Group

Page 17: Vagrant and ansible

Inventories

inventories/ dev production

group_vars/ all/ main.yml keys.yml database dev production

host_vars/ ...

# file: inventories/production

[web]4.2.2.14.2.2.2

[database]8.8.8.8

[production:children]webdatabase

Group

Host

Page 18: Vagrant and ansible

Inventories > variables

inventories/ dev production

group_vars/ all/ main.yml keys.yml database dev production

host_vars/ ...

---# file: group_vars/database

db_name: "{{ project_name }}_db"db_user: "{{ project_name }}_pg"db_encoding: UTF8db_collate_and_ctype: en_US.UTF-8db_template: template0

# file: inventories/production

[web]4.2.2.14.2.2.2

[database]8.8.8.8

[production:children]webdatabase

Page 19: Vagrant and ansible

ansible-playbook -i inventories/production site.yml

Page 20: Vagrant and ansible

Playbooks

Playbooks = a list of plays

Page 21: Vagrant and ansible

Playbooks

A play = running tasks on hosts

Page 22: Vagrant and ansible

Playbooks

- hosts: web tasks: - name: Ensure apache is at the latest version yum: pkg=httpd state=latest

- name: Ensure apache is running service: name=httpd state=started

Page 23: Vagrant and ansible

Playbooks

Roles = groups of tasks

Page 24: Vagrant and ansible

Playbooks

# file: site.yml---

- hosts: database sudo: yes sudo_user: root roles: - database

- hosts: web sudo: yes sudo_user: root roles: - memcached - webserver

deploy.ymlsite.yml

roles/ database/ tasks/ main.yml handlers/ main.yml files/ foo.txt templates/ bar.j2 vars/ main.yml web/ ... memcached/ ...

Page 25: Vagrant and ansible

ansible-playbook -i inventories/production site.yml

Page 26: Vagrant and ansible

Playbooks > Roles

roles/ database/ tasks/ main.yml handlers/ main.yml files/ foo.txt templates/ bar.j2 vars/ main.yml

Page 27: Vagrant and ansible

Inventory Playbooks

Groups

Hosts

Roles

Tasks

Modules