---
# Playbook included in OVB setups that use a testenv broker to create the
# OVB stack.

- name: Local setup for quickstart
  hosts: localhost
  connection: local
  tasks:
    - name: Host setup
      shell: >
        echo "127.0.0.1 $(hostname) $(hostname).openstacklocal" | sudo tee -a /etc/hosts;
        echo "127.0.0.2 undercloud undercloud.openstacklocal" | sudo tee -a /etc/hosts;
        if [ ! -e ${HOME}/.ssh/id_rsa.pub ] ; then
            if [[ -e ${HOME}/.ssh/id_rsa ]]; then
                ssh-keygen -y -f ${HOME}/.ssh/id_rsa > ${HOME}/.ssh/id_rsa.pub;
            else
                ssh-keygen -N "" -f ${HOME}/.ssh/id_rsa;
            fi
        fi;
        sudo mkdir -p /root/.ssh;
        cat ~/.ssh/id_rsa.pub | sudo tee -a /root/.ssh/authorized_keys | tee -a ~/.ssh/authorized_keys;
        sudo yum remove -y puppet hiera puppetlabs-release rdo-release centos-release-[a-z]*;
        sudo rm -rf /etc/puppet /etc/hiera.yaml;
        sudo cp {{tripleo_root}}/tripleo-ci/test-environments/overcloud-cacert.pem /etc/pki/ca-trust/source/anchors/;
        sudo update-ca-trust extract;
        cp -f {{ lookup('env', 'TE_DATAFILE') }} ~/instackenv.json;

    - name: Correct the driver for newer releases
      # TODO(dtantsur): remove when Pike is not supported
      command: sed -i s/pxe_ipmitool/ipmi/ ~/instackenv.json
      when: release not in ['newton', 'ocata', 'pike']

    - name: Create eth2.conf file
      blockinfile:
        dest: "{{ working_dir }}/eth2.conf"
        content: |
          network_config:
            - type: interface
              name: eth2
              use_dhcp: false
              mtu: 1450
              addresses:
                - ip_netmask: 10.0.0.1/24
                - ip_netmask: 2001:db8:fd00:1000::1/64
        create: true

    - name: Install ipmitool if not installed
      package:
        name: ipmitool
        state: latest
      become: true
