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
Erika Heidi
July 18, 2015
Programming
2
960
Vagrant Provisioning with Ansible
As presented at PHP Southcoast 2015
Erika Heidi
July 18, 2015
Tweet
Share
More Decks by Erika Heidi
See All by Erika Heidi
FreeCAD 101 Lightning Talk
erikaheidi
0
27
Learning Lab: WordPress
erikaheidi
0
97
Criando Container Runtimes mais Seguras com Wolfi
erikaheidi
0
170
Introducing Chainguard Images for Safer PHP Runtimes
erikaheidi
0
210
Automatizando documentação em PHP com Autodocs
erikaheidi
0
160
Building the World: The Story Behind Wolfi
erikaheidi
0
770
Hello Wolfi
erikaheidi
1
760
Container Images for the Cloud Native Era
erikaheidi
1
420
Creating Secure Container Images with apko
erikaheidi
0
580
Other Decks in Programming
See All in Programming
開発組織の戦略的な役割と 設計スキル向上の効果
masuda220
PRO
10
2.1k
iOSでSVG画像を扱う
kishikawakatsumi
0
180
「10分以内に機能を消せる状態」 の実現のためにやっていること
togishima
1
120
Verilator + Rust + gRPC と Efinix の RISC-V でAIアクセラレータをAIで作ってる話 RTLを語る会(18) 2025/11/08
ryuz88
0
310
MCPサーバー「モディフィウス」で変更容易性の向上をスケールする / modifius
minodriven
5
1.1k
オンデバイスAIとXcode
ryodeveloper
0
410
Swift Concurrency 年表クイズ
omochi
3
220
When Dependencies Fail: Building Antifragile Applications in a Fragile World
selcukusta
0
120
テーブル定義書の構造化抽出して、生成AIでDWH分析を試してみた / devio2025tokyo
kasacchiful
0
400
予防に勝る防御なし(2025年版) - 堅牢なコードを導く様々な設計のヒント / Growing Reliable Code PHP Conference Fukuoka 2025
twada
PRO
30
9.1k
Node-REDのノードの開発・活用事例とコミュニティとの関わり(Node-RED Con Nagoya 2025)
404background
0
120
Eloquentを使ってどこまでコードの治安を保てるのか?を新人が考察してみた
itokoh0405
0
3.1k
Featured
See All Featured
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.5k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
660
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.5k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.3k
Building Adaptive Systems
keathley
44
2.8k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
36
6.1k
YesSQL, Process and Tooling at Scale
rocio
174
15k
Writing Fast Ruby
sferik
630
62k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
192
56k
Reflections from 52 weeks, 52 projects
jeffersonlam
355
21k
Documentation Writing (for coders)
carmenintech
76
5.1k
Embracing the Ebb and Flow
colly
88
4.9k
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