100% found this document useful (2 votes)
2K views26 pages

Vagrant and Ansible Training

This document discusses using Ansible and Vagrant together. It introduces Vagrant as a tool for creating portable development environments that can be provisioned with Ansible. It then summarizes some key features of Ansible, including its use of YAML files, modules, roles, templates and playbooks to automate configuration management. The document also provides instructions for setting up a basic Vagrant environment with Ansible and describes additional Ansible concepts like dynamic inventory, vaults, plugins and the Tower GUI.

Uploaded by

wefner
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
2K views26 pages

Vagrant and Ansible Training

This document discusses using Ansible and Vagrant together. It introduces Vagrant as a tool for creating portable development environments that can be provisioned with Ansible. It then summarizes some key features of Ansible, including its use of YAML files, modules, roles, templates and playbooks to automate configuration management. The document also provides instructions for setting up a basic Vagrant environment with Ansible and describes additional Ansible concepts like dynamic inventory, vaults, plugins and the Tower GUI.

Uploaded by

wefner
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

Ansible & Vagrant

ecosystem

Oriol Fbregas Bull

Who am I?

S DevOps Enthusiast
S Using Ansible for over a year
S Love automation
S Love challenges
S 3 years in Telefnica R+D

Why Vagrant?

S Great development environment


S Portable to many platforms
S Widely customizable
S Ansible provisioning
S Many providers
S Excellent for trainings!

And why Ansible?

S Simple YAML playbooks


S Good conditional statements
S Ansible Facts
S Run tasks on hosts
S Speed

About this training


S Basic 3 nodes
S MySQL
S Nginx
S Wordpress on Apache
S Advanced 10 nodes
S MySQL cluster
S Nginx
S Apache cluster
S GlusterFS cluster
S Source Code

Vagrant setup

$ git clone https://github.com/wefner/ansible-vagrant.git


$ cd ansible-vagrant/
$ vagrant plugin install vagrant-host-shell
$ vagrant box add chef/centos-6.5 --provider virtualbox
$ cd basic/
$ vagrant status
Current machine states:
web
db
proxy
$ vagrant up --provision

not created (virtualbox)


not created (virtualbox)
not created (virtualbox)

Vagrantfile
S Hosts and hardware specs
S OS to load from
S Port forwarding
S Ansible provision

Know more

Ansible components

S Ansible
S Ansible-playbook
S Ansible-vault
S Ansible galaxy
S Ansible Tower

Getting started

S Install ansible
S Get familiar with:
S YAML
S JINJA2

S Check if Tower fits your needs


S Vagrant interface

$ pip install ansible


$ brew install sshpass

What is YAML?
S Everything in Ansible are files
S Most of them are YAML files
S YAML is simple to define structured data
array_example:
- value1
- value2
- value3

literal: value

hash_example:
key1: value1
key2: value2
key3: value3

Ansible.cfg

S Configuration settings
S Default behavior
S Global

Know more

Ansible adhoc

$ ansible 'db' -i enviro/vagrant/hosts -m ping -u vagrant

Know more

Ansible Facts
S Returns facts from hosts
S Set them as variables for Ansible
$ ansible 'db' -i enviro/vagrant/hosts -m setup -u vagrant

Know more

ansible-playbook

$ ansible-playbook i enviro/vagrant/hosts e pub_file=~/id_rsa.pub e user=vagrant

Know more

Inventory

S Where your hosts are defined

$ cat /etc/ansible/hosts

S Within groups
S Host/group variables
S Group of groups

Know more

Dynamic inventory

S Script that outputs JSON file


S JSON file that Ansible will read
S Integration with:
S EC2
S LDAP
S CMDB
S Cobbler

Modules

S Libraries for playbooks


S Everybody can submit PR
S Can control system resources
S Essential
S Takes arguments as key=value

Roles

S Set a number of tasks as roles


S Define what servers should have running
S Default variables capability
S Conditionals
S Jinja2 templates

Know more

Handlers
S Shortcuts called by tasks when changed

Templates

Jinja2 language

Develop your own plugins!

Keep logic according to task/hosts variables

The less logic inside templates the better

Know more

Tasks

S List of things you want to do. Period.


S Use of conditionals
S Use of variables
S Call handlers
S Tags

Know more

Run playbooks

S Main playbook definitions


S You can
S Set roles
S Set hosts
S Set variables
S Set conditions

$ ansible-playbook -i enviro/vagrant/hosts lamp.yml -limit proxy

Vault

S Secure playbooks
S Useful for variables as
S Certificates
S Passwords
S Private keys

$ vim playbook.yml
$ ansible-vault encrypt playbook.yml
Vault password:
Confirm Vault password:
Encryption successful
$ echo password > secret.txt
$ ansible-playbook playbook-yml \
--vault-password-file=secret.txt

S Master password
S From file
S On demand
Know more

Plugins

S Connection Type Plugins


S Lookup Plugins
S Vars Plugins
S Filter plugins
S Callbacks

Know more

Tower

S Licenced feature
S GUI framework
S User/group grants
S Playbook history
S Scheduled jobs

Q/A
source: inc.com

You might also like