---
- name: install libguestfs-tools to get virt-customize
  become: yes
  package:
      name: libguestfs-tools
      state: present

- name: tmp repos.d for overcloud
  file:
      name: "{{ tmp_oc_repos_dir }}"
      state: directory

# TODO(psedlak): use install/rhos-release / mirror urls (do we want it here?)
- name: setup repositories locally
  rhos_release:
      state: install
      release: "{{ install.version | default(undercloud_version) }}"
      build_date: "{{ install.build }}"
      # explicitly avoid director packages for images
      director: no
      target_directory: "{{ tmp_oc_repos_dir }}"
      # Assume images distro is the same as undercloud
  register: command_result
  until: command_result.stderr.find('Connection reset by peer') == -1
  retries: 40
  delay: 5

- name: push repos to overcloud image
  command: "virt-copy-in -a {{ overcloud_image_file }} {{ tmp_oc_repos_dir }} /etc/"

- name: Install packages in overcloud image
  command: "virt-customize -a {{ overcloud_image_file }} --install {{ install.images.packages }}"
  when: install.images.packages|default(None) != None

# Don't use virt-customize to update images. It's unreliable.

---
- name: install libguestfs-tools to get virt-customize
  become: yes
  package:
      name: libguestfs-tools
      state: present

- name: tmp repos.d for overcloud
  file:
      name: "{{ tmp_oc_repos_dir }}"
      state: directory

# TODO(psedlak): use install/rhos-release / mirror urls (do we want it here?)
- name: setup repositories locally
  rhos_release:
      state: install
      release: "{{ install.version | default(undercloud_version) }}"
      build_date: "{{ install.build }}"
      # explicitly avoid director packages for images
      director: no
      target_directory: "{{ tmp_oc_repos_dir }}"
      # Assume images distro is the same as undercloud
  register: command_result
  until: command_result.stderr.find('Connection reset by peer') == -1
  retries: 40
  delay: 5

- name: push repos to overcloud image
  command: "virt-copy-in -a {{ overcloud_image_file }} {{ tmp_oc_repos_dir }} /etc/"

- name: Install packages in overcloud image
  command: "virt-customize -a {{ overcloud_image_file }} --install {{ install.images.packages }} --selinux-relabel"
  when: install.images.packages|default(None) != None

# Don't use virt-customize to update images. It's unreliable.

Add --selinux-relabel to packages installation in overcloud images
Add --selinux-relabel to packages installation in overcloud images

Not using --selinux-relable when installing new packages in overcloud
images may lead to endless overcloud deployment.

Change-Id: I4a4622b5f960bb4225d611019fba413d61cc77c1
