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
940
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
Learning Lab: WordPress
erikaheidi
0
54
Criando Container Runtimes mais Seguras com Wolfi
erikaheidi
0
130
Introducing Chainguard Images for Safer PHP Runtimes
erikaheidi
0
160
Automatizando documentação em PHP com Autodocs
erikaheidi
0
120
Building the World: The Story Behind Wolfi
erikaheidi
0
660
Hello Wolfi
erikaheidi
1
720
Container Images for the Cloud Native Era
erikaheidi
1
380
Creating Secure Container Images with apko
erikaheidi
0
540
Criando GitHub Actions em PHP com Minicli
erikaheidi
0
240
Other Decks in Programming
See All in Programming
In geheimer Mission: AI Agents entwickeln
joergneumann
0
110
REALITY コマンド作成チュートリアル
nishiuriraku
0
120
ぽちぽち選択するだけでOSSを読めるVSCode拡張機能
ymbigo
9
3.9k
The Missing Link in Angular’s Signal Story: Resource API and httpResource
manfredsteyer
PRO
0
140
eBPF超入門「o11yに使える」とは (20250424_eBPF_o11y)
thousanda
1
110
Enterprise Web App. Development (1): Build Tool Training Ver. 5
knakagawa
1
120
Optimizing JRuby 10
headius
0
580
Bedrock×MCPで社内ブログ執筆文化を育てたい!
har1101
7
1.4k
カオスに立ち向かう小規模チームの装備の選択〜フルスタックTSという装備の強み _ 弱み〜/Choosing equipment for a small team facing chaos ~ Strengths and weaknesses of full-stack TS~
bitkey
1
130
Serving TUIs over SSH with Go
caarlos0
0
590
Instrumentsを使用した アプリのパフォーマンス向上方法
hinakko
0
240
サービスレベルを管理してアジャイルを加速しよう!! / slm-accelerate-agility
tomoyakitaura
1
200
Featured
See All Featured
Testing 201, or: Great Expectations
jmmastey
42
7.5k
Become a Pro
speakerdeck
PRO
28
5.3k
Embracing the Ebb and Flow
colly
85
4.7k
Code Reviewing Like a Champion
maltzj
523
40k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
105
19k
Why Our Code Smells
bkeepers
PRO
336
57k
Code Review Best Practice
trishagee
67
18k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
26k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
357
30k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
129
19k
Designing Experiences People Love
moore
142
24k
The Straight Up "How To Draw Better" Workshop
denniskardys
233
140k
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