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
Automation made simple with Ansible
Search
Erika Heidi
March 19, 2015
Programming
3
440
Automation made simple with Ansible
As presented at Cloudconf 2015 in Turin, Italy
Erika Heidi
March 19, 2015
Tweet
Share
More Decks by Erika Heidi
See All by Erika Heidi
Learning Lab: WordPress
erikaheidi
0
33
Criando Container Runtimes mais Seguras com Wolfi
erikaheidi
0
110
Introducing Chainguard Images for Safer PHP Runtimes
erikaheidi
0
140
Automatizando documentação em PHP com Autodocs
erikaheidi
0
110
Building the World: The Story Behind Wolfi
erikaheidi
0
600
Hello Wolfi
erikaheidi
1
680
Container Images for the Cloud Native Era
erikaheidi
1
360
Creating Secure Container Images with apko
erikaheidi
0
500
Criando GitHub Actions em PHP com Minicli
erikaheidi
0
220
Other Decks in Programming
See All in Programming
[Fin-JAWS 第38回 ~re:Invent 2024 金融re:Cap~]FaultInjectionServiceアップデート@pre:Invent2024
shintaro_fukatsu
0
240
Rubyでつくるパケットキャプチャツール
ydah
0
240
2025.01.17_Sansan × DMM.swift
riofujimon
2
620
shadcn/uiを使ってReactでの開発を加速させよう!
lef237
0
330
Amazon Nova Reelの可能性
hideg
0
240
『改訂新版 良いコード/悪いコードで学ぶ設計入門』活用方法−爆速でスキルアップする!効果的な学習アプローチ / effective-learning-of-good-code
minodriven
29
4.5k
アクターシステムに頼らずEvent Sourcingする方法について
j5ik2o
6
720
どうして手を動かすよりもチーム内のコードレビューを優先するべきなのか
okashoi
3
920
ecspresso, ecschedule, lambroll を PipeCDプラグインとして動かしてみた (プロトタイプ) / Running ecspresso, ecschedule, and lambroll as PipeCD Plugins (prototype)
tkikuc
2
2.1k
サーバーゆる勉強会 DBMS の仕組み編
kj455
1
320
AHC041解説
terryu16
0
480
DevFest - Serverless 101 with Google Cloud Functions
tunmise
0
140
Featured
See All Featured
Testing 201, or: Great Expectations
jmmastey
41
7.2k
A better future with KSS
kneath
238
17k
Building Applications with DynamoDB
mza
93
6.2k
Designing on Purpose - Digital PM Summit 2013
jponch
117
7.1k
Designing Experiences People Love
moore
139
23k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
2k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
127
18k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
98
18k
Facilitating Awesome Meetings
lara
51
6.2k
RailsConf 2023
tenderlove
29
980
Documentation Writing (for coders)
carmenintech
67
4.6k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Transcript
None
whoami
What to expect from this talk 1. Ansible Overview 2.
Inventories and ad-hoc commands 3. Using Playbooks 4. Playbook crash-course
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.
Setting up SSH access • Servers should be accessible via
SSH using keypair authentication • It's recommended to have a user with sudo NOPASSWD permission to run the tasks in the server How to configure your SSH access for running Ansible: bit.ly/ansible-ssh
INVENTORIES & AD-HOC COMMANDS
Inventory file #/etc/ansible/hosts [webservers] erikaheidi.com dev-human.com [testservers] 178.62.192.53 95.85.35.248
ad-hoc commands $ ansible all -m ping $ ansible webservers
-a “php -v” $ ansible all -i staging -a “sudo apt-get update” ansible group [-i inventory] [-m module]
DEMO 1 Running ad-hoc commands
None
None
USING PLAYBOOKS
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
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
DEMO 2 ansible-playbook
None
THE PLAYBOOK CRASH-COURSE
Variables --- - hosts: all sudo: yes vars: web_server: nginx
tasks: - name: Install {{ web_server }} apt: pkg={{ web_server }} state=latest
Variables (facts) • Information discovered from systems • Globally available
• Example: ansible_default_ipv4.address
Loops (with_items) tasks: - name: Install Packages apt: pkg={{ item
}} state=latest with_items: - nginx - php5-fpm - git
Loops (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
Conditionals - name: "shutdown Debian flavored systems" command: /sbin/shutdown -t
now when: ansible_os_family == "Debian" - name: check if bar is defined fail: msg="This play requires 'bar'" when: bar is not defined
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) 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
WORKING WITH ROLES
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
RESOURCES
None
Using Phansible with remote servers: bit.ly/phansible-remote
Ansible Tutorials: http://do.co/ansible