From be3ea1ca7841423a6f29f7bdc88585e815b04d87 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?D=C3=B3nal=20Cunningham?= <donal.cunningham@heanet.ie>
Date: Wed, 8 Dec 2021 20:27:27 +0000
Subject: [PATCH] DC - reorganised the show version playbooks

---
 README.md                                     |  4 +--
 Section1/show_version/ansible.cfg             | 16 ------------
 Section2/playbooks/ansible.cfg                |  1 +
 .../all.yaml}                                 |  0
 .../devicename.yaml}                          |  0
 Section2/playbooks/hosts                      | 11 ++++++--
 Section2/playbooks/hosts_simple               |  3 ---
 Section2/playbooks/ping.output                | 19 ++++++++++++++
 Section2/playbooks/ping.yaml                  |  2 +-
 Section2/playbooks/ping_unknown_host.output   |  7 +++++
 Section2/playbooks/ping_unknown_host.yaml     |  9 +++++++
 .../playbooks/ping_unreachable_host.output    | 11 ++++++++
 Section2/playbooks/ping_unreachable_host.yaml |  9 +++++++
 Section2/playbooks/show_version.yaml          | 12 ---------
 .../playbooks}/show_version/README.md         | 10 +++----
 Section2/playbooks/show_version/ansible.cfg   |  9 +++++++
 Section2/playbooks/show_version/hosts         | 14 ++++++++++
 .../show_version/show_all_responses.output    |  8 +++---
 .../show_version/show_all_responses.yaml      |  2 +-
 .../show_version/show_version.output          |  0
 .../playbooks}/show_version/show_version.yaml |  2 +-
 .../show_version_and_uptime.output            |  0
 .../show_version/show_version_and_uptime.yaml |  0
 .../show_version/show_version_arista.output   |  0
 .../show_version/show_version_arista.yaml     |  2 +-
 .../show_version/show_version_juniper.output  |  0
 .../show_version/show_version_juniper.yaml    |  2 +-
 Section2/playbooks/show_version_simple.yaml   | 26 -------------------
 Section2/playbooks/show_version_with_raw.yaml |  8 ------
 .../playbooks/simple_example_playbook.yaml    |  7 ++++-
 ...{tree.txt => tree_directory_structure.txt} |  0
 ...ple_variables.yaml => variable_files.yaml} |  0
 32 files changed, 110 insertions(+), 84 deletions(-)
 delete mode 100644 Section1/show_version/ansible.cfg
 rename Section2/playbooks/{real_world_group_var.yaml => group_vars/all.yaml} (100%)
 rename Section2/playbooks/{real_world_host_var.yaml => host_vars/devicename.yaml} (100%)
 delete mode 100644 Section2/playbooks/hosts_simple
 create mode 100644 Section2/playbooks/ping.output
 create mode 100644 Section2/playbooks/ping_unknown_host.output
 create mode 100644 Section2/playbooks/ping_unknown_host.yaml
 create mode 100644 Section2/playbooks/ping_unreachable_host.output
 create mode 100644 Section2/playbooks/ping_unreachable_host.yaml
 delete mode 100644 Section2/playbooks/show_version.yaml
 rename {Section1 => Section2/playbooks}/show_version/README.md (83%)
 create mode 100644 Section2/playbooks/show_version/ansible.cfg
 create mode 100644 Section2/playbooks/show_version/hosts
 rename {Section1 => Section2/playbooks}/show_version/show_all_responses.output (55%)
 rename {Section1 => Section2/playbooks}/show_version/show_all_responses.yaml (93%)
 rename {Section1 => Section2/playbooks}/show_version/show_version.output (100%)
 rename {Section1 => Section2/playbooks}/show_version/show_version.yaml (97%)
 rename {Section1 => Section2/playbooks}/show_version/show_version_and_uptime.output (100%)
 rename {Section1 => Section2/playbooks}/show_version/show_version_and_uptime.yaml (100%)
 rename {Section1 => Section2/playbooks}/show_version/show_version_arista.output (100%)
 rename {Section1 => Section2/playbooks}/show_version/show_version_arista.yaml (97%)
 rename {Section1 => Section2/playbooks}/show_version/show_version_juniper.output (100%)
 rename {Section1 => Section2/playbooks}/show_version/show_version_juniper.yaml (93%)
 delete mode 100644 Section2/playbooks/show_version_simple.yaml
 delete mode 100644 Section2/playbooks/show_version_with_raw.yaml
 rename Section2/playbooks/{tree.txt => tree_directory_structure.txt} (100%)
 rename Section2/playbooks/{simple_variables.yaml => variable_files.yaml} (100%)

diff --git a/README.md b/README.md
index eddfe31..40a22ed 100644
--- a/README.md
+++ b/README.md
@@ -2,6 +2,6 @@
 
 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/`.
+These mostly consist of vEOS examples but there is a `show_version_juniper` example in `Section2/playbooks/show_version/`.
 
-Some of the files are accompanied by example output, e.g. `show_version.yaml` produced `show_version.output`.
+Some of the files are accompanied by example output, e.g. `show_version.yaml` is accompanied by `show_version.output`.
diff --git a/Section1/show_version/ansible.cfg b/Section1/show_version/ansible.cfg
deleted file mode 100644
index 5a86c42..0000000
--- a/Section1/show_version/ansible.cfg
+++ /dev/null
@@ -1,16 +0,0 @@
-[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
diff --git a/Section2/playbooks/ansible.cfg b/Section2/playbooks/ansible.cfg
index 259fbb9..913fbe0 100644
--- a/Section2/playbooks/ansible.cfg
+++ b/Section2/playbooks/ansible.cfg
@@ -4,6 +4,7 @@ host_key_checking = False
 
 stdout_callback = yaml
 
+# Damned cows...
 nocows = True
 
 inventory = hosts
diff --git a/Section2/playbooks/real_world_group_var.yaml b/Section2/playbooks/group_vars/all.yaml
similarity index 100%
rename from Section2/playbooks/real_world_group_var.yaml
rename to Section2/playbooks/group_vars/all.yaml
diff --git a/Section2/playbooks/real_world_host_var.yaml b/Section2/playbooks/host_vars/devicename.yaml
similarity index 100%
rename from Section2/playbooks/real_world_host_var.yaml
rename to Section2/playbooks/host_vars/devicename.yaml
diff --git a/Section2/playbooks/hosts b/Section2/playbooks/hosts
index 17b6438..685ec3a 100644
--- a/Section2/playbooks/hosts
+++ b/Section2/playbooks/hosts
@@ -1,9 +1,16 @@
 [all:vars]
 ansible_user=zork
 ansible_ssh_pass=swordfish
+ansible_host=localhost
 
 [veos_hosts]
-veos ansible_port=9022 ansible_host=localhost ansible_network_os=eos ansible_connection=network_cli
+veos ansible_port=9022  ansible_network_os=eos ansible_connection=network_cli
 
 [debian_hosts]
-testhost ansible_port=9023 ansible_host=localhost
+testhost ansible_port=9024
+
+#
+# Why different passwords? JunOS is a lot stricter. Good!
+#
+[junos_hosts]
+vSRX ansible_port=9023 ansible_ssh_pass=Swordfish123
diff --git a/Section2/playbooks/hosts_simple b/Section2/playbooks/hosts_simple
deleted file mode 100644
index 769e9ad..0000000
--- a/Section2/playbooks/hosts_simple
+++ /dev/null
@@ -1,3 +0,0 @@
-[guinea_pigs]
-veos ansible_connection=ssh ansible_host=localhost ansible_port=9022 ansible_user=zork ansible_ssh_pass=swordfish
-
diff --git a/Section2/playbooks/ping.output b/Section2/playbooks/ping.output
new file mode 100644
index 0000000..47501c3
--- /dev/null
+++ b/Section2/playbooks/ping.output
@@ -0,0 +1,19 @@
+
+PLAY [A play to run the ping module] ******************************************************************************************************************************************
+
+TASK [Gathering Facts] ********************************************************************************************************************************************************
+ok: [testhost]
+
+TASK [A task to invoke the ping module] ***************************************************************************************************************************************
+ok: [testhost]
+
+TASK [A task to print the output] *********************************************************************************************************************************************
+ok: [testhost] => 
+  ping_results:
+    changed: false
+    failed: false
+    ping: pong
+
+PLAY RECAP ********************************************************************************************************************************************************************
+testhost                   : ok=3    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
+
diff --git a/Section2/playbooks/ping.yaml b/Section2/playbooks/ping.yaml
index 50a1cbd..f5299fe 100644
--- a/Section2/playbooks/ping.yaml
+++ b/Section2/playbooks/ping.yaml
@@ -1,6 +1,6 @@
 ---
 - name: A play to run the ping module
-  hosts: testhost
+  hosts: debian_hosts
   tasks:
   - name: A task to invoke the ping module
     ping:
diff --git a/Section2/playbooks/ping_unknown_host.output b/Section2/playbooks/ping_unknown_host.output
new file mode 100644
index 0000000..545b75a
--- /dev/null
+++ b/Section2/playbooks/ping_unknown_host.output
@@ -0,0 +1,7 @@
+[WARNING]: Could not match supplied host pattern, ignoring: fakeserver
+
+PLAY [A play to run the ping module] **********************************************************
+skipping: no hosts matched
+
+PLAY RECAP ************************************************************************************
+
diff --git a/Section2/playbooks/ping_unknown_host.yaml b/Section2/playbooks/ping_unknown_host.yaml
new file mode 100644
index 0000000..7745dfc
--- /dev/null
+++ b/Section2/playbooks/ping_unknown_host.yaml
@@ -0,0 +1,9 @@
+---
+- name: A play to run the ping module
+  hosts: fakeserver
+  tasks:
+  - name: A task to invoke the ping module
+    ping:
+    register: ping_results
+  - name: A task to print the output
+    debug: var=ping_results
diff --git a/Section2/playbooks/ping_unreachable_host.output b/Section2/playbooks/ping_unreachable_host.output
new file mode 100644
index 0000000..76adfee
--- /dev/null
+++ b/Section2/playbooks/ping_unreachable_host.output
@@ -0,0 +1,11 @@
+
+PLAY [A play to run the ping module against an unreachable host] ***************
+
+TASK [Gathering Facts] *********************************************************
+fatal: [vSRX]: UNREACHABLE! => changed=false 
+  msg: 'Failed to connect to the host via ssh: ssh: connect to host localhost port 9023: Connection refused'
+  unreachable: true
+
+PLAY RECAP *********************************************************************
+vSRX                       : ok=0    changed=0    unreachable=1    failed=0    skipped=0    rescued=0    ignored=0   
+
diff --git a/Section2/playbooks/ping_unreachable_host.yaml b/Section2/playbooks/ping_unreachable_host.yaml
new file mode 100644
index 0000000..2213e9b
--- /dev/null
+++ b/Section2/playbooks/ping_unreachable_host.yaml
@@ -0,0 +1,9 @@
+---
+- name: A play to run the ping module against an unreachable host
+  hosts: vSRX
+  tasks:
+  - name: A task to invoke the ping module
+    ping:
+    register: ping_results
+  - name: A task to print the output
+    debug: var=ping_results
diff --git a/Section2/playbooks/show_version.yaml b/Section2/playbooks/show_version.yaml
deleted file mode 100644
index 92d342d..0000000
--- a/Section2/playbooks/show_version.yaml
+++ /dev/null
@@ -1,12 +0,0 @@
----
-- name: Check the version of code on all switches
-  hosts: veos
-  gather_facts: no        # or False
-  tasks:
-    - name:     Gather version from switches
-      raw:      ‘show version| include Software’
-      register: show_version
-
-    - name:     Display the version
-      debug:    var=show_version
-
diff --git a/Section1/show_version/README.md b/Section2/playbooks/show_version/README.md
similarity index 83%
rename from Section1/show_version/README.md
rename to Section2/playbooks/show_version/README.md
index 6c53d04..00c4197 100644
--- a/Section1/show_version/README.md
+++ b/Section2/playbooks/show_version/README.md
@@ -4,19 +4,19 @@ The hosts file in this directory has two hosts defined - one vEOS, one JunOS.
 
 ```
 [all:vars]
-ansible_connection=ssh
 ansible_user=zork
+ansible_ssh_pass=swordfish
 ansible_host=localhost
+ansible_connection=ssh
 
 [veos_hosts]
-veos ansible_port=9022 ansible_ssh_pass=swordfish
+veos ansible_port=9022
 
 #
 # Why different passwords? JunOS is a lot stricter. Good!
 #
 [junos_hosts]
-vSRX ansible_port=9023 ansible_ssh_pass=Swordfish123
-```
+vSRX ansible_port=9023 ansible_ssh_pass=Swordfish123```
 
 You will need to replace the host information to match your test/learning environment.
 
@@ -34,4 +34,4 @@ Run ``ansible-playbook -i hosts show_version_and_uptime.yaml``
 
 # Device specific
 
-There are device-specific `show version` playbooks. JunOS in particular paginates its output - so you have to run the command through `no-more` to stop it printing `--More--` and pausing for keyboard input...which since it's hidden by Ansible will never come.
+There are device-specific `show version` playbooks. JunOS in particular paginates its output - so you have to run the command through `no-more` to stop it printing `--More--` and pausing for keyboard input. Which - since the prompt is hidden by Ansible - will never come.
diff --git a/Section2/playbooks/show_version/ansible.cfg b/Section2/playbooks/show_version/ansible.cfg
new file mode 100644
index 0000000..08ec8e5
--- /dev/null
+++ b/Section2/playbooks/show_version/ansible.cfg
@@ -0,0 +1,9 @@
+[defaults]
+
+host_key_checking = False
+
+#stdout_callback = yaml
+
+nocows = True
+
+inventory = hosts
diff --git a/Section2/playbooks/show_version/hosts b/Section2/playbooks/show_version/hosts
new file mode 100644
index 0000000..deffb7f
--- /dev/null
+++ b/Section2/playbooks/show_version/hosts
@@ -0,0 +1,14 @@
+[all:vars]
+ansible_user=zork
+ansible_ssh_pass=swordfish
+ansible_host=localhost
+ansible_connection=ssh
+
+[veos_hosts]
+veos ansible_port=9022
+
+#
+# Why different passwords? JunOS is a lot stricter. Good!
+#
+[junos_hosts]
+vSRX ansible_port=9023 ansible_ssh_pass=Swordfish123
diff --git a/Section1/show_version/show_all_responses.output b/Section2/playbooks/show_version/show_all_responses.output
similarity index 55%
rename from Section1/show_version/show_all_responses.output
rename to Section2/playbooks/show_version/show_all_responses.output
index 81c607e..39beb98 100644
--- a/Section1/show_version/show_all_responses.output
+++ b/Section2/playbooks/show_version/show_all_responses.output
@@ -1,10 +1,10 @@
 
-PLAY [Play 1 - Show the software version on an Arista switch] *****************************************************************************************************
+PLAY [Play 1 - Show the software version on an Arista switch] ******************
 
-TASK [Task 1.1 - Gather version from switches] ********************************************************************************************************************
+TASK [Task 1.1 - Gather version from switch using the raw module] **************
 changed: [veos]
 
-TASK [Task 1.2 - Print output] ************************************************************************************************************************************
+TASK [Task 1.2 - Print version] ************************************************
 ok: [veos] => {
     "showvers": {
         "changed": true,
@@ -21,6 +21,6 @@ ok: [veos] => {
     }
 }
 
-PLAY RECAP ********************************************************************************************************************************************************
+PLAY RECAP *********************************************************************
 veos                       : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
 
diff --git a/Section1/show_version/show_all_responses.yaml b/Section2/playbooks/show_version/show_all_responses.yaml
similarity index 93%
rename from Section1/show_version/show_all_responses.yaml
rename to Section2/playbooks/show_version/show_all_responses.yaml
index 4f38ce3..661f901 100644
--- a/Section1/show_version/show_all_responses.yaml
+++ b/Section2/playbooks/show_version/show_all_responses.yaml
@@ -1,7 +1,7 @@
 ---
 - name: Play 1 - Show the software version on an Arista switch
   hosts: veos_hosts
-  gather_facts: "no"
+  gather_facts: no
   connection: local
   tasks:
     - name: Task 1.1 - Gather version from switch using the raw module
diff --git a/Section1/show_version/show_version.output b/Section2/playbooks/show_version/show_version.output
similarity index 100%
rename from Section1/show_version/show_version.output
rename to Section2/playbooks/show_version/show_version.output
diff --git a/Section1/show_version/show_version.yaml b/Section2/playbooks/show_version/show_version.yaml
similarity index 97%
rename from Section1/show_version/show_version.yaml
rename to Section2/playbooks/show_version/show_version.yaml
index 8bfe25c..6434f0c 100644
--- a/Section1/show_version/show_version.yaml
+++ b/Section2/playbooks/show_version/show_version.yaml
@@ -1,7 +1,7 @@
 ---
 - name: Play 1 - Show the software version on an Arista switch
   hosts: veos_hosts
-  gather_facts: "no"
+  gather_facts: no
   connection: local
   tasks:
     - name: Task 1.1 - Gather version from switches using the raw module
diff --git a/Section1/show_version/show_version_and_uptime.output b/Section2/playbooks/show_version/show_version_and_uptime.output
similarity index 100%
rename from Section1/show_version/show_version_and_uptime.output
rename to Section2/playbooks/show_version/show_version_and_uptime.output
diff --git a/Section1/show_version/show_version_and_uptime.yaml b/Section2/playbooks/show_version/show_version_and_uptime.yaml
similarity index 100%
rename from Section1/show_version/show_version_and_uptime.yaml
rename to Section2/playbooks/show_version/show_version_and_uptime.yaml
diff --git a/Section1/show_version/show_version_arista.output b/Section2/playbooks/show_version/show_version_arista.output
similarity index 100%
rename from Section1/show_version/show_version_arista.output
rename to Section2/playbooks/show_version/show_version_arista.output
diff --git a/Section1/show_version/show_version_arista.yaml b/Section2/playbooks/show_version/show_version_arista.yaml
similarity index 97%
rename from Section1/show_version/show_version_arista.yaml
rename to Section2/playbooks/show_version/show_version_arista.yaml
index b749586..64cd46f 100644
--- a/Section1/show_version/show_version_arista.yaml
+++ b/Section2/playbooks/show_version/show_version_arista.yaml
@@ -1,7 +1,7 @@
 ---
 - name: Play 1 - Show the software version on an Arista switch
   hosts: veos_hosts
-  gather_facts: "no"
+  gather_facts: no
   connection: local
   tasks:
     - name: Task 1.1 - Gather version from switches
diff --git a/Section1/show_version/show_version_juniper.output b/Section2/playbooks/show_version/show_version_juniper.output
similarity index 100%
rename from Section1/show_version/show_version_juniper.output
rename to Section2/playbooks/show_version/show_version_juniper.output
diff --git a/Section1/show_version/show_version_juniper.yaml b/Section2/playbooks/show_version/show_version_juniper.yaml
similarity index 93%
rename from Section1/show_version/show_version_juniper.yaml
rename to Section2/playbooks/show_version/show_version_juniper.yaml
index cd91f71..01b8180 100644
--- a/Section1/show_version/show_version_juniper.yaml
+++ b/Section2/playbooks/show_version/show_version_juniper.yaml
@@ -1,7 +1,7 @@
 ---
 - name: Play 1 - Show the software version on a vSRX
   hosts: vSRX
-  gather_facts: "no"
+  gather_facts: no
   connection: local
   tasks:
     - name: Task 1.1 - Gather version from switches
diff --git a/Section2/playbooks/show_version_simple.yaml b/Section2/playbooks/show_version_simple.yaml
deleted file mode 100644
index db46254..0000000
--- a/Section2/playbooks/show_version_simple.yaml
+++ /dev/null
@@ -1,26 +0,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}}!"
diff --git a/Section2/playbooks/show_version_with_raw.yaml b/Section2/playbooks/show_version_with_raw.yaml
deleted file mode 100644
index c5d1b7c..0000000
--- a/Section2/playbooks/show_version_with_raw.yaml
+++ /dev/null
@@ -1,8 +0,0 @@
----
-- name: Check the version of code on a switch
-  hosts: veos
-  gather_facts: no			# or False
-  tasks:
-    - name:		Gather version from switches
-      raw:      ‘show version’
-      register: show_version
diff --git a/Section2/playbooks/simple_example_playbook.yaml b/Section2/playbooks/simple_example_playbook.yaml
index 8c4f70d..c4af863 100644
--- a/Section2/playbooks/simple_example_playbook.yaml
+++ b/Section2/playbooks/simple_example_playbook.yaml
@@ -1,6 +1,11 @@
 ---
 # Oh look, a comment…
 # …spread out over multiple lines
+
+# This is not a real playbook - please do not attempt to run it.
+# If you do it anyway, you will get this error:
+#   "ERROR! no module/action detected in task."
+
 - name: Set up Apache		# Or nginx, or Mongoose
   hosts: webservers
   tasks:
@@ -8,4 +13,4 @@
     - name: generate Apache config file
     - name: download Web content to relevant directory
     - name: restart Apache
-    - name: eat cake
+    - name: eat cake
\ No newline at end of file
diff --git a/Section2/playbooks/tree.txt b/Section2/playbooks/tree_directory_structure.txt
similarity index 100%
rename from Section2/playbooks/tree.txt
rename to Section2/playbooks/tree_directory_structure.txt
diff --git a/Section2/playbooks/simple_variables.yaml b/Section2/playbooks/variable_files.yaml
similarity index 100%
rename from Section2/playbooks/simple_variables.yaml
rename to Section2/playbooks/variable_files.yaml
-- 
GitLab