This document provides an introduction to using Ansible in a top-down approach. It discusses using Ansible to provision infrastructure including load balancers, application servers, and databases. It covers using ad-hoc commands and playbooks to configure systems. Playbooks can target groups of hosts, apply roles to automate common tasks, and allow variables to customize configurations. Selective execution allows running only certain parts of a playbook. Overall the document demonstrates how Ansible can be used to deploy and manage infrastructure and applications in a centralized, automated way.
41. 24
ansible
--user=vagrant --ask-pass
lb
-m yum
-a "name=openssh"
apply to the “lb” host
in the inventory file
invoke Ansible module “yum”
lb 10.0.0.10
CentOS 7.1
42. 24
ansible
--user=vagrant --ask-pass
lb
-m yum
-a "name=openssh"
apply to the “lb” host
in the inventory file
invoke Ansible module “yum”
inspect package status
lb 10.0.0.10
CentOS 7.1
44. 25
ansible
--user=vagrant --ask-pass
--become
lb
-m yum
-a "name=openssh state=latest"
install or update latest package
become “sudo” privilege
lb 10.0.0.10
CentOS 7.1
45. 26
ansible
--user=vagrant --ask-pass
--become
lb:db
-m yum
-a "name=openssh state=latest"
apply to the “lb” and “db” hosts
in the inventory file
lb 10.0.0.10 db 10.0.0.30
CentOS 7.1 CentOS 7.1
46. 27
ansible
--user=vagrant --ask-pass
--become
'app*'
-m apt
-a "name=openssh-server state=latest"
apply to the “app*” hosts
in the inventory file
app1 10.0.0.20
app2 10.0.0.21
app3 10.0.0.22
Ubuntu 14.04
47. 27
ansible
--user=vagrant --ask-pass
--become
'app*'
-m apt
-a "name=openssh-server state=latest"
apply to the “app*” hosts
in the inventory file
app1 10.0.0.20
app2 10.0.0.21
app3 10.0.0.22
Ubuntu 14.04
invoke Ansible module
“apt”
85. 52
ansible-playbook
--user=vagrant --ask-pass
--become
--tags=deploy
playbook.yml
apply only the roles/tasks with a “deploy” tag
to all hosts in the inventory
lb 10.0.0.10 app1 10.0.0.20
app2 10.0.0.21
app3 10.0.0.22
db 10.0.0.30
CentOS 7.1 CentOS 7.1Ubuntu 14.04
103. 63
ansible-playbook
--user=vagrant --ask-pass
--become
--extra-vars='project_version=green'
--limit=app1
--tags=deploy
playbook.yml
apply only the roles/tasks with a “deploy” tag
lb 10.0.0.10 app1 10.0.0.20
app2 10.0.0.21
app3 10.0.0.22
db 10.0.0.30
CentOS 7.1 CentOS 7.1Ubuntu 14.04
apply to the “app1” host
104. 63
ansible-playbook
--user=vagrant --ask-pass
--become
--extra-vars='project_version=green'
--limit=app1
--tags=deploy
playbook.yml
apply only the roles/tasks with a “deploy” tag
lb 10.0.0.10 app1 10.0.0.20
app2 10.0.0.21
app3 10.0.0.22
db 10.0.0.30
CentOS 7.1 CentOS 7.1Ubuntu 14.04
apply to the “app1” host
checkout “green” branch