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
1k
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
86
Learning Lab: WordPress
erikaheidi
0
180
Criando Container Runtimes mais Seguras com Wolfi
erikaheidi
0
240
Introducing Chainguard Images for Safer PHP Runtimes
erikaheidi
0
290
Automatizando documentação em PHP com Autodocs
erikaheidi
0
230
Building the World: The Story Behind Wolfi
erikaheidi
0
880
Hello Wolfi
erikaheidi
1
830
Container Images for the Cloud Native Era
erikaheidi
1
490
Creating Secure Container Images with apko
erikaheidi
0
740
Other Decks in Programming
See All in Programming
承認済みなのに差戻しできてしまうバグ、型で潰せます
shinchit
0
130
이 함수, 실패하면 어떻게 되나요? null부터 Rich Errors까지, Kotlin 에러 처리 15년
haeti2
0
110
AIエージェント時代のコードレビューを設計する
nogu66
5
2.3k
What We Talk About When We Talk About XP
m_seki
2
210
数年滞っていたダークモード対応をおよそ2週間で完了させる
chigichan24
0
600
Swift愛好会と私(ウホーイ) / Swift Fan Club and Uhooi
uhooi
0
120
30年振りにコンパイラの定数整数除算を改善した
herumi
9
4.4k
週末にAI-DLCを本気で回したら$1,600溶けた
hbashimizu
0
120
まずはプロンプトガイドを読もう、話はそれからだ
kiakiraki
1
250
DroidKaigi 2026 「個人開発という実験場: Android エンジニアが手にする4つの自由」
slashnephy
0
190
tsc.rip を支える技術 / Kyoto.なんか #8
susisu
0
4.2k
DynamoDBの基礎を振り返りながらベクトル検索機能を理解する
musan
3
260
Featured
See All Featured
How Software Deployment tools have changed in the past 20 years
geshan
1
34k
Tell your own story through comics
letsgokoyo
1
1.1k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
500
The untapped power of vector embeddings
frankvandijk
2
1.9k
Claude Code のすすめ
schroneko
67
230k
GraphQLとの向き合い方2022年版
quramy
50
15k
The Spectacular Lies of Maps
axbom
PRO
1
970
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
440
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
520
Building Adaptive Systems
keathley
44
3.2k
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
430
Building a Scalable Design System with Sketch
lauravandoore
463
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