---
- name: Install undercloud repo file
  copy: src="{{ files }}/newcloud/rhos13.repo" dest=/etc/yum.repos.d/rhos13.repo
  tags:
  - config
  - packages
  - yumrepos
  - undercloud

- name: Install packages
  package: name={{ item }} state=present
  with_items:
  - subscription-manager-rhsm-certificates
  - python-tripleoclient
  - rhosp-director-images-all
  tags:
  - packages
  - undercloud

- name: Create stack user
  user: name=stack comment="openstack user" home=/home/stack
  tags:
  - config
  - users
  - undercloud

- name: Create some directories
  file: path=/home/stack/{{item}} state=directory owner=stack group=stack mode=0755
  with_items:
  - templates
  - images
  - images/x86_64
  - images/ppc64le
  tags:
  - config
  - undercloud

- name: Create web directory
  file: path=/srv/web state=directory owner=root group=root mode=0755
  tags:
  - config
  - undercloud

- name: Copy files to ~/stack/
  copy: src={{item}} dest=/home/stack/{{item}} owner=stack group=stack mode=0644
  with_items:
  - undercloud.conf
  - templates/node-info.yaml
  - openstack-overcloud-deploy.sh
  tags:
  - config
  - undercloud

- name: Copy templates to ~/stack/
  template: src={{item}} dest=/home/stack/{{item}} owner=stack group=stack mode=0644
  with_items:
  - custom-storage.yaml
  - environment-rhel-registration.yaml
  tags:
  - config
  - undercloud

- name: Copy nodes.json
  template: src=nodes.json dest=/home/stack/nodes.json owner=stack group=stack mode=0644
  tags:
  - config
  - undercloud
  - nodes

- name: Do an undercloud install if it has yet to be done
  become: yes
  become_user: stack
  shell: openstack undercloud install
  args:
    chdir: /home/stack/
    creates: /home/stack/stackrc

- name: Copy over images
  become: yes
  become_user: stack
  shell: |
    for arch in x86_64 ppc64le; do
      for i in /usr/share/rhosp-director-images/overcloud-full-latest-13.0-${arch}.tar \
        /usr/share/rhosp-director-images/ironic-python-agent-latest-13.0-${arch}.tar; do
          tar -C $arch -xf $i;
      done;
    done
  args:
    chdir: /home/stack/images/
    creates: /home/stack/imagex/x86_64/overcloud-full.initrd

