Convert with_dict tasks to use loop and be less chatty

with_dict is replaced by ansible's loop:
https://docs.ansible.com/ansible/latest/user_guide/playbooks_loops.html#with-dict

This migrates tasks using with_dict over to use loop instead.

Additionally, when using loop (or with_dict), the entire loop item is
logged by default. This makes these tasks very verbose since we're
looping over large json/yaml files. Instead, use loop_control and label
ot only log the item key. The entire data structure already exists in
the config-download directory anyway, so there's no need to log the
whole thing to the console.

Change-Id: I1fc7431dfc662212b6ca64f4f738760f25b0c30b
This commit is contained in:
James Slagle 2018-09-17 17:26:47 -04:00
parent 1badfc470a
commit 1b0c827930
1 changed files with 23 additions and 15 deletions

View File

@ -71,12 +71,14 @@
- name: Write docker config scripts - name: Write docker config scripts
copy: copy:
content: "{{ item.value.content }}" content: "{{ item[1].content }}"
dest: "/var/lib/docker-config-scripts/{{ item.key }}" dest: "/var/lib/docker-config-scripts/{{ item[0] }}"
force: yes force: yes
mode: "{{ item.value.mode | default('0600', true) }}" mode: "{{ item[1].mode | default('0600', true) }}"
setype: svirt_sandbox_file_t setype: svirt_sandbox_file_t
with_dict: "{{ role_data_docker_config_scripts }}" loop: "{{ role_data_docker_config_scripts | dictsort }}"
loop_control:
label: "{{ item[0] }}"
vars: vars:
role_data_docker_config_scripts: "{{ lookup('file', tripleo_role_name + '/docker_config_scripts.yaml', errors='ignore') | default({}, True) | from_yaml }}" role_data_docker_config_scripts: "{{ lookup('file', tripleo_role_name + '/docker_config_scripts.yaml', errors='ignore') | default({}, True) | from_yaml }}"
tags: tags:
@ -116,11 +118,13 @@
- name: Write per-step docker-container-startup-configs - name: Write per-step docker-container-startup-configs
copy: copy:
content: "{{ item.value | to_json }}" content: "{{ item[1] | to_json }}"
dest: "/var/lib/tripleo-config/docker-container-startup-config-{{ item.key }}.json" dest: "/var/lib/tripleo-config/docker-container-startup-config-{{ item[0] }}.json"
force: yes force: yes
mode: '0600' mode: '0600'
with_dict: "{{ docker_config_with_default }}" loop: "{{ docker_config_with_default | dictsort }}"
loop_control:
label: "{{ item[0] }}"
tags: tags:
- container_startup_configs - container_startup_configs
@ -143,12 +147,14 @@
- name: Write kolla config json files - name: Write kolla config json files
copy: copy:
content: "{{ item.value | to_json }}" content: "{{ item[1] | to_json }}"
dest: "{{ item.key }}" dest: "{{ item[0] }}"
force: yes force: yes
mode: '0600' mode: '0600'
setype: svirt_sandbox_file_t setype: svirt_sandbox_file_t
with_dict: "{{ lookup('file', tripleo_role_name + '/kolla_config.yaml', errors='ignore') | default([], True) | from_yaml }}" loop: "{{ lookup('file', tripleo_role_name + '/kolla_config.yaml', errors='ignore') | default([], True) | from_yaml | dictsort }}"
loop_control:
label: "{{ item[0] }}"
tags: tags:
- container_startup_configs - container_startup_configs
@ -168,11 +174,13 @@
- name: Write docker-puppet-tasks json files - name: Write docker-puppet-tasks json files
copy: copy:
content: "{{item.value|to_json}}" content: "{{item[1]|to_json}}"
dest: /var/lib/docker-puppet/docker-puppet-tasks{{item.key.replace("step_", "")}}.json dest: /var/lib/docker-puppet/docker-puppet-tasks{{item[0].replace("step_", "")}}.json
force: yes force: yes
mode: '0600' mode: '0600'
with_dict: "{{ lookup('file', tripleo_role_name + '/docker_puppet_tasks.yaml', errors='ignore') | default({}, True) | from_yaml }}" 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 when: deploy_server_id == bootstrap_server_id
tags: tags:
- container_config_tasks - container_config_tasks