From ac2f824f2d98844a82d45c6119abe69cf26c5adb Mon Sep 17 00:00:00 2001
From: Aleksandr Kurbatov <ak@geant.org>
Date: Sat, 26 Apr 2025 14:46:01 +0100
Subject: [PATCH] `iptrunk_migration` - update to use the new storage path

---
 .../iptrunk_migration/tasks/bfd_update.yaml   |  4 ++--
 .../tasks/compile_template.yaml               | 19 ++++++-------------
 .../tasks/configure_storage.yaml              |  1 +
 .../tasks/deactivate_trunk_side.yaml          |  4 ++--
 .../tasks/delete_trunk_side.yaml              |  4 ++--
 .../tasks/deploy_object.yaml                  |  4 ++--
 .../roles/iptrunk_migration/tasks/main.yml    | 12 +++---------
 7 files changed, 18 insertions(+), 30 deletions(-)
 create mode 120000 geant/gap_ansible/roles/iptrunk_migration/tasks/configure_storage.yaml

diff --git a/geant/gap_ansible/roles/iptrunk_migration/tasks/bfd_update.yaml b/geant/gap_ansible/roles/iptrunk_migration/tasks/bfd_update.yaml
index 74842b76..10e8292a 100644
--- a/geant/gap_ansible/roles/iptrunk_migration/tasks/bfd_update.yaml
+++ b/geant/gap_ansible/roles/iptrunk_migration/tasks/bfd_update.yaml
@@ -8,7 +8,7 @@
     dry_run | ansible.builtin.bool
   junipernetworks.junos.junos_config:
     update: 'replace'
-    src: "/var/tmp/ansible_run_{{ opid }}/{{ config_object }}.conf"
+    src: "{{ play_storage_path }}/{{ config_object }}.conf"
     src_format: set
     check_commit: true
   diff: true
@@ -22,7 +22,7 @@
     not (dry_run | ansible.builtin.bool)
   junipernetworks.junos.junos_config:
     update: 'replace'
-    src: "/var/tmp/ansible_run_{{ opid }}/{{ config_object }}.conf"
+    src: "{{ play_storage_path }}/{{ config_object }}.conf"
     src_format: set
     comment: "{{ commit_comment }}"
   diff: true
diff --git a/geant/gap_ansible/roles/iptrunk_migration/tasks/compile_template.yaml b/geant/gap_ansible/roles/iptrunk_migration/tasks/compile_template.yaml
index 80e59fe7..89d9c063 100644
--- a/geant/gap_ansible/roles/iptrunk_migration/tasks/compile_template.yaml
+++ b/geant/gap_ansible/roles/iptrunk_migration/tasks/compile_template.yaml
@@ -13,37 +13,30 @@
     ( new_node.router.router_access_via_ts | ansible.builtin.bool ) is true and
     (verb == "deploy")
 
-- name: Create a folder for all the templates
-  ansible.builtin.file:
-    path: "/var/tmp/ansible_run_{{ opid }}"
-    state: directory
-    mode: '0755'
-  delegate_to: localhost
-
-- name: Print template for the old node "{{ old_node.fqdn }}" in "/var/tmp/ansible_run_{{ opid }}/{{ config_object }}.conf"
+- name: Print template for the old node "{{ old_node.fqdn }}" in "{{ play_storage_path }}/{{ config_object }}.conf"
   ansible.builtin.template:
     src: "{{ old_node.vendor }}/{{ config_object }}.j2"
-    dest: "/var/tmp/ansible_run_{{ opid }}/{{ config_object }}.conf"
+    dest: "{{ play_storage_path }}/{{ config_object }}.conf"
     lstrip_blocks: true
     trim_blocks: true
     mode: '0755'
   delegate_to: localhost
   when: (verb == "delete" or verb == "deactivate") and inventory_hostname != new_node.router.router_fqdn
 
-- name: Print template for the new node in "/var/tmp/ansible_run_{{ opid }}/{{ config_object }}.conf"
+- name: Print template for the new node in "{{ play_storage_path }}/{{ config_object }}.conf"
   ansible.builtin.template:
     src: "{{ new_node.router.vendor }}/{{ config_object }}.j2"
-    dest: "/var/tmp/ansible_run_{{ opid }}/{{ config_object }}.conf"
+    dest: "{{ play_storage_path }}/{{ config_object }}.conf"
     lstrip_blocks: true
     trim_blocks: true
     mode: '0755'
   delegate_to: localhost
   when: (verb == "deploy") and inventory_hostname == new_node.router.router_fqdn
 
-- name: Print template for the remaining node in "/var/tmp/ansible_run_{{ opid }}/{{ config_object }}.conf"
+- name: Print template for the remaining node in "{{ play_storage_path }}/{{ config_object }}.conf"
   ansible.builtin.template:
     src: "{{ remaining_side.vendor }}/{{ config_object }}.j2"
-    dest: "/var/tmp/ansible_run_{{ opid }}/{{ config_object }}.conf"
+    dest: "{{ play_storage_path }}/{{ config_object }}.conf"
     lstrip_blocks: true
     trim_blocks: true
     mode: '0755'
diff --git a/geant/gap_ansible/roles/iptrunk_migration/tasks/configure_storage.yaml b/geant/gap_ansible/roles/iptrunk_migration/tasks/configure_storage.yaml
new file mode 120000
index 00000000..67d67dcb
--- /dev/null
+++ b/geant/gap_ansible/roles/iptrunk_migration/tasks/configure_storage.yaml
@@ -0,0 +1 @@
+../../../playbooks/configure_storage.yaml
\ No newline at end of file
diff --git a/geant/gap_ansible/roles/iptrunk_migration/tasks/deactivate_trunk_side.yaml b/geant/gap_ansible/roles/iptrunk_migration/tasks/deactivate_trunk_side.yaml
index 2eb8ec6c..46e618bc 100644
--- a/geant/gap_ansible/roles/iptrunk_migration/tasks/deactivate_trunk_side.yaml
+++ b/geant/gap_ansible/roles/iptrunk_migration/tasks/deactivate_trunk_side.yaml
@@ -8,7 +8,7 @@
     dry_run | ansible.builtin.bool
   junipernetworks.junos.junos_config:
     update: 'replace'
-    src: "/var/tmp/ansible_run_{{ opid }}/{{ config_object }}.conf"
+    src: "{{ play_storage_path }}/{{ config_object }}.conf"
     src_format: set
     check_commit: true
   diff: true
@@ -22,7 +22,7 @@
     not (dry_run | ansible.builtin.bool)
   junipernetworks.junos.junos_config:
     update: 'replace'
-    src: "/var/tmp/ansible_run_{{ opid }}/{{ config_object }}.conf"
+    src: "{{ play_storage_path }}/{{ config_object }}.conf"
     src_format: set
     comment: "{{ commit_comment }}"
   diff: true
diff --git a/geant/gap_ansible/roles/iptrunk_migration/tasks/delete_trunk_side.yaml b/geant/gap_ansible/roles/iptrunk_migration/tasks/delete_trunk_side.yaml
index ec7b2da4..af48e736 100644
--- a/geant/gap_ansible/roles/iptrunk_migration/tasks/delete_trunk_side.yaml
+++ b/geant/gap_ansible/roles/iptrunk_migration/tasks/delete_trunk_side.yaml
@@ -2,7 +2,7 @@
 - name: Delete Trunk interface on  "{{ inventory_hostname }}" [CHECK ONLY][JUNIPER]
   junipernetworks.junos.junos_config:
     update: 'replace'
-    src: "/var/tmp/ansible_run_{{ opid }}/{{ config_object }}.conf"
+    src: "{{ play_storage_path }}/{{ config_object }}.conf"
     src_format: set
     check_commit: true
   diff: true
@@ -14,7 +14,7 @@
 - name: Delete Trunk interface on "{{ inventory_hostname }}" [AND COMMIT][JUNIPER]
   junipernetworks.junos.junos_config:
     update: 'replace'
-    src: "/var/tmp/ansible_run_{{ opid }}/{{ config_object }}.conf"
+    src: "{{ play_storage_path }}/{{ config_object }}.conf"
     src_format: set
     comment: "{{ commit_comment }}"
   diff: true
diff --git a/geant/gap_ansible/roles/iptrunk_migration/tasks/deploy_object.yaml b/geant/gap_ansible/roles/iptrunk_migration/tasks/deploy_object.yaml
index e9fd1683..0eb19691 100644
--- a/geant/gap_ansible/roles/iptrunk_migration/tasks/deploy_object.yaml
+++ b/geant/gap_ansible/roles/iptrunk_migration/tasks/deploy_object.yaml
@@ -2,7 +2,7 @@
 - name: Deploy "{{ config_object }}" on  "{{ inventory_hostname }}" [CHECK ONLY][JUNIPER]
   junipernetworks.junos.junos_config:
     update: 'replace'
-    src: "/var/tmp/ansible_run_{{ opid }}/{{ config_object }}.conf"
+    src: "{{ play_storage_path }}/{{ config_object }}.conf"
     src_format: set
     check_commit: true
   diff: true
@@ -14,7 +14,7 @@
 - name: Deploy "{{ config_object }}" on "{{ inventory_hostname }}" [AND COMMIT][JUNIPER]
   junipernetworks.junos.junos_config:
     update: 'replace'
-    src: "/var/tmp/ansible_run_{{ opid }}/{{ config_object }}.conf"
+    src: "{{ play_storage_path }}/{{ config_object }}.conf"
     src_format: set
     comment: "{{ commit_comment }}"
   diff: true
diff --git a/geant/gap_ansible/roles/iptrunk_migration/tasks/main.yml b/geant/gap_ansible/roles/iptrunk_migration/tasks/main.yml
index 92983df4..6b475754 100644
--- a/geant/gap_ansible/roles/iptrunk_migration/tasks/main.yml
+++ b/geant/gap_ansible/roles/iptrunk_migration/tasks/main.yml
@@ -20,11 +20,6 @@
   ansible.builtin.include_vars:
     dir: /opt/ansible_inventory/group_vars/routers
 
-- name: Set an ID for this run
-  ansible.builtin.set_fact:
-    opid: "{{ lookup('community.general.random_string', length=18, special=false) }}"
-    config_is_different: "False"
-
 - name: The old node is
   ansible.builtin.debug:
     msg: "{{ old_node.fqdn }}"
@@ -33,6 +28,9 @@
   ansible.builtin.debug:
     msg: "{{ new_node.router.router_fqdn }}"
 
+- name: Include configure storage tasks
+  ansible.builtin.include_tasks: configure_storage.yaml
+
 - name: Select the correct IPaddresses
   ansible.builtin.include_tasks: calculate_ips.yaml
   when: verb == "deploy"
@@ -60,10 +58,6 @@
   when:
     verb == "deploy"
 
-- name: Print the ID
-  ansible.builtin.debug:
-    msg: "{{ opid }}"
-
 - name: Include compiling the template for the old node
   ansible.builtin.include_tasks: compile_template.yaml
   when: (verb == "deactivate" or verb == "delete")
-- 
GitLab