From a77d57bf712592cf1a7877009f9a4d5487ea6643 Mon Sep 17 00:00:00 2001
From: Simone Spinelli <simone.spinelli@geant.org>
Date: Mon, 8 Jan 2024 09:59:24 +0100
Subject: [PATCH] Add a role to perform checks after base config

---
 .../playbooks/base_config_checks.yaml         |  0
 .../roles/base_config_checks/README.md        | 38 +++++++++++++++++++
 .../tasks/base_config_single_command.yaml     | 10 +++++
 .../roles/base_config_checks/tasks/main.yml   |  5 +++
 .../templates/base_config_single_command.j2   |  5 +++
 .../roles/base_config_checks/vars/main.yml    | 17 +++++++++
 6 files changed, 75 insertions(+)
 create mode 100644 geant/gap_ansible/playbooks/base_config_checks.yaml
 create mode 100644 geant/gap_ansible/roles/base_config_checks/README.md
 create mode 100644 geant/gap_ansible/roles/base_config_checks/tasks/base_config_single_command.yaml
 create mode 100644 geant/gap_ansible/roles/base_config_checks/tasks/main.yml
 create mode 100644 geant/gap_ansible/roles/base_config_checks/templates/base_config_single_command.j2
 create mode 100644 geant/gap_ansible/roles/base_config_checks/vars/main.yml

diff --git a/geant/gap_ansible/playbooks/base_config_checks.yaml b/geant/gap_ansible/playbooks/base_config_checks.yaml
new file mode 100644
index 00000000..e69de29b
diff --git a/geant/gap_ansible/roles/base_config_checks/README.md b/geant/gap_ansible/roles/base_config_checks/README.md
new file mode 100644
index 00000000..225dd44b
--- /dev/null
+++ b/geant/gap_ansible/roles/base_config_checks/README.md
@@ -0,0 +1,38 @@
+Role Name
+=========
+
+A brief description of the role goes here.
+
+Requirements
+------------
+
+Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.
+
+Role Variables
+--------------
+
+A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.
+
+Dependencies
+------------
+
+A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.
+
+Example Playbook
+----------------
+
+Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
+
+    - hosts: servers
+      roles:
+         - { role: username.rolename, x: 42 }
+
+License
+-------
+
+BSD
+
+Author Information
+------------------
+
+An optional section for the role authors to include contact information, or a website (HTML is not allowed).
diff --git a/geant/gap_ansible/roles/base_config_checks/tasks/base_config_single_command.yaml b/geant/gap_ansible/roles/base_config_checks/tasks/base_config_single_command.yaml
new file mode 100644
index 00000000..8552009d
--- /dev/null
+++ b/geant/gap_ansible/roles/base_config_checks/tasks/base_config_single_command.yaml
@@ -0,0 +1,10 @@
+- name: "Execute {{item.command}}"
+  ansible.netcommon.netconf_rpc:
+    rpc: action
+    xmlns: "urn:ietf:params:xml:ns:yang:1"
+    content: "{{ lookup('ansible.builtin.template', './base_config_single_command.j2') }}"
+    display: json
+  register: out
+- name: "Results of {{item.command}}"
+  debug:
+    msg: "{{out.output['rpc-reply']['nokiaoper:results']['nokiaoper:md-cli-output-block'].split('\n')}}"
diff --git a/geant/gap_ansible/roles/base_config_checks/tasks/main.yml b/geant/gap_ansible/roles/base_config_checks/tasks/main.yml
new file mode 100644
index 00000000..122da68e
--- /dev/null
+++ b/geant/gap_ansible/roles/base_config_checks/tasks/main.yml
@@ -0,0 +1,5 @@
+---
+# tasks file for base_config_checks
+- name: Execute post-check command
+  include_tasks: base_config_single_command.yaml
+  with_items: "{{commands}}"
diff --git a/geant/gap_ansible/roles/base_config_checks/templates/base_config_single_command.j2 b/geant/gap_ansible/roles/base_config_checks/templates/base_config_single_command.j2
new file mode 100644
index 00000000..9c358cf0
--- /dev/null
+++ b/geant/gap_ansible/roles/base_config_checks/templates/base_config_single_command.j2
@@ -0,0 +1,5 @@
+<global-operations xmlns="urn:nokia.com:sros:ns:yang:sr:oper-global">
+   <md-cli-raw-command>
+     <md-cli-input-line>{{item.command}}</md-cli-input-line>
+   </md-cli-raw-command>
+</global-operations>
diff --git a/geant/gap_ansible/roles/base_config_checks/vars/main.yml b/geant/gap_ansible/roles/base_config_checks/vars/main.yml
new file mode 100644
index 00000000..335e8e41
--- /dev/null
+++ b/geant/gap_ansible/roles/base_config_checks/vars/main.yml
@@ -0,0 +1,17 @@
+---
+# vars file for base_config_checks
+commands:
+- command: show version
+  description: "Shows the version of SROS"
+- command: show chassis
+  description: "Shows the status of the chassis"
+- command: show card
+  description: "Shows the status of the cards"
+- command: show port
+  description: "Shows the status of the ports"
+- command: show mda
+  description: "Shows the status of the mdas"
+- command: show sfm
+  description: "Shows the status of Switching Fabric Modules"
+- command: show redundancy synchronization
+  description: "Shows the status of the syncronization"
-- 
GitLab