From 1602d68daabecb420efa43188fc517257aa85e0a Mon Sep 17 00:00:00 2001 From: James Slagle Date: Wed, 22 Jan 2020 14:11:33 -0500 Subject: [PATCH] Dynamically include container-puppet tasks The container-puppet tasks only need to be run if tasks actually exist, which is already being checked on the ansible control node. A "when" statement is then applied to the set of tasks necessary to run the container-puppet tasks, when the tasks are actually defined. This patch moves that set of tasks to a separate tasks file and uses a dynamic include. This results in less tasks being skipped, which can save several minutes at scale. This results in 3 less tasks that need to be skipped at steps 1-5, which equates to 15 tasks overall, when no container-puppet tasks actually exist. When container-puppet tasks do exist, all the tasks will be executed as necessary. Change-Id: Ifad32bf79942cde58295fd9aae7e23e2f62c1ae2 --- common/deploy-steps-tasks.yaml | 51 +------------------------ common/deploy-steps.j2 | 1 + common/host-container-puppet-tasks.yaml | 48 +++++++++++++++++++++++ 3 files changed, 51 insertions(+), 49 deletions(-) create mode 100644 common/host-container-puppet-tasks.yaml diff --git a/common/deploy-steps-tasks.yaml b/common/deploy-steps-tasks.yaml index 1553f4f257..836ba98596 100644 --- a/common/deploy-steps-tasks.yaml +++ b/common/deploy-steps-tasks.yaml @@ -172,55 +172,8 @@ tags: - container_config_tasks - - name: Write container-puppet-tasks json file for {{ansible_hostname}} step {{step}} - no_log: True - copy: - content: "{{host_container_puppet_tasks|to_nice_json}}" - dest: "/var/lib/container-puppet/container-puppet-tasks{{step}}.json" - force: yes - mode: '0600' - tags: - - container_config_tasks - when: host_container_puppet_tasks is defined - - - name: Run container-puppet tasks (bootstrap tasks) for step {{ step }} - async: 3600 - poll: 0 - shell: "{{ python_cmd }} /var/lib/container-puppet/container-puppet.py" - environment: - CONFIG: /var/lib/container-puppet/{{ ansible_check_mode | bool | ternary('check-mode/', '') }}container-puppet-tasks{{ step }}.json - CONFIG_VOLUME_PREFIX: '/var/lib/config-data{{ ansible_check_mode | bool | ternary("/check-mode", "") }}' - NET_HOST: "true" - NO_ARCHIVE: "true" - STEP: "{{ step }}" - CONTAINER_CLI: "{{ container_cli }}" - DEBUG: "{{ docker_puppet_debug }}" - MOUNT_HOST_PUPPET: '{{docker_puppet_mount_host_puppet}}' - SHORT_HOSTNAME: "{{ ansible_hostname }}" - PROCESS_COUNT: "{{ docker_puppet_process_count }}" - when: host_container_puppet_tasks is defined - register: bootstrap_tasks_async_result - no_log: true - tags: - - container_config_tasks - - - name: Wait for container-puppet tasks (bootstrap tasks) for step {{ step }} to finish - async_status: - jid: "{{ bootstrap_tasks_async_result.ansible_job_id }}" - register: bootstrap_tasks_outputs - until: bootstrap_tasks_outputs.finished - retries: 1200 - delay: 3 + - name: Include container-puppet tasks for step {{step}} + include_tasks: host-container-puppet-tasks.yaml when: host_container_puppet_tasks is defined tags: - container_config_tasks - - - name: "Debug output for task: Run container-puppet tasks (bootstrap tasks) for step {{ step }}" - debug: - var: bootstrap_tasks_outputs.stdout_lines | default([]) | union(bootstrap_tasks_outputs.stderr_lines | default([])) - when: - - host_container_puppet_tasks is defined - - bootstrap_tasks_outputs.rc is defined - failed_when: bootstrap_tasks_outputs.rc != 0 - tags: - - container_config_tasks diff --git a/common/deploy-steps.j2 b/common/deploy-steps.j2 index 1b05a4a2a7..2ea0aa911e 100644 --- a/common/deploy-steps.j2 +++ b/common/deploy-steps.j2 @@ -404,6 +404,7 @@ outputs: deploy-artifacts.sh : {get_file: ../puppet/deploy-artifacts.sh} hosts-config.sh: {get_file: ../scripts/hosts-config.sh} generate-config-tasks: {get_file: generate-config-tasks.yaml} + host-container-puppet-tasks: {get_file: host-container-puppet-tasks.yaml} deploy_steps_playbook: str_replace: params: diff --git a/common/host-container-puppet-tasks.yaml b/common/host-container-puppet-tasks.yaml new file mode 100644 index 0000000000..9eed67c2dd --- /dev/null +++ b/common/host-container-puppet-tasks.yaml @@ -0,0 +1,48 @@ +- name: Write container-puppet-tasks json file for {{ansible_hostname}} step {{step}} + no_log: True + copy: + content: "{{host_container_puppet_tasks|to_nice_json}}" + dest: "/var/lib/container-puppet/container-puppet-tasks{{step}}.json" + force: yes + mode: '0600' + tags: + - container_config_tasks + +- name: Run container-puppet tasks (bootstrap tasks) for step {{ step }} + async: 3600 + poll: 0 + shell: "{{ python_cmd }} /var/lib/container-puppet/container-puppet.py" + environment: + CONFIG: /var/lib/container-puppet/{{ ansible_check_mode | bool | ternary('check-mode/', '') }}container-puppet-tasks{{ step }}.json + CONFIG_VOLUME_PREFIX: '/var/lib/config-data{{ ansible_check_mode | bool | ternary("/check-mode", "") }}' + NET_HOST: "true" + NO_ARCHIVE: "true" + STEP: "{{ step }}" + CONTAINER_CLI: "{{ container_cli }}" + DEBUG: "{{ docker_puppet_debug }}" + MOUNT_HOST_PUPPET: '{{docker_puppet_mount_host_puppet}}' + SHORT_HOSTNAME: "{{ ansible_hostname }}" + PROCESS_COUNT: "{{ docker_puppet_process_count }}" + register: bootstrap_tasks_async_result + no_log: true + tags: + - container_config_tasks + +- name: Wait for container-puppet tasks (bootstrap tasks) for step {{ step }} to finish + async_status: + jid: "{{ bootstrap_tasks_async_result.ansible_job_id }}" + register: bootstrap_tasks_outputs + until: bootstrap_tasks_outputs.finished + retries: 1200 + delay: 3 + tags: + - container_config_tasks + +- name: "Debug output for task: Run container-puppet tasks (bootstrap tasks) for step {{ step }}" + debug: + var: bootstrap_tasks_outputs.stdout_lines | default([]) | union(bootstrap_tasks_outputs.stderr_lines | default([])) + when: + - bootstrap_tasks_outputs.rc is defined + failed_when: bootstrap_tasks_outputs.rc != 0 + tags: + - container_config_tasks