- name: check/create instance
  hosts: 127.0.0.1
  gather_facts: False

  tasks:
    - name: add hypervisor
      local_action: add_host hostname=rh-power2.fit.vutbr.cz groupname=spinup_vm_group


- name: spinup vm
  hosts: spinup_vm_group
  gather_facts: False
  user: msuchy

  tasks:
    - name: spin up VM
      shell: /home/msuchy/bin/get-one-vm.sh
      register: get_one

    - debug: msg="{{ get_one.stdout }}"

    - set_fact: builder_ip="{{ get_one.stdout|extract_ip_from_stdout() }}"

    - name: wait for he host to be hot
      local_action: wait_for host={{ builder_ip }} port=22 delay=1 timeout=600

    - name: add builder ip to the special group
      local_action: add_host hostname={{ builder_ip }} groupname=builder_temp_group

- name: provision builder
  hosts: builder_temp_group
  gather_facts: True
  user: root

  vars:
    # pass this options if you need to create new base image from snapshot
    #prepare_base_image: True

  tasks:
  - include: "provision_builder_tasks.yml"

  - get_url: url=https://kojipkgs.fedoraproject.org//packages/mock/1.2.10/1.fc21/noarch/mock-1.2.10-1.fc21.noarch.rpm dest=/tmp/
    when: ansible_distribution == 'Fedora' and ansible_distribution_major_version == 21

  - yum: state=present name=/tmp/mock-1.2.10-1.fc21.noarch.rpm
    when: ansible_distribution == 'Fedora' and ansible_distribution_major_version == 21

  - get_url: url=https://kojipkgs.fedoraproject.org//packages/mock/1.2.10/1.fc22/noarch/mock-1.2.10-1.fc22.noarch.rpm dest=/tmp/
    when: ansible_distribution == 'Fedora' and ansible_distribution_major_version == 22

  - yum: state=present name=/tmp/mock-1.2.10-1.fc22.noarch.rpm
    when: ansible_distribution == 'Fedora' and ansible_distribution_major_version == 22

  - get_url: url=https://kojipkgs.fedoraproject.org//packages/mock/1.2.10/1.fc23/noarch/mock-1.2.10-1.fc23.noarch.rpm dest=/tmp/
    when: ansible_distribution == 'Fedora' and ansible_distribution_major_version == 23

  - yum: state=present name=/tmp/mock-1.2.10-1.fc22.noarch.rpm
    when: ansible_distribution == 'Fedora' and ansible_distribution_major_version == 23
