Use exists filter instead of stat where possible

When checking for the existance of a file on the host where
Ansible is being executed, using the stat module with localhost
delegation is rather heavy-handed. We can instead just make use
of the 'exists' test.

This should improve execution time just a little bit and reduces
the number of tasks for us to maintain. We also remove the
repetition of the task file path by using a variable.

Change-Id: I8b278ca83b2afb07575dbae2496ec265c3a06473
This commit is contained in:
Jesse Pretorius (odyssey4me) 2020-03-11 15:35:14 +00:00
parent 6112a21aa6
commit 9666a7e645
2 changed files with 8 additions and 18 deletions

View File

@ -26,15 +26,10 @@
copy: src=container_puppet_script.yaml dest=/var/lib/container-puppet/container-puppet.sh force=yes mode=0755 setype=container_file_t copy: src=container_puppet_script.yaml dest=/var/lib/container-puppet/container-puppet.sh force=yes mode=0755 setype=container_file_t
{%- for role in roles %} {%- for role in roles %}
- name: Check for {{role.name}}/deploy_steps_tasks_step0.yaml - include_tasks: "{% raw %}{{ _task_file_path }}{% endraw %}"
delegate_to: localhost vars:
run_once: true _task_file_path: "{{role.name}}/deploy_steps_tasks_step0.yaml"
become: false
stat:
path: "{{ '{{' }} playbook_dir ~ '/' ~ '{{role.name}}' ~ '/' ~ 'deploy_steps_tasks_step0.yaml' {{ '}}' }}"
register: tasks_stat
- include_tasks: {{role.name}}/deploy_steps_tasks_step0.yaml
when: when:
- tripleo_role_name == '{{role.name}}' - tripleo_role_name == '{{role.name}}'
- tasks_stat.stat.exists - "{% raw %}'{{ playbook_dir }}/{{ _task_file_path }}' is exists{% endraw %}"
{%- endfor %} {%- endfor %}

View File

@ -709,17 +709,12 @@ outputs:
debug: debug:
msg: Use --start-at-task 'Deploy step tasks for {{step}}' to resume from this task msg: Use --start-at-task 'Deploy step tasks for {{step}}' to resume from this task
{%- for role in roles %} {%- for role in roles %}
- name: Check for {{role.name}}/deploy_steps_tasks_step{{step}}.yaml - include_tasks: "{% raw %}{{ _task_file_path }}{% endraw %}"
delegate_to: localhost vars:
become: false _task_file_path: "{{role.name}}/deploy_steps_tasks_step{{step}}.yaml"
run_once: true
stat:
path: "{{ '{{' }} playbook_dir ~ '/' ~ '{{role.name}}' ~ '/' ~ 'deploy_steps_tasks_step{{step}}.yaml' {{ '}}' }}"
register: tasks_stat
- include_tasks: {{role.name}}/deploy_steps_tasks_step{{step}}.yaml
when: when:
- tripleo_role_name == '{{role.name}}' - tripleo_role_name == '{{role.name}}'
- tasks_stat.stat.exists - "{% raw %}'{{ playbook_dir }}/{{ _task_file_path }}' is exists{% endraw %}"
{%- endfor %} {%- endfor %}
tags: tags:
- overcloud - overcloud