Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up for free
Automation made simple with Ansible
Erika Heidi
March 19, 2015
Programming
3
400
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
Building GitHub Actions in PHP with Minicli
erikaheidi
0
53
10 Code Search Tricks for Open Source
erikaheidi
2
32
The Art of Programming - Laracon Online Winter 22
erikaheidi
0
140
A Arte de Programar
erikaheidi
4
74
The Art of Programming - Codeland 2020
erikaheidi
32
11k
How to Create PHP Development Environments with Docker Compose
erikaheidi
3
140
Automation Made Simple with Ansible
erikaheidi
2
130
DRIVE with Vagrant and Ansible
erikaheidi
4
440
DRIVE with Vagrant and Ansible
erikaheidi
1
510
Other Decks in Programming
See All in Programming
What's new in Android development tools まとめ
mkeeda
0
400
GDG Seoul IO Extended 2022 - Android Compose
taehwandev
0
330
Android Compose Component - mapping.
taehwandev
0
140
Angular‘s Future without NgModules: Architectures with Standalone Components @enterJS
manfredsteyer
PRO
0
250
I/O Extended 2022 in Android ~ Whats new in Android development tools
pluu
0
570
Cybozu GoogleI/O 2022 LT会 - Input for all screens
jaewgwon
0
390
[월간 데이터리안 세미나 6월] 스스로 성장하는 분석가 커리어 이야기
datarian
0
250
リアルタイムボイスチェンジャーMMVCとVITSの紹介
stealthinu
0
150
大規模プロダクトにLinterを導入し運用している話
hirokiotsuka
0
240
データ分析やAIの "運用" について考える
mmorito
0
150
Haskellでオブジェクト指向プログラミング
koheisakata
0
130
Get Ready for Jakarta EE 10
ivargrimstad
0
1.1k
Featured
See All Featured
Unsuck your backbone
ammeep
659
55k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
105
16k
How to name files
jennybc
40
61k
Art Directing for the Web. Five minutes with CSS Template Areas
malarkey
196
9.4k
The MySQL Ecosystem @ GitHub 2015
samlambert
238
11k
Testing 201, or: Great Expectations
jmmastey
21
5.4k
ParisWeb 2013: Learning to Love: Crash Course in Emotional UX Design
dotmariusz
100
5.9k
Ruby is Unlike a Banana
tanoku
91
9.2k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
498
130k
A better future with KSS
kneath
225
15k
Producing Creativity
orderedlist
PRO
334
37k
The Power of CSS Pseudo Elements
geoffreycrofte
47
3.9k
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