Skip to content
Snippets Groups Projects
Commit 9001bf36 authored by Dónal Cunningham's avatar Dónal Cunningham
Browse files

DC - Initial commit

parents
No related branches found
No related tags found
No related merge requests found
Showing
with 358 additions and 0 deletions
# The GÉANT Ansible learning unit
This repo holds sample Ansible playbooks for the GÉANT OAV Ansible course.
These mostly consist of vEOS examples but there is a `show_version_juniper` example in `Section1/show_version/`.
Some of the files are accompanied by example output, e.g. `show_version.yaml` produced `show_version.output`.
# Inventories
Here are four inventories to amuse you; two with just hostnames
and two with variables added in to spice it up a little.
You can verify any of them as valid inventories with
``ansible-inventory`` and its ``graph`` option.
An example command line is...
```
ansible-inventory --graph -i hosts.ini
```
## Inventory variables
If you want to see the inventory variables too, you
will need to add ``--vars`` to the command line.
loadbalancer1
[webservers]
web[1:4]_dublin
[dbservers]
db[1:2]_dublin
[all_servers:children]
webservers
dbservers
---
all:
hosts:
loadbalancer1:
children:
webservers:
hosts:
web[01:04]_dublin:
dbservers:
hosts:
db[01:02]_dublin:
all_servers:
children:
webservers:
dbservers:
loadbalancer1
veos ansible_host="localhost" ansible_port=9022
[all:vars]
ansible_user=zork
ansible_ssh_pass=swordfish
[webservers]
web[1:2]_dublin
[webservers:vars]
ansible_user=nginx_test
[dbservers]
db[1:2]_dublin
[all_servers:children]
webservers
dbservers
---
all:
vars:
ansible_user: zork
ansible_ssh_pass: swordfish
hosts:
loadbalancer1:
veos:
vars:
ansible_host: localhost
ansible_port: 9022
children:
webservers:
vars:
ansible_user: nginx_test
hosts:
web[01:04]_dublin:
dbservers:
hosts:
db[01:02]_dublin:
all_servers:
children:
webservers:
dbservers:
# Verifying connectivity with the ping module.
Just a reminder - this does NOT work on most network
equipment, but should work on servers.
```
ansible-playbook -i hosts ping.yaml
```
It should look like this:
```
$ ansible-playbook -i ./hosts ping.yaml
PLAY [A play to run the ping module] *********************************************************
TASK [Gathering Facts] ***********************************************************************
ok: [example.host.name]
TASK [A task to invoke the ping module] ******************************************************
ok: [example.host.name]
TASK [A task to print the output] ************************************************************
ok: [example.host.name] =>
ping_results:
changed: false
failed: false
ping: pong
PLAY RECAP ***********************************************************************************
example.host.name : ok=3 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
# Ping for an unknown host
If you want to see what happens when you try and
run a playbook against a non-existant host, try
this;
```
ansible-playbook -i hosts ping_unknown_host.yaml
```
(If you actually do have a host called "scapegoat" then you have bigger problems than a non-existant host...)
It should look like this:
```
$ ansible-playbook -i hosts ping_unknown_host.yaml
[WARNING]: Could not match supplied host pattern, ignoring: scapegoat
PLAY [A play to run the ping module] *********************************************************
skipping: no hosts matched
PLAY RECAP ***********************************************************************************
```
[defaults]
deprecation_warnings=False
# don't like cows? that's unfortunate.
# set to 1 if you don't want cowsay support or export ANSIBLE_NOCOWS=1
nocows = 1
# You can only have one 'stdout' callback type enabled at a time. The default
# is 'default'. The 'yaml' or 'debug' stdout callback plugins are easier to read.
#
#stdout_callback = default
stdout_callback = yaml
#stdout_callback = debug
inventory = hosts
################################################################################################
#
# Try this on any UNIX host to which you have ssh access.
#
# You will need to set several ansible variable to make it work, e.g.
#
## vhost ansible_host=localhost ansible_user=zork ansible_ssh_pass=swordfish ansible_port=9023
#
################################################################################################
vhost ansible_host=localhost ansible_user=zork ansible_ssh_pass=swordfish ansible_port=9023
PLAY [A play to run the ping module] ******************************************************************************************************************************
TASK [Gathering Facts] ********************************************************************************************************************************************
ok: [vhost]
TASK [A task to invoke the ping module] ***************************************************************************************************************************
ok: [vhost]
TASK [A task to print the output] *********************************************************************************************************************************
ok: [vhost] =>
ping_results:
changed: false
failed: false
ping: pong
PLAY RECAP ********************************************************************************************************************************************************
vhost : ok=3 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
---
- name: A play to run the ping module
hosts: all
tasks:
- name: A task to invoke the ping module
ping:
register: ping_results
- name: A task to print the output
debug: var=ping_results
[WARNING]: Could not match supplied host pattern, ignoring: scapegoat
PLAY [A play to run the ping module] ******************************************************************************************************************************
skipping: no hosts matched
PLAY RECAP ********************************************************************************************************************************************************
---
- name: A play to run the ping module
hosts: scapegoat
tasks:
- name: A task to invoke the ping module
ping:
# Show version
You need to update the hosts file : replace the "veos" host
with one to which you can log on with ssh.
Run ``ansible-playbook -i hosts show_version.yaml``.
# Show the full responses to a module invocation
This will show all of the responses, including
the bits that most people don't even exist.
Run ``ansible-playbook -i hosts show_all_responses.yaml``
# Multiple lines of commands
Run ``ansible-playbook -i hosts show_version_and_uptime.yaml``
[defaults]
deprecation_warnings=False
# don't like cows? that's unfortunate.
# set to 1 if you don't want cowsay support or export ANSIBLE_NOCOWS=1
nocows = 1
# You can only have one 'stdout' callback type enabled at a time. The default
# is 'default'. The 'yaml' or 'debug' stdout callback plugins are easier to read.
#
stdout_callback = default
#stdout_callback = yaml
#stdout_callback = debug
inventory = hosts
[all:vars]
ansible_connection=ssh
ansible_user=zork
[veos_hosts]
veos ansible_host=localhost ansible_port=9022 ansible_ssh_pass=swordfish
[junos_hosts]
vSRX ansible_host=localhost ansible_port=9023 ansible_ssh_pass=Swordfish123
PLAY [Play 1 - Show the software version on an Arista switch] *****************************************************************************************************
TASK [Task 1.1 - Gather version from switches] ********************************************************************************************************************
changed: [veos]
TASK [Task 1.2 - Print output] ************************************************************************************************************************************
ok: [veos] => {
"showvers": {
"changed": true,
"failed": false,
"rc": 0,
"stderr": "Shared connection to localhost closed.\r\n",
"stderr_lines": [
"Shared connection to localhost closed."
],
"stdout": "Software image version: 4.27.0F\r\n",
"stdout_lines": [
"Software image version: 4.27.0F"
]
}
}
PLAY RECAP ********************************************************************************************************************************************************
veos : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
---
- name: Play 1 - Show the software version on an Arista switch
hosts: veos
gather_facts: "no"
connection: local
tasks:
- name: Task 1.1 - Gather version from switches
raw: 'show version | include Software'
register: showvers
- name: Task 1.2 - Print output
debug: var=showvers
PLAY [Play 1 - Show the software version on an Arista switch] *****************************************************************************************************
TASK [Task 1.1 - Gather version from switches] ********************************************************************************************************************
fatal: [veos]: UNREACHABLE! => {"changed": false, "msg": "Invalid/incorrect password: ", "unreachable": true}
PLAY RECAP ********************************************************************************************************************************************************
veos : ok=0 changed=0 unreachable=1 failed=0 skipped=0 rescued=0 ignored=0
dcunningham@hellfire ~/O/G/O/A/e/S/show_version (master) [4]> ansible-playbook -i hosts show_version.yaml
PLAY [Play 1 - Show the software version on an Arista switch] *****************************************************************************************************
TASK [Task 1.1 - Gather version from switches] ********************************************************************************************************************
changed: [veos]
TASK [Task 1.2 - Print output] ************************************************************************************************************************************
ok: [veos] => {
"showvers.stdout_lines[0]": "Software image version: 4.27.0F"
}
PLAY [Play 2 - Verify switch software] ****************************************************************************************************************************
TASK [Task 2.1 - Assert we are running the correct EOS version (4.25)] ********************************************************************************************
fatal: [veos]: FAILED! => {
"assertion": "'4.25' in showvers.stdout_lines[0]",
"changed": false,
"evaluated_to": false,
"msg": "Oh noes! Switch not running eOS 4.25!"
}
PLAY RECAP ********************************************************************************************************************************************************
veos : ok=2 changed=1 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
---
- name: Play 1 - Show the software version on an Arista switch
hosts: veos
gather_facts: "no"
connection: local
tasks:
- name: Task 1.1 - Gather version from switches
raw: 'show version | include Software'
register: showvers
- name: Task 1.2 - Print output
debug: var=showvers.stdout_lines[0]
- name: Play 2 - Verify switch software
hosts: veos
vars:
eos_version: "4.25"
gather_facts: "no"
connection: local
tasks:
- name: Task 2.1 - Assert we are running the correct EOS version ({{eos_version}})
assert:
that:
- "'{{eos_version}}' in showvers.stdout_lines[0]"
msg: "Oh noes! Switch not running eOS {{eos_version}}!"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment