Vagrant and ansible
-
Upload
manicflight -
Category
Engineering
-
view
259 -
download
0
description
Transcript of Vagrant and ansible
Vagrant & Ansible for local dev and production
deployment
Christoffer Kaalund : Everplaces@ChrisKaalund
= Local development tool
• 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
Vagrant, VirtualBox, Ansible
Application deployment &
Configuration Management
• Agentless - push not pull
• Simple to setup, read and understand
• Wildly powerful
• Easy to extent
• Python
ansible-playbook -i production webserver.yml
ansible-playbook -i production webserver.ymlWHERE
stagingdev
ansible-playbook -i production webserver.ymlWHAT
database.ymlsite.yml (all)
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/ ...
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/ ...
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
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
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
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
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
ansible-playbook -i inventories/production site.yml
Playbooks
Playbooks = a list of plays
Playbooks
A play = running tasks on hosts
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
Playbooks
Roles = groups of tasks
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/ ...
ansible-playbook -i inventories/production site.yml
Playbooks > Roles
roles/ database/ tasks/ main.yml handlers/ main.yml files/ foo.txt templates/ bar.j2 vars/ main.yml
Inventory Playbooks
Groups
Hosts
Roles
Tasks
Modules