Ansible Playbook
Ansible Playbook
Ansible Playbook
Once you have started your Linux Academy Lab Servers and logged in
with the 'user' account and password provided, use the appropriate
command to generate a public and private key pair on 'Server1'. Verify the
key pair was created by changing to the appropriate directory and listing
the files.
[user@tcox4 ~]$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/user/.ssh/id_rsa):
Created directory '/home/user/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/user/.ssh/id_rsa.
Your public key has been saved in /home/user/.ssh/id_rsa.pub.
The key fingerprint is:
b8:49:0a:1f:71:f9:0c:54:c8:8e:30:9b:93:b3:3c:bf
[email protected]
The key's randomart image is:
+--[ RSA 2048]----+
| ..o. |
| o .o. |
| *.o+ |
| * .o.= |
| ..+. o S |
| +o + o |
| oo o |
| . |
| E. |
+-----------------+
[user@tcox4 ~]$ cd .ssh
[user@tcox4 .ssh]$ ll
total 8
-rw-------. 1 user user 1679 Sep 21 14:23 id_rsa
-rw-r--r--. 1 user user 408 Sep 21 14:23 id_rsa.pub
2. Exchange the public key with 'Server2' and the 'user' account on that
server. Verify that the identity appearing in the appropriate key file matches
the user and system name/IP of the originating 'Server1'.
[user@tcox4 .ssh]$ ssh-copy-id 54.86.179.231
The authenticity of host '54.86.179.231 (54.86.179.231)' can't be
established.
ECDSA key fingerprint is
0d:0c:b1:1d:e1:cf:6d:9f:51:bf:0f:dc:60:82:a1:73.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new
key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if
you are prompted now it is to install the new keys
[email protected]'s password:
3. Verify that you are able to log into 'Server2' from 'Server1' with the 'user'
account without entering a password. Check the hostname file to be sure
you are logged into 'Server2'.
[user@tcox4 .ssh]$ ssh 54.86.179.231
Last login: Mon Sep 21 14:22:42 2015 from 216.46.60.98
[user@tcox5 .ssh]$ hostname
tcox5.mylabserver.com
4. Repeat Step #1 for 'Server2' (creating and exchanging the 'user' SSH
keys with 'Server1'). Create a file on 'Server1' using any method you
choose. Use 'secure copy' to copy that file to 'Server2'. Confirm the copy
succeeds without password entry.
[user@tcox4 ~]$ echo "test file" > testfile.txt
[user@tcox4 ~]$ scp testfile.txt 54.86.179.231:/home/user
testfile.txt
5. Using 'secure copy', copy the file from Step #4 back to 'Server1' from
'Server2', renaming it to something else during the copy process, verify that
no password was required.
[user@tcox4 ~]$ scp 54.86.179.231:/home/user/testfile.txt
copiedfrom.txt
testfile.txt
1. Verify that Ansible is running by displaying the version and module path.
Change to the Ansible configuration directory and list the contents.
[root@tcox3 ~]# ansible --version
ansible 1.9.2
configured module search path = None
[root@tcox3 ~]# cd /etc/ansible
[root@tcox3 ansible]# ll
total 20
-rw-r--r--. 1 root root 8629 Jun 25 21:11 ansible.cfg
-rw-r--r--. 1 root root 88 Sep 21 14:43 hosts
drwxr-xr-x. 2 root root 6 Jun 25 21:11 roles
2. Move the original Ansible Hosts file to another file in the same directory
called 'hosts.original'. Create a new empty 'hosts' file in the default
configuration directory location.
[root@tcox3 ansible]# mv hosts hosts.original && touch hosts && ll
total 20
-rw-r--r--. 1 root root 8629 Jun 25 21:11 ansible.cfg
-rw-r--r--. 1 root root 0 Sep 21 14:43 hosts
-rw-r--r--. 1 root root 965 Jun 25 21:11 hosts.original
drwxr-xr-x. 2 root root 6 Jun 25 21:11 roles
3. Create a section in the new 'hosts' file called 'local'. Make sure it
contains:
* Localhost
* Localhost.Localdomain
* 127.0.0.1
[root@tcox3 ansible]# vim hosts
[root@tcox3 ansible]# cat hosts
[local]
127.0.0.1
localhost
localhost.localdomain
4. Create a second section called 'web hosts' with the NAME of the second
Linux Academy lab server in your environment (see previous lab for setting
up the two host environment). Display the contents of the file.
[root@tcox3 ansible]# vim hosts
[root@tcox3 ansible]# cat hosts
[local]
127.0.0.1
localhost
localhost.localdomain
[web hosts]
tcox4.mylabserver.com
1. Verify that Ansible is running by displaying the version and module path.
Change to the Ansible configuration directory and list the contents.
[root@tcox3 ~]# ansible --version
ansible 1.9.2
configured module search path = None
[root@tcox3 ~]# cd /etc/ansible
[root@tcox3 ansible]# ll
total 20
-rw-r--r--. 1 root root 8629 Jun 25 21:11 ansible.cfg
-rw-r--r--. 1 root root 88 Sep 21 14:43 hosts
drwxr-xr-x. 2 root root 6 Jun 25 21:11 roles
2. Move the original Ansible Hosts file to another file in the same directory
called 'hosts.original'. Create a new empty 'hosts' file in the default
configuration directory location.
[root@tcox3 ansible]# mv hosts hosts.original && touch hosts && ll
total 20
-rw-r--r--. 1 root root 8629 Jun 25 21:11 ansible.cfg
-rw-r--r--. 1 root root 0 Sep 21 14:43 hosts
-rw-r--r--. 1 root root 965 Jun 25 21:11 hosts.original
drwxr-xr-x. 2 root root 6 Jun 25 21:11 roles
3. Create a section in the new 'hosts' file called 'local'. Make sure it
contains:
* Localhost
* Localhost.Localdomain
* 127.0.0.1
[root@tcox3 ansible]# vim hosts
[root@tcox3 ansible]# cat hosts
[local]
127.0.0.1
localhost
localhost.localdomain
4. Create a second section called 'web hosts' with the NAME of the second
Linux Academy lab server in your environment (see previous lab for setting
up the two host environment). Display the contents of the file.
[root@tcox3 ansible]# vim hosts
[root@tcox3 ansible]# cat hosts
[local]
127.0.0.1
localhost
localhost.localdomain
[web hosts]
tcox4.mylabserver.com
2. Run the ansible command that lists all of the hosts configured in your
control server 'hosts' file for the system.
[test@tcox3 ~]$ ansible all --list-hosts
tcox5.mylabserver.com
localhost
tcox4.mylabserver.com
3. Using the 'setup' module for ansible, list all of the known facts on the
local system.
[test@tcox3 ~]$ ansible local -m setup
localhost | success >> {
"ansible_facts": {
"ansible_all_ipv4_addresses": [
"172.31.107.208"
],
"ansible_all_ipv6_addresses": [
"fe80::103f:68ff:fefe:2bd1"
],
"ansible_architecture": "x86_64",
"ansible_bios_date": "05/06/2015",
"ansible_bios_version": "4.2.amazon",
"ansible_cmdline": {
"BOOT_IMAGE": "/boot/vmlinuz-3.10.0-
229.14.1.el7.x86_64",
(NOTE: Your output will be larger as this was concatenated
for space and readability)
4. Using the 'setup' module for ansible, list all of the known facts for all
systems configured in the 'hosts' file on the system.
[test@tcox3 ~]$ ansible all -m setup
(NOTE: Localhost truncated here... starting with another host output)
tcox4.mylabserver.com | success >> {
"ansible_facts": {
"ansible_all_ipv4_addresses": [
"172.31.108.45"
],
"ansible_all_ipv6_addresses": [
"fe80::1029:fbff:fed6:9aaf"
],
"ansible_architecture": "x86_64",
"ansible_bios_date": "05/06/2015",
"ansible_bios_version": "4.2.amazon",
"ansible_cmdline": {
"BOOT_IMAGE": "/boot/vmlinuz-3.10.0-
229.14.1.el7.x86_64",
(NOTE: Your output will be larger as this was concatenated for space
and readability)
5. While listing the facts on the local system, filter the list showing only the
content pertaining to the system IP addresses.
[test@tcox3 ~]$ ansible local -m setup -a 'filter=ans*ipv4*'
localhost | success >> {
"ansible_facts": {
"ansible_all_ipv4_addresses": [
"172.31.107.208"
],
"ansible_default_ipv4": {
"address": "172.31.107.208",
"alias": "eth0",
"gateway": "172.31.96.1",
"interface": "eth0",
"macaddress": "12:3f:68:fe:2b:d1",
"mtu": 9001,
"netmask": "255.255.240.0",
"network": "172.31.96.0",
"type": "ether"
}
},
"changed": false
}
2. Using the appropriate module, from your control server, list all the hosts
configured in your environment. Using ansible, run a ping command
against all hosts in the environment.
[test@tcox3 ~]$ ansible all --list-hosts
tcox5.mylabserver.com
localhost
tcox4.mylabserver.com
[test@tcox3 ~]$ ansible all -m ping
localhost | success >> {
"changed": false,
"ping": "pong"
}
tcox5.mylabserver.com | success >> {
"changed": false,
"ping": "pong"
}
3. List the contents of your ansible 'hosts' file. Using only ONE of the
groups in the file, attempt to install the 'lynx' package on that server.
[test@tcox3 ~]$ cat /etc/ansible/hosts
[local]
localhost
[apacheweb]
tcox4.mylabserver.com
[appserver]
tcox5.mylabserver.com
1. On the control server, display the ansible version and status and issue
an ansible command to list all configured hosts.
[test@tcox3 ~]$ ansible --version
ansible 1.9.2
tcox5.mylabserver.com
localhost
tcox4.mylabserver.com
2. Choosing ONE of the groups from the displayed list in Step #1 above,
query that system for all the 'facts' that can be displayed, while filtering the
content for the IP address information.
[test@tcox3 ~]$ ansible apacheweb -m setup -a 'filter=ans*ipv4*'
tcox4.mylabserver.com | success >> {
"ansible_facts": {
"ansible_all_ipv4_addresses": [
"172.31.108.45"
],
"ansible_default_ipv4": {
"address": "172.31.108.45",
"alias": "eth0",
"gateway": "172.31.96.1",
"interface": "eth0",
"macaddress": "12:29:fb:d6:9a:af",
"mtu": 9001,
"netmask": "255.255.240.0",
"network": "172.31.96.0",
"type": "ether"
}
},
"changed": false
}
3. Using the same group from Steps #1 and #2, issue a shell command
through ansible that will determine if the 'lynx' package is already installed
on that server.
[test@tcox3 ~]$ ansible apacheweb -m shell -a 'yum list installed |
grep lynx'
tcox4.mylabserver.com | success | rc=0 >>
lynx.x86_64 2.8.8-0.3.dev15.el7
@base
4. Using the same group, issue an ansible command (as sudo) that will
display the last ten lines of output from the remote system's 'syslog' file.
[test@tcox3 ~]$ ansible apacheweb -m shell -a 'tail -n 10
/var/log/dmesg'
tcox4.mylabserver.com | success | rc=0 >>
[ 3.577455] SELinux: initialized (dev autofs, type autofs), uses
genfs_contexts
[ 3.621406] SELinux: initialized (dev hugetlbfs, type hugetlbfs),
uses transition SIDs
[ 3.748973] systemd-udevd[504]: starting version 208
[ 3.828536] Installing knfsd (copyright (C) 1996
[email protected]).
[ 3.839265] SELinux: initialized (dev nfsd, type nfsd), uses
genfs_contexts
[ 3.949670] piix4_smbus 0000:00:01.3: SMBus base address
uninitialized - upgrade BIOS or use force_addr=0xaddr
[ 4.082323] input: PC Speaker as
/devices/platform/pcspkr/input/input4
[ 4.191443] type=1305 audit(1443204264.317:4): audit_pid=546
old=0 auid=4294967295 ses=4294967295
subj=system_u:system_r:auditd_t:s0 res=1
[ 4.277258] ppdev: user-space parallel port driver
[ 4.459507] Adding 2097148k swap on /root/swap. Priority:-1
extents:2 across:3037200k SSFS
2. Edit the 'deploy_DATE.yml' file and create a structure that will run the
following against ONE of the groups in your host configuration:
- Using the package installation module, install lynx package
- Using the package installation module, determine if the telnet package is
installed
CONTENT SHOULD LOOK SOMETHING LIKE:
- hosts: appserver
tasks:
- name: Install Lynx on App Servers
yum: pkg=lynx state=installed update_cache=true
- name: Querying for Telnet Install
yum: pkg=telnet state=present update_cache=true
PLAY [appserver]
**************************************************************
GATHERING FACTS
***************************************************************
ok: [tcox5.mylabserver.com]
PLAY RECAP
********************************************************************
tcox5.mylabserver.com : ok=3 changed=0 unreachable=0
failed=0
4. Edit the playbook in Step #2 and create a new section for a DIFFERENT
group in your host configuration as follows:
- Using the package installation module, install the telnet package
- Using the package installation module, determine if the lynx package is
installed
FULL FILE SHOULD NOW LOOK SOMETHING LIKE:
- hosts: appserver
tasks:
- name: Install Lynx on App Servers
yum: pkg=lynx state=installed update_cache=true
- name: Querying for Telnet Install
yum: pkg=telnet state=present update_cache=true
- hosts: apacheweb
tasks:
- name: Install Lynx on Web Servers
yum: pkg=telnet state=installed update_cache=true
- name: Querying for Lynx Install
yum: pkg=lynx state=present update_cache=true
PLAY [appserver]
**************************************************************
GATHERING FACTS
***************************************************************
ok: [tcox5.mylabserver.com]
PLAY [apacheweb]
**************************************************************
GATHERING FACTS
***************************************************************
ok: [tcox4.mylabserver.com]
PLAY RECAP
********************************************************************
tcox4.mylabserver.com : ok=3 changed=0 unreachable=0
failed=0
tcox5.mylabserver.com : ok=3 changed=0 unreachable=0
failed=0
6. Tail the last lines of the ansible log file and compare to the results in
Step #5.
[test@tcox3 Playbooks]$ tail /var/log/ansible.log
2015-09-25 18:25:43,538 p=1682 u=test |
2015-09-25 18:25:43,569 p=1682 u=test | PLAY [appserver]
**************************************************************
2015-09-25 18:25:43,569 p=1682 u=test | GATHERING FACTS
***************************************************************
2015-09-25 18:25:43,782 p=1682 u=test | ok: [tcox5.mylabserver.com]
2015-09-25 18:25:43,783 p=1682 u=test | TASK: [Install Lynx on App
Servers] *******************************************
2015-09-25 18:25:47,166 p=1682 u=test | ok: [tcox5.mylabserver.com]
2015-09-25 18:25:47,166 p=1682 u=test | TASK: [Querying for Telnet
Install] *******************************************
2015-09-25 18:25:51,595 p=1682 u=test | ok: [tcox5.mylabserver.com]
2015-09-25 18:25:51,596 p=1682 u=test | PLAY RECAP
********************************************************************
2015-09-25 18:25:51,596 p=1682 u=test | tcox5.mylabserver.com
: ok=3 changed=0 unreachable=0 failed=0
1. Run the appropriate ansible command to list all the hosts that are
configured on your system for access by the control server. Display the
ansible 'hosts' file in active use on the control server so that the hosts and
groups are displayed.
[test@tcox3 ~]$ ansible all --list-hosts
tcox5.mylabserver.com
localhost
tcox4.mylabserver.com
[test@tcox3 ~]$ cat /etc/ansible/hosts
[local]
localhost
[apacheweb]
tcox4.mylabserver.com
[appserver]
tcox5.mylabserver.com
3. Edit the playbook and create a target section that will run against either
one of the defined hosts in Step #1 above or a group of hosts in Step #1
above. Save the plabook and execute the appropriate command to run the
playbook and display the results.
[test@tcox3 Playbooks]$ vim myfirstplaybook.yml
[test@tcox3 Playbooks]$ cat myfirstplaybook.yml
--- # My First YAML Playbook for Ansible
- hosts: apacheweb
PLAY [apacheweb]
**************************************************************
GATHERING FACTS
***************************************************************
ok: [tcox4.mylabserver.com]
PLAY RECAP
********************************************************************
tcox4.mylabserver.com : ok=1 changed=0 unreachable=0
failed=0
4. Edit the playbook and add the following to the target section we just
created:
- Force use of SSH connections
- Always run the playbook as the user 'test'
- Run this playbook as SUDO by default
- Do not use the setup module to gather facts from systems during
execution
[test@tcox3 Playbooks]$ vim myfirstplaybook.yml
[test@tcox3 Playbooks]$ cat myfirstplaybook.yml
--- # My First YAML Playbook for Ansible
- hosts: apacheweb
user: test
sudo: yes
connection: ssh
gather_facts: no
5. Display the file and run the playbook, displaying the results of the run.
[test@tcox3 Playbooks]$ cat myfirstplaybook.yml
--- # My First YAML Playbook for Ansible
- hosts: apacheweb
user: test
sudo: yes
connection: ssh
gather_facts: no
PLAY [apacheweb]
**************************************************************
PLAY RECAP
********************************************************************
1. Run the appropriate ansible command to list all the hosts that are
configured on your system for access by the control server. Display the
ansible 'hosts' file in active use on the control server so that the hosts and
groups are displayed.
[test@tcox3 ~]$ ansible all --list-hosts
tcox5.mylabserver.com
localhost
tcox4.mylabserver.com
[test@tcox3 ~]$ cat /etc/ansible/hosts
[local]
localhost
[apacheweb]
tcox4.mylabserver.com
[appserver]
tcox5.mylabserver.com
2. Create a directory called 'conf'. Change to that directory and create two
files, one called 'copyright.yml' and one called 'webdefaults.yml'. In the
copyright file, create variables called 'message' and 'author' containing
appropriate text of your choice. In the webdefaults file, create two variables
called 'apache_version' and 'apache_mod_req' with values of your choice.
Display the files.
[test@tcox3 Playbooks]$ mkdir conf
[test@tcox3 Playbooks]$ cd conf
[test@tcox3 conf]$ cat
copyright.yml webdefaults.yml
[test@tcox3 conf]$ cat copyright.yml
---
message: Copyright 2015 by Linux Academy
author: Linux Academy
[test@tcox3 conf]$ cat webdefaults.yml
---
apache_version: 2.6
apache_mod_req: mod_ssl
PLAY [apacheweb]
**************************************************************
PLAY RECAP
********************************************************************
5. Run the ansible playbook just edited and note the results.
[test@tcox3 Playbooks]$ ansible-playbook myfirstplaybook.yml
PLAY [apacheweb]
**************************************************************
PLAY RECAP
********************************************************************
1. Run the appropriate ansible command to list all the hosts that are
configured on your system for access by the control server. Display the
ansible 'hosts' file in active use on the control server so that the hosts and
groups are displayed.
[test@tcox3 ~]$ ansible all --list-hosts
tcox5.mylabserver.com
localhost
tcox4.mylabserver.com
[test@tcox3 ~]$ cat /etc/ansible/hosts
[local]
localhost
[apacheweb]
tcox4.mylabserver.com
[appserver]
tcox5.mylabserver.com
3. Run the playbook, after the initial installation of apache, run the playbook
a second time to note the differing output.
[test@tcox3 Playbooks]$ ansible-playbook myfirstplaybook.yml
PLAY [apacheweb]
**************************************************************
PLAY RECAP
********************************************************************
tcox4.mylabserver.com : ok=1 changed=1 unreachable=0
failed=0
PLAY [apacheweb]
**************************************************************
PLAY RECAP
********************************************************************
tcox4.mylabserver.com : ok=1 changed=0 unreachable=0
failed=0
4. Add another task to the playbook that uses the 'yum' module to check
and see if the 'lynx' package is installed and then display that file.
[test@tcox3 Playbooks]$ vim myfirstplaybook.yml
[test@tcox3 Playbooks]$ cat myfirstplaybook.yml
--- # My First YAML Playbook for Ansible
- hosts: apacheweb
user: test
sudo: yes
connection: ssh
gather_facts: no
vars:
playbook_version: 0.1b
vars_files:
- conf/copyright.yml
- conf/webdefaults.yml
tasks:
- name: Install Apache Web Server
action: yum name=httpd state=installed
- name: Verify the Lynx Web Browser
action: yum name=lynx state=present
PLAY [apacheweb]
**************************************************************
PLAY RECAP
********************************************************************
tcox4.mylabserver.com : ok=2 changed=0 unreachable=0
failed=0
2. Run the ansible command that lists all of the hosts configured in your
control server 'hosts' file for the system.
[test@tcox3 ~]$ ansible all --list-hosts
tcox5.mylabserver.com
localhost
tcox4.mylabserver.com
PLAY [apacheweb]
**************************************************************
PLAY RECAP
********************************************************************
tcox4.mylabserver.com : ok=1 changed=0 unreachable=0
failed=0
2. Run the ansible command that lists all of the hosts configured in your
control server 'hosts' file for the system.
[test@tcox3 ~]$ ansible all --list-hosts
tcox5.mylabserver.com
localhost
tcox4.mylabserver.com
PLAY [apacheweb]
**************************************************************
TASK: [Install Apache Web Server]
*********************************************
changed: [tcox4.mylabserver.com]
PLAY RECAP
********************************************************************
tcox4.mylabserver.com : ok=2 changed=2 unreachable=0
failed=0
PLAY [aptserver]
**************************************************************
GATHERING FACTS
***************************************************************
ok: [tcox1.mylabserver.com]
PLAY RECAP
********************************************************************
2. Run the ansible command that lists all of the hosts configured in your
control server 'hosts' file for the system.
[test@tcox3 ~]$ ansible all --list-hosts
tcox5.mylabserver.com
localhost
tcox4.mylabserver.com
PLAY [apacheweb]
**************************************************************
PLAY RECAP
********************************************************************
2. Run the ansible command that lists all of the hosts configured in your
control server 'hosts' file for the system.
[test@tcox3 ~]$ ansible all --list-hosts
tcox5.mylabserver.com
localhost
tcox4.mylabserver.com
3. Create a playbook, using the 'LOCAL ACTION' concepts from the video:
- Uses local connection
- Logs in to the remote system as 'test' user
- Connects to the localhost
- The playbook runs as 'sudo'
- Skip gathering remote facts
- Installs the 'Telnet Client' using the appropriate package module
[test@tcox3 Playbooks]$ vim local.yml
[test@tcox3 Playbooks]$ cat local.yml
--- # LOCAL ACTION PLAYBOOK
- hosts: 127.0.0.1
connection: local
tasks:
- name: Install Telnet Client
yum: pkg=telnet state=latest
PLAY [127.0.0.1]
**************************************************************
GATHERING FACTS
***************************************************************
ok: [127.0.0.1]
PLAY RECAP
********************************************************************
3. Create a playbook, using the 'RUN ONCE' concepts from the video:
- Uses SSH
- Logs in to the remote system as 'test' user
- Connects to ALL servers
- The playbook runs as 'sudo'
- Skip gathering remote facts
- Runs the remote 'uptime' command and logs it to the remote /home/test
directory in a file called 'uptime.log'
- List the remote /var directory and pipe the output to the /home/test
directory in a file called 'dir.list'
- Indicate that the directory listing command should only be run ONCE on
the first host and not again
[test@tcox3 Playbooks]$ vim runonce.yml
[test@tcox3 Playbooks]$ cat runonce.yml
--- # RUNONCE PLAYBOOK EXAMPLE
- hosts: all
user: test
sudo: yes
connection: ssh
gather_facts: no
tasks:
- name: Run the uptime command on all hosts and log it
raw: /usr/bin/uptime >> /home/test/uptime.log
- name: List the /var directory and log it
raw: ls -al /var >> /home/test/dir.list
run_once: true
4. Run the playbook and display the results.
[test@tcox3 Playbooks]$ ansible-playbook runonce.yml
PLAY [all]
********************************************************************
TASK: [Run the uptime command on all hosts and log it]
************************
ok: [localhost]
ok: [tcox4.mylabserver.com]
ok: [tcox5.mylabserver.com]
ok: [tcox1.mylabserver.com]
PLAY RECAP
********************************************************************
2. Run the ansible command that lists all of the hosts configured in your
control server 'hosts' file for the system.
[test@tcox3 ~]$ ansible all --list-hosts
tcox5.mylabserver.com
localhost
tcox4.mylabserver.com
PLAY [apacheweb]
**************************************************************
PLAY RECAP
********************************************************************
tcox4.mylabserver.com : ok=1 changed=0 unreachable=0
failed=0
2. Run the ansible command that lists all of the hosts configured in your
control server 'hosts' file for the system.
[test@tcox3 ~]$ ansible all --list-hosts
tcox5.mylabserver.com
localhost
tcox4.mylabserver.com
PLAY [apacheweb]
**************************************************************
PLAY RECAP
********************************************************************
tcox4.mylabserver.com : ok=3 changed=0 unreachable=0
failed=0
2. Run the ansible command that lists all of the hosts configured in your
control server 'hosts' file for the system.
[test@tcox3 ~]$ ansible all --list-hosts
tcox5.mylabserver.com
localhost
tcox4.mylabserver.com
4. Run the playbook and display the results. Run the playbook a second
time and ONLY run the tag called 'packages'.
[test@tcox3 Playbooks]$ ansible-playbook tags.yml
PLAY [apacheweb]
**************************************************************
PLAY RECAP
********************************************************************
tcox4.mylabserver.com : ok=2 changed=0 unreachable=0
failed=0
PLAY RECAP
********************************************************************
tcox4.mylabserver.com : ok=1 changed=0 unreachable=0
failed=0
2. Run the ansible command that lists all of the hosts configured in your
control server 'hosts' file for the system.
[test@tcox3 ~]$ ansible all --list-hosts
tcox5.mylabserver.com
localhost
tcox4.mylabserver.com
PLAY [apacheweb]
**************************************************************
PLAY RECAP
********************************************************************
2. Run the ansible command that lists all of the hosts configured in your
control server 'hosts' file for the system.
[test@tcox3 ~]$ ansible all --list-hosts
tcox5.mylabserver.com
localhost
tcox4.mylabserver.com
PLAY [apacheweb]
**************************************************************
PLAY RECAP
********************************************************************
tcox4.mylabserver.com : ok=2 changed=1 unreachable=0
failed=0
1. Verify that your ansible installation is available by displaying the version
of ansible while logged in as the 'user' user.
[test@tcox3 ~]$ ansible --version
ansible 1.9.2
configured module search path = None
2. Run the ansible command that lists all of the hosts configured in your
control server 'hosts' file for the system.
[test@tcox3 ~]$ ansible all --list-hosts
tcox5.mylabserver.com
localhost
tcox4.mylabserver.com
PLAY [apacheweb]
**************************************************************
PLAY RECAP
********************************************************************
tcox4.mylabserver.com : ok=3 changed=1 unreachable=0
failed=0
2. Run the ansible command that lists all of the hosts configured in your
control server 'hosts' file for the system.
[test@tcox3 ~]$ ansible all --list-hosts
tcox5.mylabserver.com
localhost
tcox4.mylabserver.com
2. Run the ansible command that lists all of the hosts configured in your
control server 'hosts' file for the system.
[test@tcox3 ~]$ ansible all --list-hosts
tcox5.mylabserver.com
localhost
tcox4.mylabserver.com
PLAY [apacheweb]
**************************************************************
TASK: [date/time stamp for when the playbook starts]
**************************
ok: [tcox4.mylabserver.com]
PLAY RECAP
********************************************************************
2. Run the ansible command that lists all of the hosts configured in your
control server 'hosts' file for the system.
[test@tcox3 ~]$ ansible all --list-hosts
tcox5.mylabserver.com
localhost
tcox4.mylabserver.com
PLAY [apacheweb]
**************************************************************
PLAY RECAP
********************************************************************
tcox4.mylabserver.com : ok=12 changed=8 unreachable=0
failed=0
1. Verify that your ansible installation is available by displaying the version
of ansible while logged in as the 'user' user.
[test@tcox3 ~]$ ansible --version
ansible 1.9.2
configured module search path = None
2. Run the ansible command that lists all of the hosts configured in your
control server 'hosts' file for the system.
[test@tcox3 ~]$ ansible all --list-hosts
tcox5.mylabserver.com
localhost
tcox4.mylabserver.com
PLAY [apacheweb]
**************************************************************
PLAY RECAP
********************************************************************
2. Run the ansible command that lists all of the hosts configured in your
control server 'hosts' file for the system.
[test@tcox3 ~]$ ansible all --list-hosts
tcox5.mylabserver.com
localhost
tcox4.mylabserver.com
<Account Information>
Username {{ userName }}
Password {{ userPassword }}
</Account Information>
<System Information>
DistributionType {{ ansible_os_family }}
</System Information>
NOTE THAT THIS IS ONE EXAMPLE, YOUR EXAMPLE CAN AND
PROBABLY WILL VARY, THIS IS JUST AN EXAMPLE
2. Run the ansible command that lists all of the hosts configured in your
control server 'hosts' file for the system.
[test@tcox3 ~]$ ansible all --list-hosts
tcox5.mylabserver.com
localhost
tcox4.mylabserver.com
PLAY [apacheweb:debian]
*******************************************************
GATHERING FACTS
***************************************************************
ok: [tcox4.mylabserver.com]
ok: [tcox1.mylabserver.com]
2. Run the ansible command that lists all of the hosts configured in your
control server 'hosts' file for the system.
[test@tcox3 ~]$ ansible all --list-hosts
tcox5.mylabserver.com
localhost
tcox4.mylabserver.com
3. Create a playbook, using the 'START AT' concepts from the video:
- Uses SSH
- Logs in to the remote system as 'test' user
- Connects to one server or group from Step #2 above
- The playbook runs as 'sudo'
- Skip gathering remote facts
- Uses three separate, named, tasks to install three packages (your choice)
--- # START AT PLAYBOOK EXAMPLE
- hosts: apacheweb
user: test
sudo: yes
connection: ssh
gather_facts: no
tasks:
- name: Install Telnet
yum: pkg=telnet state=latest
- name: Install Lynx
yum: pkg=lynx state=latest
- name: Install at
yum: pkg=at state=latest
4. Run the playbook, starting with the SECOND named task and display
the results.
[test@tcox3 Playbooks]$ ansible-playbook startat.yml --start-
at="Install Lynx"
PLAY [apacheweb]
**************************************************************
PLAY RECAP
********************************************************************
tcox4.mylabserver.com : ok=2 changed=2 unreachable=0
failed=0
2. Run the ansible command that lists all of the hosts configured in your
control server 'hosts' file for the system.
[test@tcox3 ~]$ ansible all --list-hosts
tcox5.mylabserver.com
localhost
tcox4.mylabserver.com
3. Create a playbook, using the 'STEP INTO' concepts from the video:
- Uses SSH
- Logs in to the remote system as 'test' user
- Connects to one server or group from Step #2 above
- The playbook runs as 'sudo'
- Skip gathering remote facts
- Uses three separate, named, tasks to install three packages (your choice)
--- # START AT PLAYBOOK EXAMPLE
- hosts: apacheweb
user: test
sudo: yes
connection: ssh
gather_facts: no
tasks:
- name: Install Telnet
yum: pkg=telnet state=latest
- name: Install Lynx
yum: pkg=lynx state=latest
- name: Install at
yum: pkg=at state=latest
4. Run the playbook, indicating that you should be prompted for each task
run.
[test@tcox3 Playbooks]$ ansible-playbook startat.yml --step
PLAY [apacheweb]
**************************************************************
Perform task: Install Telnet (y/n/c): y
PLAY RECAP
********************************************************************
tcox4.mylabserver.com : ok=3 changed=0 unreachable=0
failed=0
2. Run the ansible command that lists all of the hosts configured in your
control server 'hosts' file for the system.
[test@tcox3 ~]$ ansible all --list-hosts
tcox5.mylabserver.com
localhost
tcox4.mylabserver.com
PLAY [apacheweb]
**************************************************************
PLAY RECAP
********************************************************************
tcox4.mylabserver.com : ok=1 changed=0 unreachable=0
failed=0
3. Create a playbook, using the 'DELEGATE TO' concepts from the video:
- Uses local connection
- Logs in to the remote system as 'test' user
- Connects to the localhost
- The playbook runs as 'sudo'
- Skip gathering remote facts
- Installs the 'Telnet Client' using the appropriate package module
[test@tcox3 Playbooks]$ vim local.yml
[test@tcox3 Playbooks]$ cat local.yml
--- # LOCAL ACTION PLAYBOOK
- hosts: 127.0.0.1
connection: local
tasks:
- name: Install Telnet Client
yum: pkg=telnet state=latest
PLAY [127.0.0.1]
**************************************************************
GATHERING FACTS
***************************************************************
ok: [127.0.0.1]
PLAY RECAP
********************************************************************
127.0.0.1 : ok=2 changed=0 unreachable=0
failed=0