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
880
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
Introducing Chainguard Images for Safer PHP Runtimes
erikaheidi
0
27
Automatizando documentação em PHP com Autodocs
erikaheidi
0
29
Building the World: The Story Behind Wolfi
erikaheidi
0
290
Hello Wolfi
erikaheidi
1
590
Container Images for the Cloud Native Era
erikaheidi
1
260
Creating Secure Container Images with apko
erikaheidi
0
380
Criando GitHub Actions em PHP com Minicli
erikaheidi
0
150
Building GitHub Actions in PHP with Minicli
erikaheidi
0
430
10 Code Search Tricks for Open Source
erikaheidi
2
200
Other Decks in Programming
See All in Programming
CA.swift19 恋するAIアプリ開発の裏側
oskmr
0
360
スクラムガイドのスプリントレトロスペクティブを改めて読みかえしてみた / Re-reading the Sprint Retrospective Section in the Scrum Guide
mackey0225
3
400
新宿ダンジョンを可視化してみた
satoshi7190
2
210
ゆるい個人開発のススメ
kuroppe1819
10
980
try! Swift Tokyo 2024のLT枠に採択されたプロポーザルを出すときに考えていたこと
ski
0
350
PostmanでAPIの動作確認が楽になった話
h455h1
0
160
はてなにおける CSS Modules、及び CSS Modules に足りないもの / CSS Modules in Hatena, and CSS Modules missing parts
mizdra
6
880
スキーマ駆動開発による品質とスピードの両立 - 私達は何故、スキーマを書くのか
kentaroutakeda
0
160
TYPO3 v13 – The road to LTS: What's new and new APIs
luisasofie_xoxo
0
190
GitHub Copilotのススメ
marcy731
0
190
Designing for tomorrow's programming workflows
honnibal
PRO
2
120
PHPはいつから死んでいるかの調査
chiroruxx
1
360
Featured
See All Featured
Debugging Ruby Performance
tmm1
70
11k
Faster Mobile Websites
deanohume
298
30k
Unsuck your backbone
ammeep
662
57k
Design by the Numbers
sachag
274
18k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
24
2.3k
Rebuilding a faster, lazier Slack
samanthasiow
72
8.2k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
273
13k
Building Better People: How to give real-time feedback that sticks.
wjessup
354
18k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
154
14k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
321
20k
How STYLIGHT went responsive
nonsquared
92
4.8k
Creatively Recalculating Your Daily Design Routine
revolveconf
209
11k
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