From a0a09d29aac1ad44fa48dae5d1db72e3905aeb69 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. Closes-Bug: #1792613 Change-Id: Ib6efd03584c95ed4ab997f614aa3178b01877b8c --- common/deploy-steps-tasks.yaml | 68 +++++++++++++++++----------------- common/services.yaml | 5 ++- 2 files changed, 37 insertions(+), 36 deletions(-) diff --git a/common/deploy-steps-tasks.yaml b/common/deploy-steps-tasks.yaml index 76ca3d9a8f..f3fd6984dc 100644 --- a/common/deploy-steps-tasks.yaml +++ b/common/deploy-steps-tasks.yaml @@ -7,16 +7,23 @@ setup: gather_subset: "!min,python" when: ansible_python is not defined + tags: + - container_config_tasks - name: set python_cmd set_fact: python_cmd: "python{{ ansible_python.version.major }}" cacheable: true when: python_cmd is not defined + tags: + - container_config_tasks + - name: print python facts debug: msg: "python_cmd: {{ python_cmd }}" + tags: + - container_config_tasks - name: Write config data at the start of step 1 when: step == "1" @@ -294,33 +301,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 ##################################################### @@ -500,16 +480,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_cmd }} /var/lib/docker-puppet/docker-puppet.py" environment: @@ -521,9 +521,7 @@ CONTAINER_CLI: "{{ container_cli }}" DEBUG: "{{ docker_puppet_debug }}" MOUNT_HOST_PUPPET: '{{docker_puppet_mount_host_puppet}}' - 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 8abe98123a..fa351bd08f 100644 --- a/common/services.yaml +++ b/common/services.yaml @@ -295,7 +295,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: