From 923948100e5e94a96798759d6f832779bf47e6ad Mon Sep 17 00:00:00 2001
From: Aleksandr Kurbatov <ak@geant.org>
Date: Mon, 11 Nov 2024 10:39:43 +0000
Subject: [PATCH] Change ansible_connection in base_config

---
 .../tasks/compile_base_config.yaml            |  2 +-
 .../roles/base_config/tasks/main.yml          | 43 ++++++++-----------
 2 files changed, 18 insertions(+), 27 deletions(-)

diff --git a/geant/gap_ansible/roles/base_config/tasks/compile_base_config.yaml b/geant/gap_ansible/roles/base_config/tasks/compile_base_config.yaml
index 0b75d6be..fd129021 100644
--- a/geant/gap_ansible/roles/base_config/tasks/compile_base_config.yaml
+++ b/geant/gap_ansible/roles/base_config/tasks/compile_base_config.yaml
@@ -35,6 +35,6 @@
 - name: Set back ansible_host to target terminal server
   ansible.builtin.set_fact:
     ansible_host: "{{ wfo_router.router.router_site.site_ts_address }}"
-    ansible_connection: netconf
+    ansible_connection: "{{ netconf_access[wfo_router.router.vendor].ansible_connection }}"
   when:
     ( wfo_router.router.router_access_via_ts | ansible.builtin.bool ) is true
diff --git a/geant/gap_ansible/roles/base_config/tasks/main.yml b/geant/gap_ansible/roles/base_config/tasks/main.yml
index 35d3b0e1..e44b00d6 100644
--- a/geant/gap_ansible/roles/base_config/tasks/main.yml
+++ b/geant/gap_ansible/roles/base_config/tasks/main.yml
@@ -6,31 +6,29 @@
       - "Allowed verbs: 'compile' and 'deploy'. Use: -e 'verb=$verb'."
   when: (verb is not defined) or (verb not in verbs)
 
+- name: Fail if arguments are missing
+  ansible.legacy.meta: end_play
+  when: (verb is not defined) or (verb not in verbs)
+
+- name: Import routers variables
+  ansible.builtin.include_vars:
+    dir: /opt/ansible_inventory/group_vars/routers
+
+- name: Import variables from 'all'
+  ansible.builtin.include_vars:
+    dir: /opt/ansible_inventory/group_vars/all
+
 - name: Set ansible_host to terminal server when router is offline
-  ansible.legacy.set_fact:
+  ansible.builtin.set_fact:
     ansible_host: "{{ wfo_router.router.router_site.site_ts_address }}"
     ansible_port: "{{ wfo_router.router.router_ts_port }}"
   when:
     ( wfo_router.router.router_access_via_ts | ansible.builtin.bool ) is true
 
-# FIX: Load these vars via group_vars
 - name: Set variable to connect to nokia
-  ansible.legacy.set_fact:
-    ansible_network_os: geant.gap_ansible.sros
-    ansible_connection: netconf
-  when:
-    wfo_router.router.vendor == "nokia"
-
-- name: Set variables for connecting to Junos
-  ansible.legacy.set_fact:
-    ansible_network_os: junos
-    ansible_connection: netconf
-  when:
-    wfo_router.router.vendor == "juniper"
-
-- name: Fail if arguments are missing
-  ansible.legacy.meta: end_play
-  when: (verb is not defined) or (verb not in verbs)
+  ansible.builtin.set_fact:
+    ansible_connection: "{{ netconf_access[wfo_router.router.vendor].ansible_connection }}"
+    ansible_network_os: "{{ netconf_access[wfo_router.router.vendor].ansible_network_os }}"
 
 # FIX: this does not work with ncclient 0.6.15
 # NOTE: `gather_subset: all` breaks. Workaround to use `min`.
@@ -41,16 +39,9 @@
   when:
     wfo_router.router.vendor == "juniper"
 
-- name: Import routers variables
-  ansible.builtin.include_vars:
-    dir: /opt/ansible_inventory/group_vars/routers
-
-- name: Import variables from 'all'
-  ansible.builtin.include_vars:
-    dir: /opt/ansible_inventory/group_vars/all
 
 - name: Generate an ID for this run
-  ansible.legacy.set_fact:
+  ansible.builtin.set_fact:
     opid: "{{ lookup('community.general.random_string', length=18, special=false) }}"
     config_is_different: "False"
 
-- 
GitLab