From 87b16ddbfc19263e81bf49a5c643855c98ffb240 Mon Sep 17 00:00:00 2001 From: Steven Hardy Date: Thu, 13 Dec 2018 17:56:44 +0000 Subject: [PATCH] run docker_puppet_tasks on any role Currently this assumes all tasks will run on the primary controller but because of composable roles, that may not be the case. An example is if you deploy keystone on any role other than the role tagged primary e.g Controller by default, we don't create any of the users/endpoints because the tasks aren't written to the role unless keystone actually runs there. Conflicts: common/deploy-steps-tasks.yaml Closes-Bug: #1792613 Change-Id: Ib6efd03584c95ed4ab997f614aa3178b01877b8c (cherry picked from commit a0a09d29aac1ad44fa48dae5d1db72e3905aeb69) --- common/deploy-steps-tasks.yaml | 62 ++++++++++++++-------------------- common/services.yaml | 5 ++- 2 files changed, 30 insertions(+), 37 deletions(-) diff --git a/common/deploy-steps-tasks.yaml b/common/deploy-steps-tasks.yaml index 6a79ebf5b0..e05828c948 100644 --- a/common/deploy-steps-tasks.yaml +++ b/common/deploy-steps-tasks.yaml @@ -3,7 +3,6 @@ ################################################## # Step 1 block, write data for subsequent steps ################################################## - - name: Write config data at the start of step 1 when: step == "1" block: @@ -253,33 +252,6 @@ tags: - container_startup_configs - ######################################################## - # Bootstrap tasks, only performed on bootstrap_server_id - ######################################################## - - - name: Clean /var/lib/docker-puppet/docker-puppet-tasks*.json files - file: - path: "{{ item }}" - state: absent - with_fileglob: - - /var/lib/docker-puppet/docker-puppet-tasks*.json - when: deploy_server_id == bootstrap_server_id - tags: - - container_config_tasks - - - name: Write docker-puppet-tasks json files - copy: - content: "{{item[1]|to_nice_json}}" - dest: /var/lib/docker-puppet/docker-puppet-tasks{{item[0].replace("step_", "")}}.json - force: yes - mode: '0600' - loop: "{{ lookup('file', tripleo_role_name + '/docker_puppet_tasks.yaml', errors='ignore') | default({}, True) | from_yaml | dictsort }}" - loop_control: - label: "{{ item[0] }}" - when: deploy_server_id == bootstrap_server_id - tags: - - container_config_tasks - ##################################################### # Per step puppet configuration of the baremetal host ##################################################### @@ -456,16 +428,36 @@ - container_startup_configs ######################################################## - # Bootstrap tasks, only performed on bootstrap_server_id + # Bootstrap tasks - run any tasks that have been defined ######################################################## - - name: Check if /var/lib/docker-puppet/docker-puppet-tasks{{ step }}.json exists - stat: - path: /var/lib/docker-puppet/{{ ansible_check_mode | ternary('check-mode/', '') }}docker-puppet-tasks{{ step }}.json - register: docker_puppet_tasks_json + - name: "Clean docker_puppet_tasks for {{ansible_hostname}} step {{step}}" + file: + path: /var/lib/docker-puppet/docker-puppet-tasks{{step}}.json + state: absent tags: - container_config_tasks + - name: Calculate docker_puppet_tasks for {{ansible_hostname}} step {{step}} + set_fact: + host_docker_puppet_tasks: "{{host_docker_puppet_tasks|default([]) + [item]}}" + loop: "{{docker_puppet_tasks.get('step_' + step, [])}}" + when: vars[item.service_name + '_short_bootstrap_node_name'] == ansible_hostname + vars: + docker_puppet_tasks: "{{ lookup('file', tripleo_role_name + '/docker_puppet_tasks.yaml', errors='ignore') | default({}, True) | from_yaml }}" + tags: + - container_config_tasks + + - name: Write docker-puppet-tasks json file for {{ansible_hostname}} step {{step}} + copy: + content: "{{host_docker_puppet_tasks|to_nice_json}}" + dest: "/var/lib/docker-puppet/docker-puppet-tasks{{step}}.json" + force: yes + mode: '0600' + tags: + - container_config_tasks + when: host_docker_puppet_tasks is defined + - name: Run docker-puppet tasks (bootstrap tasks) for step {{ step }} shell: python /var/lib/docker-puppet/docker-puppet.py environment: @@ -474,9 +466,7 @@ NET_HOST: "true" NO_ARCHIVE: "true" STEP: "{{ step }}" - when: - - deploy_server_id == bootstrap_server_id - - docker_puppet_tasks_json.stat.exists + when: host_docker_puppet_tasks is defined changed_when: false register: outputs failed_when: false diff --git a/common/services.yaml b/common/services.yaml index 103abb3106..a9eca5ea96 100644 --- a/common/services.yaml +++ b/common/services.yaml @@ -364,7 +364,10 @@ resources: type: json value: yaql: - expression: dict(coalesce($.data, []).where($ != null).select($.get('docker_puppet_tasks')).where($ != null).selectMany($.items()).groupBy($[0], $[1])) + # This extracts docker_puppet_tasks for each step, + # and merges {service_name: the_service} for each item, so we + # can later filter based on the bootstrap hostname for the service + expression: dict(coalesce($.data, []).where($ != null).select([$.get('docker_puppet_tasks'), $.get('service_name')]).where($[0] != null).select([$[0], dict($[0].keys().zip(dict(service_name=>$[1]).repeat(len($[0].keys()))))]).select($[0].mergeWith($[1])).selectMany($.items()).groupBy($[0], $[1])) data: {get_attr: [ServiceChain, role_data]} HostPrepTasks: