Browse Source

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
(cherry picked from commit 1602d68daa)
changes/10/706610/2
James Slagle 4 weeks ago
parent
commit
7683b8bcaa
3 changed files with 51 additions and 47 deletions
  1. +2
    -47
      common/deploy-steps-tasks.yaml
  2. +1
    -0
      common/deploy-steps.j2
  3. +48
    -0
      common/host-container-puppet-tasks.yaml

+ 2
- 47
common/deploy-steps-tasks.yaml View File

@@ -234,53 +234,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}}'
- name: Include container-puppet tasks for step {{step}}
include_tasks: host-container-puppet-tasks.yaml
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
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

+ 1
- 0
common/deploy-steps.j2 View File

@@ -399,6 +399,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:

+ 48
- 0
common/host-container-puppet-tasks.yaml View File

@@ -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

Loading…
Cancel
Save