From 0a5662aa9f0b6e1cadf327db7263e6fa5f20ea1b Mon Sep 17 00:00:00 2001 From: Milos Zdravkovic <zmilos85@gmail.com> Date: Tue, 12 Nov 2024 17:22:19 +0100 Subject: [PATCH] Replace import with include/block --- .../tasks/assemble_config.yml | 75 ++++++++++--------- .../deploy_service_config/tasks/main.yml | 6 +- 2 files changed, 42 insertions(+), 39 deletions(-) diff --git a/geant/gap_ansible/roles/deploy_service_config/tasks/assemble_config.yml b/geant/gap_ansible/roles/deploy_service_config/tasks/assemble_config.yml index 4105b214..4196066d 100644 --- a/geant/gap_ansible/roles/deploy_service_config/tasks/assemble_config.yml +++ b/geant/gap_ansible/roles/deploy_service_config/tasks/assemble_config.yml @@ -5,42 +5,45 @@ # playbook in order to introduce the opid_dir variable # and avoid it's use all over the place. -# Because ansible.builtin.assemble works with a single directory -- name: Create a subdirectory for the assembled output - ansible.builtin.file: - path: "/var/tmp/ansible_run_{{ opid }}/assembled/" - state: directory - mode: '0755' +- name: Locally-delegated assemble block + delegate_to: localhost + block: + # Because ansible.builtin.assemble works with a single directory + - name: Create a subdirectory for the assembled output + ansible.builtin.file: + path: "/var/tmp/ansible_run_{{ opid }}/assembled/" + state: directory + mode: '0755' + + # Enumeration prefix is needed to impact the order of assembly + - name: Copy Nokia SR OS header for assembly + ansible.builtin.copy: + src: "{{ vendor }}/header" + dest: "/var/tmp/ansible_run_{{ opid }}/assembled/00_header" -# Enumeration prefix is needed to impact the order of assembly -- name: Copy Nokia SR OS header for assembly - ansible.builtin.copy: - src: "{{ vendor }}/header" - dest: "/var/tmp/ansible_run_{{ opid }}/assembled/00_header" - -# Enumeration prefix is needed to impact the order of assembly -- name: Copy Nokia SR OS footer for assembly - ansible.builtin.copy: - src: "{{ vendor }}/footer" - dest: "/var/tmp/ansible_run_{{ opid }}/assembled/02_footer" - -# Enumeration prefix is needed to impact the order of assembly -- name: Assemble body of the config - ansible.builtin.assemble: - src: "/var/tmp/ansible_run_{{ opid }}/" - dest: "/var/tmp/ansible_run_{{ opid }}/assembled/01-body" - -# Use the enumeration prefixes to assemble fragments in the right order -- name: Merge header, body and footer to get the final config - ansible.builtin.assemble: - src: "/var/tmp/ansible_run_{{ opid }}/assembled" - dest: "/var/tmp/ansible_run_{{ opid }}/assembled/for_deployment" - -- name: Clean up the fragments - ansible.builtin.file: - path: "{{ item }}" - state: absent - mode: '0755' - with_fileglob: + # Enumeration prefix is needed to impact the order of assembly + - name: Copy Nokia SR OS footer for assembly + ansible.builtin.copy: + src: "{{ vendor }}/footer" + dest: "/var/tmp/ansible_run_{{ opid }}/assembled/02_footer" + + # Enumeration prefix is needed to impact the order of assembly + - name: Assemble body of the config + ansible.builtin.assemble: + src: "/var/tmp/ansible_run_{{ opid }}/" + dest: "/var/tmp/ansible_run_{{ opid }}/assembled/01-body" + + # Use the enumeration prefixes to assemble fragments in the right order + - name: Merge header, body and footer to get the final config + ansible.builtin.assemble: + src: "/var/tmp/ansible_run_{{ opid }}/assembled" + dest: "/var/tmp/ansible_run_{{ opid }}/assembled/for_deployment" + + - name: Clean up the fragments + ansible.builtin.file: + path: "{{ item }}" + state: absent + mode: '0755' + with_fileglob: - "/var/tmp/ansible_run_{{ opid }}/assembled/0*" diff --git a/geant/gap_ansible/roles/deploy_service_config/tasks/main.yml b/geant/gap_ansible/roles/deploy_service_config/tasks/main.yml index 3de81268..0a7d3377 100644 --- a/geant/gap_ansible/roles/deploy_service_config/tasks/main.yml +++ b/geant/gap_ansible/roles/deploy_service_config/tasks/main.yml @@ -3,10 +3,10 @@ - name: Fetch access port info from the subscription ansible.builtin.include_tasks: traverse_subscription.yml -# The "delegate_to" works as expected in conjuction with "import_tasks" +# The "delegate_to" works as expected in conjuction with "import_tasks". +# However, mixing "imports" with "includes" is not recommended. - name: Assemble the config from fragments in previous roles - ansible.builtin.import_tasks: assemble_config.yml - delegate_to: localhost + ansible.builtin.include_tasks: assemble_config.yml - name: Include set connection tasks ansible.builtin.include_tasks: connection_tasks.yml -- GitLab