SlideShare ist ein Scribd-Unternehmen logo
1 von 19
Larry cai <larry.caiyu@gmail.com>
Agenda 
 Ansible Introduction 
 Exercise 1: Setup environment using docker 
 Exercise 2: Inventory and ad-hoc command 
 Exercise 3: Playbooks - install apache 
 Exercise 4: Playbooks – variables 
 Exercise 5: Playbooks – Template using Jinja2 
 Summary 
Code: 
https://github.com/larrycai/codingwithme-ansible 
Learn Ansible 2 in Docker in 90 minutes 09/28/14
Environment (docker/fig) 
 Boot2docker Installer (127M) http://boot2docker.io/ 
 Contains latest docker already, fast 
 Container persistence via disk automount on /var/lib/docker 
 Add proxy /var/lib/boot2docker/profile if needed 
 $ sudo vi /var/lib/boot2docker/profile 
 export http_proxy=<your proxy> 
 $ sudo /etc/init.d/docker restart 
 $ docker -v 
 User/Passwd: docker/tcuser 
 (Optional) replace with boot2docker.iso 
(fig/share folder support) 
https://github.com/larrycai/boot2docker-vbga-fig/releases 
Learn Ansible 3 in Docker in 90 minutes 09/28/14
Environment use online service 
 Create docker VM using CoreOS image, and assign public 
IP to access 
 http://ustack.com or 
https://cloud.digitalocean.com 
 Clone code & Start them 
$ git clone https://github.com/larrycai/codingwithme-ansible.git 
$ cd codingwithme-ansible 
$ bash start.sh 
# ./update.sh 
# ansible all –a “uname –a” 
Learn Ansible 4 in Docker in 90 minutes 09/28/14
What is Ansible 
 Ansible is a radically simple IT orchestration engine that 
automates configuration management, application 
deployment, and many other IT needs. 
 Similar to Cfengine/Puppet/Chef/Saltstack 
 Features: 
 Agentless with ssh 
 Very simple language (YAML). 
 Lots of modules to execute task. 
 Python 
Image source: page21 
from http://www.slideshare.net/NETWAYS/jp-mensansible 
Learn Ansible 5 in Docker in 90 minutes 09/28/14
Exercise 1: 
Setup environment using docker 
 Clone code from 
https://github.com/larrycai/codingwithme-ansible 
 $ fig run ansible bash # or ./start.sh 
(ansible) # ./update.sh & cd exercise 
(ansible) # ansible all –a “uname –a” 
AAnsnisbilbel ee nevnivrioronmnmenetnt 
HHaparporoxyxy 
wwebe1b1 
wwebe2b2 
DDataatbaabsaese 
DDoockckeer rE Enngigninee S eServrever r( V(VMM) ) 
80 1080 
80 80 
wwebe2b2 
hahparporoxyxy 
wwebe1b1 
Learn Ansible 6 in Docker in 90 minutes 09/28/14
Inventory & ad-hoc command 
 hosts: Inventory is host list 
 ansible.cfg: define 
 An ad-hoc command is something that you might type in 
to do something really quick, but don’t want to save for 
later. 
$ ansible <host patterns> [options] 
$ ansible web –m command –a “uname –a” 
 -m module name, default is command 
 -I inventory name, defaults is set in ansible.cfg or /etc/ansible/hosts 
 -a module args See http://docs.ansible.com/intro_adhoc.html 
Learn Ansible 7 in Docker in 90 minutes 09/28/14
Module 
 Ansible ships with a number of modules 
(called the ‘module library’) that can be 
executed directly on remote hosts 
 Modules can control system resources, 
like services, packages, or files (anything 
really), or handle executing system 
commands. 
 All modules technically return JSON 
format data 
See http://docs.ansible.com/modules.html 
Learn Ansible 8 in Docker in 90 minutes 09/28/14
Exercise 2: ad-hoc command 
 Check free memory in `all` hosts `-a “free –m”` 
 Check all facts in `web` host pattern using module setup 
 Create `/ansible` directory is created in web 
 Using file module http://docs.ansible.com/file_module.html 
 -m file -a “path=/ansible state=<?>” 
 Run command again (check changed) 
 ssh to remote web1 to remove `/ansible` and do it again 
–i /ansible/id_rsa root@web1 
 Take a look at module /usr/share/ansible/files/file 
Learn Ansible 9 in Docker in 90 minutes 09/28/14
Idempotency 
 Idempotence is the ability to run an operation which 
produces the same result whether run once or multiple 
times 
 Ansible has ability to ensure the same configuration is 
maintained whether you run it once or a thousand times. 
 In fact, almost every aspect of Ansible modules and 
commands is idempotent. 
 $ ansible web –m file –a “path=/ansible state=directory” 
 Declarative: Define what instead of how 
path=/ansible state=directory 
vs. 
mkdir /ansible 
Learn Ansible 10 in Docker in 90 minutes 09/28/14
Playbook 
 Playbooks are Ansible’s configuration, deployment, and 
orchestration language. They can describe a policy you 
want your remote systems to enforce, or a set of steps in 
a general IT process. 
 $ ansible-playbook site.yml 
 Each task is one module 
command 
 - file: path=/ansible state=directory 
or 
- name: make sure /ansible exist 
file: path=/ansible state=directory 
 YAML format 
key/value format 
http://docs.ansible.com/playbooks.html 
Learn Ansible 11 in Docker in 90 minutes 09/28/14
Exercise 3:Playbook – Install apache 
 Turn file command into playbook exer3.yml 
 Install apache2 and make them running into web hosts 
$ ansible-playbook exer3.yml 
 Use curl command to verify apache2 is running 
$ curl http://web1_1:80 
 Run ansible-playbook in debug mode using –vvvv 
notice the color for changed=true/false 
If work in firewall, run below command before exercise 
$ ansible-playbook proxy.xml –e “http_proxy=http://<company_proxy>” 
Learn Ansible 12 in Docker in 90 minutes 09/28/14 
wwebe2b2 
80
Variable 
 Variable is used to abstract data in ansible 
 Define variable and use it with “{{ }}” 
- host: web 
vars: 
http_port:80 
tasks: 
- debug: msg=“hello {{ http_port }}” 
 Default variables can be put under group_vars/all 
 Pass variable from command line –e “key=value” 
 Ansible provides a few variables for you automatically. 
‘hostvars’, ‘group_names’, and ‘groups’. 
 with_items for multi key/value 
- name: touch files with an optional mode 
file: dest={{ item.path }} state=touch 
with_items: 
- path: /tmp/foo 
- path: /tmp/bar 
Learn Ansible 13 in Docker in 90 minutes 09/28/14
Exercise 4: Variables 
 Install haproxy (understand) 
 check web ip (understand) 
 Print ip address (system variable “hostvars”) 
 Install extra packages (curl) using variables 
 Variable in yaml 
 In group_vars 
 Pass in command line 
 Install extra packages with_items (wget/socat) 
Learn Ansible 14 in Docker in 90 minutes 09/28/14 
wwebe2b2 
HHaparporoxyxy 
wwebe1b1 
80 80
File/Template 
 Template using Jinja2 (http://jinja.pocoo.org/), which is a 
modern and designer-friendly templating language for 
Python 
 Template module 
template: src=templates/haproxy.cfg.j2 dest=/etc/haproxy/haproxy.cfg 
Learn Ansible 15 in Docker in 90 minutes 09/28/14
Exercise 5: Template 
 See result 
 Add web1/web2 into haproxy backend using loop haproxy.cfg.j2 
 Add stats port 1080 in haproxy 
 Check it in haproxy server 
 docker ps to check haproxy’s port for 80/1080 
80 1080 
 http://192.168.59.103:49155 & http://192.168.59.103:49156 
 Update /var/www/html/index.html in each web for to its 
hostname 
Learn Ansible 16 in Docker in 90 minutes 09/28/14 
wwebe2b2 
hahparporoxyxy 
wwebe1b1 
80 80
Others not touched 
 Dynamic Inventory 
 Roles 
 Write own module 
 Ansible-Galaxy 
 Ansible-Tower 
Learn Ansible 17 in Docker in 90 minutes 09/28/14
Summary 
 Ansible is the orchestration engine to manage your 
infrastructure 
 Automate your own tasks using Ansible 
 Just do it ! 
Learn Ansible 18 in Docker in 90 minutes 09/28/14
Reference 
 http://docs.ansible.com/ 
 https://serversforhackers.com/editions/2014/08/26/getting 
-started-with-ansible/ 
 Practice online 
 http://ustack.com 
Learn Ansible 19 in Docker in 90 minutes 09/28/14

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Ansible presentation
Ansible presentationAnsible presentation
Ansible presentation
 
Automation with Ansible and Containers
Automation with Ansible and ContainersAutomation with Ansible and Containers
Automation with Ansible and Containers
 
docker build with Ansible
docker build with Ansibledocker build with Ansible
docker build with Ansible
 
Getting started with Ansible
Getting started with AnsibleGetting started with Ansible
Getting started with Ansible
 
Test-Driven Infrastructure with Ansible, Test Kitchen, Serverspec and RSpec
Test-Driven Infrastructure with Ansible, Test Kitchen, Serverspec and RSpecTest-Driven Infrastructure with Ansible, Test Kitchen, Serverspec and RSpec
Test-Driven Infrastructure with Ansible, Test Kitchen, Serverspec and RSpec
 
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps
 
Getting Started with Docker
Getting Started with DockerGetting Started with Docker
Getting Started with Docker
 
Continuous Integration: SaaS vs Jenkins in Cloud
Continuous Integration: SaaS vs Jenkins in CloudContinuous Integration: SaaS vs Jenkins in Cloud
Continuous Integration: SaaS vs Jenkins in Cloud
 
Infrastructure = Code
Infrastructure = CodeInfrastructure = Code
Infrastructure = Code
 
Ansible Oxford - Cows & Containers
Ansible Oxford - Cows & ContainersAnsible Oxford - Cows & Containers
Ansible Oxford - Cows & Containers
 
Take control of your Jenkins jobs via job DSL.
Take control of your Jenkins jobs via job DSL.Take control of your Jenkins jobs via job DSL.
Take control of your Jenkins jobs via job DSL.
 
Vagrant, Ansible, and OpenStack on your laptop
Vagrant, Ansible, and OpenStack on your laptopVagrant, Ansible, and OpenStack on your laptop
Vagrant, Ansible, and OpenStack on your laptop
 
Ansible new paradigms for orchestration
Ansible new paradigms for orchestrationAnsible new paradigms for orchestration
Ansible new paradigms for orchestration
 
Amazon EC2 Container Service in Action
Amazon EC2 Container Service in ActionAmazon EC2 Container Service in Action
Amazon EC2 Container Service in Action
 
Ansible: How to Get More Sleep and Require Less Coffee
Ansible: How to Get More Sleep and Require Less CoffeeAnsible: How to Get More Sleep and Require Less Coffee
Ansible: How to Get More Sleep and Require Less Coffee
 
Making environment for_infrastructure_as_code
Making environment for_infrastructure_as_codeMaking environment for_infrastructure_as_code
Making environment for_infrastructure_as_code
 
A quick intro to Ansible
A quick intro to AnsibleA quick intro to Ansible
A quick intro to Ansible
 
Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf...
Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf...Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf...
Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf...
 
Ansible Automation Best Practices From Startups to Enterprises - Minnebar 12
Ansible Automation Best Practices From Startups to Enterprises - Minnebar 12Ansible Automation Best Practices From Startups to Enterprises - Minnebar 12
Ansible Automation Best Practices From Startups to Enterprises - Minnebar 12
 
當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)
當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)
當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)
 

Ähnlich wie Learn basic ansible using docker

Ähnlich wie Learn basic ansible using docker (20)

Docker perl build
Docker perl buildDocker perl build
Docker perl build
 
Learn docker in 90 minutes
Learn docker in 90 minutesLearn docker in 90 minutes
Learn docker in 90 minutes
 
手把手帶你學Docker 03042017
手把手帶你學Docker 03042017手把手帶你學Docker 03042017
手把手帶你學Docker 03042017
 
Build service with_docker_in_90mins
Build service with_docker_in_90minsBuild service with_docker_in_90mins
Build service with_docker_in_90mins
 
Docker Security workshop slides
Docker Security workshop slidesDocker Security workshop slides
Docker Security workshop slides
 
時代在變 Docker 要會:台北 Docker 一日入門篇
時代在變 Docker 要會:台北 Docker 一日入門篇時代在變 Docker 要會:台北 Docker 一日入門篇
時代在變 Docker 要會:台北 Docker 一日入門篇
 
Streamline your development environment with docker
Streamline your development environment with dockerStreamline your development environment with docker
Streamline your development environment with docker
 
桃園市教育局Docker技術入門與實作
桃園市教育局Docker技術入門與實作桃園市教育局Docker技術入門與實作
桃園市教育局Docker技術入門與實作
 
Zero Downtime Deployment with Ansible
Zero Downtime Deployment with AnsibleZero Downtime Deployment with Ansible
Zero Downtime Deployment with Ansible
 
Running Docker in Development & Production (DevSum 2015)
Running Docker in Development & Production (DevSum 2015)Running Docker in Development & Production (DevSum 2015)
Running Docker in Development & Production (DevSum 2015)
 
Dockerizing a Symfony2 application
Dockerizing a Symfony2 applicationDockerizing a Symfony2 application
Dockerizing a Symfony2 application
 
Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGHDeploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
 
ABCs of docker
ABCs of dockerABCs of docker
ABCs of docker
 
Things I've learned working with Docker Support
Things I've learned working with Docker SupportThings I've learned working with Docker Support
Things I've learned working with Docker Support
 
Buildservicewithdockerin90mins
Buildservicewithdockerin90minsBuildservicewithdockerin90mins
Buildservicewithdockerin90mins
 
Vagrant for real codemotion (moar tips! ;-))
Vagrant for real codemotion (moar tips! ;-))Vagrant for real codemotion (moar tips! ;-))
Vagrant for real codemotion (moar tips! ;-))
 
Docker in Action
Docker in ActionDocker in Action
Docker in Action
 
A to Z of a Multi-platform Docker Swarm: Building, Shipping, and Running Mult...
A to Z of a Multi-platform Docker Swarm: Building, Shipping, and Running Mult...A to Z of a Multi-platform Docker Swarm: Building, Shipping, and Running Mult...
A to Z of a Multi-platform Docker Swarm: Building, Shipping, and Running Mult...
 
From Arm to Z: Building, Shipping, and Running a Multi-platform Docker Swarm ...
From Arm to Z: Building, Shipping, and Running a Multi-platform Docker Swarm ...From Arm to Z: Building, Shipping, and Running a Multi-platform Docker Swarm ...
From Arm to Z: Building, Shipping, and Running a Multi-platform Docker Swarm ...
 
5 Things I Wish I Knew About Gitlab CI
5 Things I Wish I Knew About Gitlab CI5 Things I Wish I Knew About Gitlab CI
5 Things I Wish I Knew About Gitlab CI
 

Mehr von Larry Cai

Learn RabbitMQ with Python in 90mins
Learn RabbitMQ with Python in 90minsLearn RabbitMQ with Python in 90mins
Learn RabbitMQ with Python in 90mins
Larry Cai
 
Learn REST API with Python
Learn REST API with PythonLearn REST API with Python
Learn REST API with Python
Larry Cai
 
Practical way to experience of Specification by Example
Practical way to experience of Specification by ExamplePractical way to experience of Specification by Example
Practical way to experience of Specification by Example
Larry Cai
 
Experience from specification_by_examples
Experience from specification_by_examplesExperience from specification_by_examples
Experience from specification_by_examples
Larry Cai
 

Mehr von Larry Cai (18)

Learn kubernetes in 90 minutes
Learn kubernetes in 90 minutesLearn kubernetes in 90 minutes
Learn kubernetes in 90 minutes
 
Learn jobDSL for Jenkins
Learn jobDSL for JenkinsLearn jobDSL for Jenkins
Learn jobDSL for Jenkins
 
Learn RabbitMQ with Python in 90mins
Learn RabbitMQ with Python in 90minsLearn RabbitMQ with Python in 90mins
Learn RabbitMQ with Python in 90mins
 
Learn flask in 90mins
Learn flask in 90minsLearn flask in 90mins
Learn flask in 90mins
 
Learn ELK in docker
Learn ELK in dockerLearn ELK in docker
Learn ELK in docker
 
Software Engineer Talk
Software Engineer TalkSoftware Engineer Talk
Software Engineer Talk
 
Learn nginx in 90mins
Learn nginx in 90minsLearn nginx in 90mins
Learn nginx in 90mins
 
Learn Dashing Widget in 90 minutes
Learn Dashing Widget in 90 minutesLearn Dashing Widget in 90 minutes
Learn Dashing Widget in 90 minutes
 
Learn REST API with Python
Learn REST API with PythonLearn REST API with Python
Learn REST API with Python
 
Jenkins Scriptler in 90mins
Jenkins Scriptler in 90minsJenkins Scriptler in 90mins
Jenkins Scriptler in 90mins
 
Python virtualenv & pip in 90 minutes
Python virtualenv & pip in 90 minutesPython virtualenv & pip in 90 minutes
Python virtualenv & pip in 90 minutes
 
Lead changes in software development
Lead changes in software developmentLead changes in software development
Lead changes in software development
 
Python in 90mins
Python in 90minsPython in 90mins
Python in 90mins
 
Practical way to experience of Specification by Example
Practical way to experience of Specification by ExamplePractical way to experience of Specification by Example
Practical way to experience of Specification by Example
 
Experience from specification_by_examples
Experience from specification_by_examplesExperience from specification_by_examples
Experience from specification_by_examples
 
Write book in markdown
Write book in markdownWrite book in markdown
Write book in markdown
 
Continuous Integration Introduction
Continuous Integration IntroductionContinuous Integration Introduction
Continuous Integration Introduction
 
Agile & ALM tools
Agile & ALM toolsAgile & ALM tools
Agile & ALM tools
 

Kürzlich hochgeladen

💚😋 Salem Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
💚😋 Salem Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋💚😋 Salem Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
💚😋 Salem Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
nirzagarg
 
valsad Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girls...
valsad Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girls...valsad Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girls...
valsad Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girls...
Call Girls In Delhi Whatsup 9873940964 Enjoy Unlimited Pleasure
 
Thalassery Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call G...
Thalassery Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call G...Thalassery Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call G...
Thalassery Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call G...
Call Girls In Delhi Whatsup 9873940964 Enjoy Unlimited Pleasure
 
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
nirzagarg
 
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
ydyuyu
 

Kürzlich hochgeladen (20)

Wadgaon Sheri $ Call Girls Pune 10k @ I'm VIP Independent Escorts Girls 80057...
Wadgaon Sheri $ Call Girls Pune 10k @ I'm VIP Independent Escorts Girls 80057...Wadgaon Sheri $ Call Girls Pune 10k @ I'm VIP Independent Escorts Girls 80057...
Wadgaon Sheri $ Call Girls Pune 10k @ I'm VIP Independent Escorts Girls 80057...
 
💚😋 Salem Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
💚😋 Salem Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋💚😋 Salem Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
💚😋 Salem Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
 
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls DubaiDubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
 
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
 
valsad Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girls...
valsad Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girls...valsad Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girls...
valsad Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girls...
 
Thalassery Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call G...
Thalassery Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call G...Thalassery Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call G...
Thalassery Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call G...
 
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
 
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
 
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service AvailableCall Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
 
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
 
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
 
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
 
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...
 
💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
 
Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...
Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...
Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...
 
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
 
Pirangut | Call Girls Pune Phone No 8005736733 Elite Escort Service Available...
Pirangut | Call Girls Pune Phone No 8005736733 Elite Escort Service Available...Pirangut | Call Girls Pune Phone No 8005736733 Elite Escort Service Available...
Pirangut | Call Girls Pune Phone No 8005736733 Elite Escort Service Available...
 
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
 
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
 
20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf
 

Learn basic ansible using docker

  • 2. Agenda  Ansible Introduction  Exercise 1: Setup environment using docker  Exercise 2: Inventory and ad-hoc command  Exercise 3: Playbooks - install apache  Exercise 4: Playbooks – variables  Exercise 5: Playbooks – Template using Jinja2  Summary Code: https://github.com/larrycai/codingwithme-ansible Learn Ansible 2 in Docker in 90 minutes 09/28/14
  • 3. Environment (docker/fig)  Boot2docker Installer (127M) http://boot2docker.io/  Contains latest docker already, fast  Container persistence via disk automount on /var/lib/docker  Add proxy /var/lib/boot2docker/profile if needed  $ sudo vi /var/lib/boot2docker/profile  export http_proxy=<your proxy>  $ sudo /etc/init.d/docker restart  $ docker -v  User/Passwd: docker/tcuser  (Optional) replace with boot2docker.iso (fig/share folder support) https://github.com/larrycai/boot2docker-vbga-fig/releases Learn Ansible 3 in Docker in 90 minutes 09/28/14
  • 4. Environment use online service  Create docker VM using CoreOS image, and assign public IP to access  http://ustack.com or https://cloud.digitalocean.com  Clone code & Start them $ git clone https://github.com/larrycai/codingwithme-ansible.git $ cd codingwithme-ansible $ bash start.sh # ./update.sh # ansible all –a “uname –a” Learn Ansible 4 in Docker in 90 minutes 09/28/14
  • 5. What is Ansible  Ansible is a radically simple IT orchestration engine that automates configuration management, application deployment, and many other IT needs.  Similar to Cfengine/Puppet/Chef/Saltstack  Features:  Agentless with ssh  Very simple language (YAML).  Lots of modules to execute task.  Python Image source: page21 from http://www.slideshare.net/NETWAYS/jp-mensansible Learn Ansible 5 in Docker in 90 minutes 09/28/14
  • 6. Exercise 1: Setup environment using docker  Clone code from https://github.com/larrycai/codingwithme-ansible  $ fig run ansible bash # or ./start.sh (ansible) # ./update.sh & cd exercise (ansible) # ansible all –a “uname –a” AAnsnisbilbel ee nevnivrioronmnmenetnt HHaparporoxyxy wwebe1b1 wwebe2b2 DDataatbaabsaese DDoockckeer rE Enngigninee S eServrever r( V(VMM) ) 80 1080 80 80 wwebe2b2 hahparporoxyxy wwebe1b1 Learn Ansible 6 in Docker in 90 minutes 09/28/14
  • 7. Inventory & ad-hoc command  hosts: Inventory is host list  ansible.cfg: define  An ad-hoc command is something that you might type in to do something really quick, but don’t want to save for later. $ ansible <host patterns> [options] $ ansible web –m command –a “uname –a”  -m module name, default is command  -I inventory name, defaults is set in ansible.cfg or /etc/ansible/hosts  -a module args See http://docs.ansible.com/intro_adhoc.html Learn Ansible 7 in Docker in 90 minutes 09/28/14
  • 8. Module  Ansible ships with a number of modules (called the ‘module library’) that can be executed directly on remote hosts  Modules can control system resources, like services, packages, or files (anything really), or handle executing system commands.  All modules technically return JSON format data See http://docs.ansible.com/modules.html Learn Ansible 8 in Docker in 90 minutes 09/28/14
  • 9. Exercise 2: ad-hoc command  Check free memory in `all` hosts `-a “free –m”`  Check all facts in `web` host pattern using module setup  Create `/ansible` directory is created in web  Using file module http://docs.ansible.com/file_module.html  -m file -a “path=/ansible state=<?>”  Run command again (check changed)  ssh to remote web1 to remove `/ansible` and do it again –i /ansible/id_rsa root@web1  Take a look at module /usr/share/ansible/files/file Learn Ansible 9 in Docker in 90 minutes 09/28/14
  • 10. Idempotency  Idempotence is the ability to run an operation which produces the same result whether run once or multiple times  Ansible has ability to ensure the same configuration is maintained whether you run it once or a thousand times.  In fact, almost every aspect of Ansible modules and commands is idempotent.  $ ansible web –m file –a “path=/ansible state=directory”  Declarative: Define what instead of how path=/ansible state=directory vs. mkdir /ansible Learn Ansible 10 in Docker in 90 minutes 09/28/14
  • 11. Playbook  Playbooks are Ansible’s configuration, deployment, and orchestration language. They can describe a policy you want your remote systems to enforce, or a set of steps in a general IT process.  $ ansible-playbook site.yml  Each task is one module command  - file: path=/ansible state=directory or - name: make sure /ansible exist file: path=/ansible state=directory  YAML format key/value format http://docs.ansible.com/playbooks.html Learn Ansible 11 in Docker in 90 minutes 09/28/14
  • 12. Exercise 3:Playbook – Install apache  Turn file command into playbook exer3.yml  Install apache2 and make them running into web hosts $ ansible-playbook exer3.yml  Use curl command to verify apache2 is running $ curl http://web1_1:80  Run ansible-playbook in debug mode using –vvvv notice the color for changed=true/false If work in firewall, run below command before exercise $ ansible-playbook proxy.xml –e “http_proxy=http://<company_proxy>” Learn Ansible 12 in Docker in 90 minutes 09/28/14 wwebe2b2 80
  • 13. Variable  Variable is used to abstract data in ansible  Define variable and use it with “{{ }}” - host: web vars: http_port:80 tasks: - debug: msg=“hello {{ http_port }}”  Default variables can be put under group_vars/all  Pass variable from command line –e “key=value”  Ansible provides a few variables for you automatically. ‘hostvars’, ‘group_names’, and ‘groups’.  with_items for multi key/value - name: touch files with an optional mode file: dest={{ item.path }} state=touch with_items: - path: /tmp/foo - path: /tmp/bar Learn Ansible 13 in Docker in 90 minutes 09/28/14
  • 14. Exercise 4: Variables  Install haproxy (understand)  check web ip (understand)  Print ip address (system variable “hostvars”)  Install extra packages (curl) using variables  Variable in yaml  In group_vars  Pass in command line  Install extra packages with_items (wget/socat) Learn Ansible 14 in Docker in 90 minutes 09/28/14 wwebe2b2 HHaparporoxyxy wwebe1b1 80 80
  • 15. File/Template  Template using Jinja2 (http://jinja.pocoo.org/), which is a modern and designer-friendly templating language for Python  Template module template: src=templates/haproxy.cfg.j2 dest=/etc/haproxy/haproxy.cfg Learn Ansible 15 in Docker in 90 minutes 09/28/14
  • 16. Exercise 5: Template  See result  Add web1/web2 into haproxy backend using loop haproxy.cfg.j2  Add stats port 1080 in haproxy  Check it in haproxy server  docker ps to check haproxy’s port for 80/1080 80 1080  http://192.168.59.103:49155 & http://192.168.59.103:49156  Update /var/www/html/index.html in each web for to its hostname Learn Ansible 16 in Docker in 90 minutes 09/28/14 wwebe2b2 hahparporoxyxy wwebe1b1 80 80
  • 17. Others not touched  Dynamic Inventory  Roles  Write own module  Ansible-Galaxy  Ansible-Tower Learn Ansible 17 in Docker in 90 minutes 09/28/14
  • 18. Summary  Ansible is the orchestration engine to manage your infrastructure  Automate your own tasks using Ansible  Just do it ! Learn Ansible 18 in Docker in 90 minutes 09/28/14
  • 19. Reference  http://docs.ansible.com/  https://serversforhackers.com/editions/2014/08/26/getting -started-with-ansible/  Practice online  http://ustack.com Learn Ansible 19 in Docker in 90 minutes 09/28/14