Upload
wefner
View
45
Download
2
Embed Size (px)
DESCRIPTION
Find out all course material here: https://github.com/wefner/ansible-vagrant
Citation preview
S
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 not created (virtualbox) db not created (virtualbox) proxy not created (virtualbox) $ vagrant up --provision
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
Know more
$ ansible 'db' -i enviro/vagrant/hosts -m setup -u vagrant
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
S Within groups
S Host/group variables
S Group of groups
$ cat /etc/ansible/hosts
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
S Jinja2 language
S Develop your own plugins!
S Keep logic according to task/hosts variables
S 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
S Master password S From file S On demand
Know more
$ 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
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