From 12b2a0aa8a5161493d6940583c6565a984e5aae8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?D=C3=B3nal=20Cunningham?= <donal.cunningham@heanet.ie>
Date: Wed, 8 Dec 2021 15:27:15 +0000
Subject: [PATCH] Changed to use veos_hosts and junos_hosts in example scripts

---
 Section1/show_version/README.md               |  5 ++++
 Section1/show_version/hosts                   |  8 ++++--
 Section1/show_version/show_all_responses.yaml |  6 ++---
 Section1/show_version/show_version.yaml       | 23 ++++++++--------
 Section1/show_version/show_version_all.yaml   | 12 ---------
 .../show_version/show_version_and_uptime.yaml |  6 ++---
 .../show_version/show_version_arista.output   | 14 ++++++++++
 .../show_version/show_version_arista.yaml     | 26 +++++++++++++++++++
 .../show_version/show_version_juniper.yaml    |  4 +--
 9 files changed, 70 insertions(+), 34 deletions(-)
 delete mode 100644 Section1/show_version/show_version_all.yaml
 create mode 100644 Section1/show_version/show_version_arista.output
 create mode 100644 Section1/show_version/show_version_arista.yaml

diff --git a/Section1/show_version/README.md b/Section1/show_version/README.md
index 81b2bd2..4c95584 100644
--- a/Section1/show_version/README.md
+++ b/Section1/show_version/README.md
@@ -13,3 +13,8 @@ Run ``ansible-playbook -i hosts show_all_responses.yaml``
 # Multiple lines of commands
 
 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 will never come.
+
diff --git a/Section1/show_version/hosts b/Section1/show_version/hosts
index 9c3f3e0..a0aad73 100644
--- a/Section1/show_version/hosts
+++ b/Section1/show_version/hosts
@@ -1,9 +1,13 @@
 [all:vars]
 ansible_connection=ssh
 ansible_user=zork
+ansible_host=localhost
 
 [veos_hosts]
-veos ansible_host=localhost ansible_port=9022 ansible_ssh_pass=swordfish
+veos ansible_port=9022 ansible_ssh_pass=swordfish
 
+#
+# Why different passwords? JunOS is a lot stricter. Good!
+#
 [junos_hosts]
-vSRX ansible_host=localhost ansible_port=9023 ansible_ssh_pass=Swordfish123
+vSRX ansible_port=9023 ansible_ssh_pass=Swordfish123
diff --git a/Section1/show_version/show_all_responses.yaml b/Section1/show_version/show_all_responses.yaml
index 464ec26..4f38ce3 100644
--- a/Section1/show_version/show_all_responses.yaml
+++ b/Section1/show_version/show_all_responses.yaml
@@ -1,12 +1,12 @@
 ---
 - name: Play 1 - Show the software version on an Arista switch
-  hosts: veos
+  hosts: veos_hosts
   gather_facts: "no"
   connection: local
   tasks:
-    - name: Task 1.1 - Gather version from switches
+    - name: Task 1.1 - Gather version from switch using the raw module
       raw: 'show version | include Software'
       register: showvers
 
-    - name: Task 1.2 - Print output
+    - name: Task 1.2 - Print version
       debug: var=showvers
diff --git a/Section1/show_version/show_version.yaml b/Section1/show_version/show_version.yaml
index db46254..8bfe25c 100644
--- a/Section1/show_version/show_version.yaml
+++ b/Section1/show_version/show_version.yaml
@@ -1,26 +1,25 @@
 ---
 - name: Play 1 - Show the software version on an Arista switch
-  hosts: veos
+  hosts: veos_hosts
   gather_facts: "no"
   connection: local
   tasks:
-    - name: Task 1.1 - Gather version from switches
+    - name: Task 1.1 - Gather version from switches using the raw module
       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"
+- name: Play 2 - Show the software version on a Juniper router
+  hosts: junos_hosts
   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}}!"
+    - name: Task 2.1 - Gather version from switches using the raw module
+      raw: 'show version | no-more| match Junos '
+      register: showvers
+
+    - name: Task 1.2 - Print output
+      debug: var=showvers.stdout_lines[0]
+
diff --git a/Section1/show_version/show_version_all.yaml b/Section1/show_version/show_version_all.yaml
deleted file mode 100644
index a78bb33..0000000
--- a/Section1/show_version/show_version_all.yaml
+++ /dev/null
@@ -1,12 +0,0 @@
----
-- name: Play 1 - Show the software version on all devices
-  hosts: all
-  gather_facts: "no"
-  connection: local
-  tasks:
-    - name: Task 1.1 - Gather version from switches
-      raw: 'show version'
-      register: showvers
-
-    - name: Task 1.2 - Print output
-      debug: var=showvers.stdout_lines
diff --git a/Section1/show_version/show_version_and_uptime.yaml b/Section1/show_version/show_version_and_uptime.yaml
index 732b86e..f317475 100644
--- a/Section1/show_version/show_version_and_uptime.yaml
+++ b/Section1/show_version/show_version_and_uptime.yaml
@@ -1,12 +1,12 @@
 ---
-- name: Play 1 - Show the software version on an Arista switch
-  hosts: veos
+- name: Play 1 - Show output of multiple commands on an Arista switch
+  hosts: veos_hosts
   gather_facts: no
   vars:
     ansible_connection: network_cli
     ansible_network_os: eos
   tasks:
-    - name: Task 1.1 - Gather version from switches
+    - name: Task 1.1 - Gather version and uptime from the switch using eos_command
       eos_command:
         commands:
           - 'show version | include Software'
diff --git a/Section1/show_version/show_version_arista.output b/Section1/show_version/show_version_arista.output
new file mode 100644
index 0000000..06e13f2
--- /dev/null
+++ b/Section1/show_version/show_version_arista.output
@@ -0,0 +1,14 @@
+
+PLAY [Play 1 - Show the software version on a vSRX] ****************************
+
+TASK [Task 1.1 - Gather version from switches] *********************************
+changed: [vSRX]
+
+TASK [Task 1.2 - Print output] *************************************************
+ok: [vSRX] => {
+    "showvers.stdout_lines[0]": "Junos: 21.3R1.9"
+}
+
+PLAY RECAP *********************************************************************
+vSRX                       : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
+
diff --git a/Section1/show_version/show_version_arista.yaml b/Section1/show_version/show_version_arista.yaml
new file mode 100644
index 0000000..b749586
--- /dev/null
+++ b/Section1/show_version/show_version_arista.yaml
@@ -0,0 +1,26 @@
+---
+- name: Play 1 - Show the software version on an Arista switch
+  hosts: veos_hosts
+  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/Section1/show_version/show_version_juniper.yaml b/Section1/show_version/show_version_juniper.yaml
index 4bded5d..cd91f71 100644
--- a/Section1/show_version/show_version_juniper.yaml
+++ b/Section1/show_version/show_version_juniper.yaml
@@ -5,8 +5,8 @@
   connection: local
   tasks:
     - name: Task 1.1 - Gather version from switches
-      raw: 'show version | no-more'
+      raw: 'show version | no-more | match Junos: '
       register: showvers
 
     - name: Task 1.2 - Print output
-      debug: var=showvers.stdout_lines
+      debug: var=showvers.stdout_lines[0]
-- 
GitLab