Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Vagrant Provisioning with Ansible
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Erika Heidi
July 18, 2015
Programming
990
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Vagrant Provisioning with Ansible
As presented at PHP Southcoast 2015
Erika Heidi
July 18, 2015
More Decks by Erika Heidi
See All by Erika Heidi
FreeCAD 101 Lightning Talk
erikaheidi
0
67
Learning Lab: WordPress
erikaheidi
0
150
Criando Container Runtimes mais Seguras com Wolfi
erikaheidi
0
220
Introducing Chainguard Images for Safer PHP Runtimes
erikaheidi
0
270
Automatizando documentação em PHP com Autodocs
erikaheidi
0
200
Building the World: The Story Behind Wolfi
erikaheidi
0
850
Hello Wolfi
erikaheidi
1
820
Container Images for the Cloud Native Era
erikaheidi
1
480
Creating Secure Container Images with apko
erikaheidi
0
670
Other Decks in Programming
See All in Programming
Modding RubyKaigi for Myself
yui_knk
0
910
jQueryをバージョンアップする前に使いたいjQuery Migrate
matsuo_atsushi
0
200
LLM Plugin for Node-REDの利用方法と開発について
404background
0
160
キャリア迷子上等 ─ "ない道"は自分で作ればいい
16bitidol
3
1.9k
ユニットテストの先へ:テスト技法で要求・仕様を整理するJava開発実践 / Beyond_Unit_Testing_Practical_Java_Development_Techniques_for_Organizing_Requirements_and_Specifications
shimashima35
0
380
Make SRE Operations Easier with Azure SRE Agent
kkamegawa
0
4.9k
脅威をエンジニアリングの糧にして――現場編 / Turning Threats into Engineering Fuel — Field Edition
nrslib
0
260
Webフレームワークの ベンチマークについて
yusukebe
0
150
ふつうのFeature Flag実践入門
irof
7
3.7k
A2UI という光を覗いてみる
satohjohn
1
120
The ROI of Quarkus for Spring Boot Applications
hollycummins
0
100
運用エージェントは "作る" から "育てる" へ - 記憶と自己進化の3層設計パターン / self-evolving-agents-three-layer-agent-design
gawa
12
3.6k
Featured
See All Featured
[SF Ruby Conf 2025] Rails X
palkan
2
1.1k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
310
4 Signs Your Business is Dying
shpigford
187
22k
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
250
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2k
Reality Check: Gamification 10 Years Later
codingconduct
0
2.2k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.2k
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
Docker and Python
trallard
47
3.9k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
940
Utilizing Notion as your number one productivity tool
mfonobong
4
320
How Software Deployment tools have changed in the past 20 years
geshan
0
34k
Transcript
None
whoami
What to expect from this talk 1. Vagrant: quick recap
2. Ansible Overview 3. Playbook crash-course 4. Standalone Ansible
VAGRANT: QUICK RECAP
None
ANSIBLE OVERVIEW
Ansible Overview • Simple and Straightforward • Human-readable automation language
• Agentless - needs only SSH • Extensive list of built-in modules • Used by Twitter, Atlassian, EA, Spotify, even NASA!
Installation $ brew update $ brew install ansible $ sudo
apt-add-repository -y ppa:ansible/ansible $ sudo apt-get update $ sudo apt-get install -y ansible Detailed installation instructions: do.co/ansible-docs Mac OSX Ubuntu *Windows is not officially supported as controller machine.
A Simple Playbook # playbook.yml --- - hosts: all sudo:
true tasks: - name: Update apt-cache apt: update_cache=yes - name: Install Nginx apt: pkg=nginx state=latest
Ansible Output
Ansible Output (with cowsay)
Ansible as Provisioner #Vagrantfile Vagrant.configure("2") do |config| config.vm.box = "hashicorp/precise64"
config.vm.provision "ansible" do |ansible| ansible.playbook = "playbook.yml" end end
DEMO
None
WRITING PLAYBOOKS
Variables --- - hosts: all sudo: yes vars: web_server: nginx
tasks: - name: Install {{ web_server }} apt: pkg={{ web_server }} state=latest
Facts
Conditionals - name: "shutdown Debian flavored systems" command: /sbin/shutdown -t
now when: ansible_os_family == "Debian" - name: foo is not defined fail: msg="Bailing out. this play requires 'bar'" when: bar is not defined
Looping: with_items tasks: - name: Install Packages apt: pkg={{ item
}} state=latest with_items: - nginx - php5-fpm - git
Looping: with_items --- - hosts: all sudo: yes vars: sys_packages:
[ 'nginx', 'php5-fpm', 'git' ] tasks: - name: Install Packages apt: pkg={{ item }} state=latest with_items: sys_packages
Templates <VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot {{ doc_root }} <Directory
{{ doc_root }}> AllowOverride All Require all granted </Directory> </VirtualHost>
Templates - Usage - name: Change default apache vhost template:
src=templates/apache.tpl dest=/etc/apache2/sites-available/000-default.conf
Handlers (services) --- - hosts: all sudo: yes vars: -
doc_root: /vagrant tasks: - name: Change default apache vhost template: src=templates/apache.tpl dest=/etc/apache2/sites- available/000-default.conf notify: restart apache handlers: - name: restart apache service: name=apache2 state=restarted
Handlers (services) --- - hosts: all sudo: yes vars: -
doc_root: /vagrant tasks: - name: Change default apache vhost template: src=templates/apache.tpl dest=/etc/apache2/sites- available/000-default.conf notify: restart apache handlers: - name: restart apache service: name=apache2 state=restarted
None
ORGANIZING PLAYBOOKS
Including Tasks --- - hosts: all sudo: true vars: doc_root:
/vagrant/web tasks: - include: tasks/init.yml - include: tasks/nginxphp.yml handlers: - name: restart nginx service: name=nginx state=restarted
Roles . ├── playbook.yml └── roles ├── init │ └──
tasks │ └── main.yml └── nginxphp ├── handlers │ └── main.yml ├── tasks │ └── main.yml └── templates └── vhost.tpl #playbook.yml --- - hosts: all sudo: true vars: doc_root: /vagrant/web roles: - init - nginxphp
STANDALONE ANSIBLE
Let's talk inventories! #/etc/ansible/hosts [webservers] erikaheidi.com dev-human.com [testservers] 178.62.192.53 95.85.35.248
178.62.221.111
Vagrant auto-generated inventory # Generated by Vagrant default ansible_ssh_host=127.0.0.1 ansible_ssh_port=2222
.vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory
ad-hoc commands
ad-hoc commands
Running playbooks $ ansible-playbook -i staging -l webservers playbook.yml $
ansible-playbook playbook.yml --list-hosts $ ansible-playbook playbook.yml --list-tasks ansible-playbook [-i inventory] [-l group] playbook.yml
Running Ansible on Vagrant vms $ ansible all -i [inventory]
-u vagrant --private-key=[key] -a "php -v" $ ansible-playbook -i [inventory] -u vagrant --private- key=[key] demo01.yml .vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory .vagrant/machines/default/virtualbox/private_key
Running Ansible on Vagrant vms
DEMO
RESOURCES
phansible.com
None
Vagrant Cookbook - Leanpub leanpub.com/vagrantcookbook/c/phpsc15 Also available on Amazon (paperback)
QUESTIONS?
Ansible Tutorials: http://do.co/ansible Please rate this talk: https://joind.in/13588