- include_vars:
      file: "{{ templates_list_file}}"
      name: current_file

- name: find the template file or corresponding j2 template
  find:
      path: "{{ item| dirname }}"
      pattern: "{{ item|basename|splitext|first }}\\.(?:yaml|j2\\.yaml)$"
      use_regex: yes
  with_items: "{{ current_file.tripleo_heat_templates | default([]) }}"
  register: default_templates

- name: fail because file not found
  vars:
      missing_templates: "{{ default_templates.results|rejectattr('matched')|map(attribute='item')|list }}"
  fail:
      msg:
          error: "Unable to locate templates from file '{{ templates_list_file }}'"
          source_file: "{{ templates_list_file }}"
          missing_templates: "{{ missing_templates }}"
  when: missing_templates | default([])

- name: generate docker images file for services not enabled by default (if any)
  vars:
      env_file_nondefault: "{{ template_base }}/docker-images-nondefault-{{ item.item|basename|splitext|list|first }}.yaml"
  shell: |
      openstack overcloud container image prepare \
          --namespace={{ container_env['container-image-prepare']['namespace'] }} \
          --env-file={{ env_file_nondefault }} \
          --prefix={{ container_env['container-image-prepare']['prefix'] }} \
          --suffix={{ container_env['container-image-prepare']['suffix'] }} \
          --tag={{ container_env['container-image-prepare']['tag'] }} \
          --service-environment-file {{ item.item }}
  with_items: "{{ default_templates.results }}"

- include_vars:
      file: "{{ templates_list_file}}"
      name: current_file

- name: find the template file or corresponding j2 template
  find:
      path: "{{ item| dirname }}"
      pattern: "{{ item|basename|splitext|first }}\\.(?:yaml|j2\\.yaml)$"
      use_regex: yes
  with_items: "{{ current_file.tripleo_heat_templates | default([]) }}"
  register: default_templates

- name: fail because file not found
  vars:
      missing_templates: "{{ default_templates.results|rejectattr('matched')|map(attribute='item')|list }}"
  fail:
      msg:
          error: "Unable to locate templates from file '{{ templates_list_file }}'"
          source_file: "{{ templates_list_file }}"
          missing_templates: "{{ missing_templates }}"
  when: missing_templates | default([])

- name: generate docker images file for services not enabled by default (if any)
  vars:
      env_file_nondefault: "{{ template_base }}/docker-images-nondefault-{{ item.item|basename|splitext|list|first }}.yaml"
  shell: |
      openstack overcloud container image prepare \
          --namespace={{ container_env['container-image-prepare']['namespace'] }} \
          --env-file={{ env_file_nondefault }} \
          --prefix={{ container_env['container-image-prepare']['prefix']|default('') }} \
          --suffix={{ container_env['container-image-prepare']['suffix']|default('') }} \
          --tag={{ container_env['container-image-prepare']['tag']|default('latest') }} \
          --service-environment-file {{ item.item }}
  with_items: "{{ default_templates.results }}"

Handle exception: 'dict object' has no attribute 'suffix'
Handle exception: 'dict object' has no attribute 'suffix'

Helper files with variables needed for running
'openstack overcloud container image prepare' might not have all
variables set. Use empty values as default.

Change-Id: I10391f9732cfaee88b90c92ed03f93fe779f1790
