From 722d535cc968b9d2b9caf2de72284fd8aba99abb Mon Sep 17 00:00:00 2001
From: Aleksandr Kurbatov <aleksandr.kurbatov@GL1342.local>
Date: Thu, 7 Mar 2024 15:26:50 +0000
Subject: [PATCH] compile_template: cleanup

---
 .../iptrunk_migration/tasks/compile_template.yaml   | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

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 994d83e8..0d645ce6 100644
--- a/geant/gap_ansible/roles/iptrunk_migration/tasks/compile_template.yaml
+++ b/geant/gap_ansible/roles/iptrunk_migration/tasks/compile_template.yaml
@@ -20,7 +20,17 @@
     mode: '0755'
   delegate_to: localhost
 
-- name: Print the template in "/var/tmp/ansible_run_{{ opid }}/{{ config_object }}.conf"
+- name: Print template for the old node "{{ old_node_fqdn }}" in "/var/tmp/ansible_run_{{ opid }}/{{ config_object }}.conf"
+  ansible.builtin.template:
+    src: "{{ old_node_vendor }}/{{ config_object }}.j2"
+    dest: "/var/tmp/ansible_run_{{ opid }}/{{ 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"
   ansible.builtin.template:
     src: "{{ new_node.router.vendor }}/{{ config_object }}.j2"
     dest: "/var/tmp/ansible_run_{{ opid }}/{{ config_object }}.conf"
@@ -28,6 +38,7 @@
     trim_blocks: true
     mode: '0755'
   delegate_to: localhost
+  when: (verb == "deploy") and inventory_hostname == new_node.router.router_fqdn
 
 - name: Set netconf connection for trunk nodes
   ansible.builtin.include_tasks: set_netconf_connection.yaml
-- 
GitLab