---
# Conditional facts to be set which are common to undercloud and overcloud

# confirmed variables for deploy and mixed upgrade
# GOOD
#   docker_registry_namespace
#   http://git.openstack.org/cgit/openstack/tripleo-quickstart/tree/config/release/tripleo-ci/CentOS-7/master-undercloud-queens-overcloud.yml

- name: set docker_registry_namespace_used
  set_fact:
    docker_registry_namespace_used: "{{ docker_registry_namespace }}"
  tags:
    - undercloud-install

# get_build_command is passing the current hash
# plus the latest dlrn hash and I'm not sure why
# http://git.openstack.org/cgit/openstack-infra/tripleo-ci/tree/roles/run-test/templates/oooq_common_functions.sh.j2#n155
- when: get_build_command is defined
  block:
    - name: execute build_command
      shell: "echo {{ get_build_command }}"
      register: build_command_output
      tags:
        - undercloud-install

    - name: set container_build_id from get_build_command
      set_fact:
        container_build_id: "{{ build_command_output.stdout }}"
        cacheable: true
      tags:
        - undercloud-install

# docker_image_tag is set to the dlrn hash but uses the tag
# as a backup default
# "{{ dlrn_hash|default(dlrn_hash_tag) }}"
- name: set container_build_id from docker_image_tag
  set_fact:
    container_build_id: "{{ docker_image_tag }}"
    cacheable: true
  when: get_build_command is not defined
  tags:
    - undercloud-install

# overcloud_docker_image_tag is set to overcloud_dlrn_hash
# I don't see where overcloud_dlrn_hash is set
# http://codesearch.openstack.org/?q=overcloud_dlrn_hash&i=nope&files=&repos=
- name: set mixed upgrade container_build_id
  set_fact:
    container_build_id: "{{ overcloud_docker_image_tag }}"
    docker_registry_namespace_used: "{{ overcloud_docker_registry_namespace }}"
    cacheable: true
  when:
    - container_build_id is not defined
    - use_overcloud_mixed_upgrade|default(false)|bool
  tags:
    - undercloud-install

- name: Set update_containers_append_tag for the play
  set_fact:
    update_containers_append_tag: "{{ lookup('pipe','date +-updated-%Y%m%d%H%M%S') }}"
    cacheable: true
  when: update_containers is defined and update_containers|bool and update_containers_append_tag is undefined
  tags:
    - undercloud-install

- name: echo container_build_id
  debug:
    var: container_build_id
  tags:
    - undercloud-install
