Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---
- - block:
- - name: authenticating to rhev
- ovirt_auth:
- url: "https://localhost/ovirt-engine/api"
- username: "{{ rhev_user | regex_replace('(.*)','\\1@redhat.com') }}"
- password: "{{ rhev_pass }}"
- insecure: true
- - ovirt_storage_domains_facts:
- pattern: "{{ rhev_storage_pattern }}"
- auth: "{{ ovirt_auth }}"
- - set_fact:
- random_sd: "{{ (ovirt_storage_domains|random).name }}"
- - name: creating the VM
- ovirt_vms:
- name: "{{ inventory_hostname }}"
- auth: "{{ ovirt_auth }}"
- type: 'server'
- high_availability: True
- cluster: "{{ rhev_cluster }}"
- boot_devices:
- - network
- - hd
- cpu_cores: "{{ rhev_cpu_cores }}"
- cpu_sockets: "{{ rhev_cpu_sockets }}"
- comment: "Created by Ansicloud"
- description: "{{ inventory_hostname }}"
- memory: "{{ rhev_memory }}"
- state: stopped
- - name: creating eth0
- ovirt_nics:
- vm: "{{ inventory_hostname }}"
- name: eth0
- auth: "{{ ovirt_auth }}"
- profile: "{{ rhev_network }}"
- network: "{{ rhev_network }}"
- state: present
- register: vm_nic
- - debug:
- var: vm_nic
- - name: creating initial disks
- ovirt_disks:
- auth: "{{ ovirt_auth }}"
- vm_name: "{{ inventory_hostname }}"
- state: "attached"
- bootable: "{{ item.bootable }}"
- name: "{{ inventory_hostname }}_{{ item.name }}"
- size: "{{ item.size | default('20GiB') }}"
- format: "{{ item.format | default('cow') }}"
- storage_domain: "{{ random_sd }}"
- interface: "{{ item.interface | default('virtio') }}"
- with_items: "{{ rhev_disks }}"
- - set_fact:
- mac_address: "{{ vm_nic['nic']['mac']['address'] }}"
- - pause:
- prompt: "Due to a bug in ansible <= 2.3.0, please log into RHV and set the network card profile/vlan manually"
- - debug:
- var: mac_address
- delegate_to: "{{ rhev_host }}"
- tags:
- - rhv
- - vm_creation
- - block:
- - command: "cobbler system report --name={{ inventory_hostname }}"
- register: exists
- changed_when: false
- ignore_errors: True
- - shell: "cobbler_find_ip -s {{ cobbler_host }} -n {{ cobbler_subnet }} | grep 'IP Address:'| awk '{print $3}'"
- register: freeip
- changed_when: false
- when: exists.rc != 0 and cobbler_managed_dns
- - set_fact:
- freeipvalue: "{{ freeip.stdout }}"
- when: exists.rc != 0 and cobbler_managed_dns
- - debug: var=freeipvalue
- when: exists.rc != 0 and cobbler_managed_dns
- - name: Create cobbler profile for new VM with managed dns
- command: "cobbler system add --name {{ inventory_hostname }} --dns-name {{ inventory_hostname }} --hostname {{ inventory_hostname }} --profile {{ cobbler_profile }} --interface eth0 --mac {{ mac_address }} --ip {{ freeipvalue }} --subnet {{ cobbler_subnet_mask }} --gateway {{ cobbler_gateway }} --static true --netboot-enabled true --netboot 1"
- when: exists.rc != 0 and cobbler_managed_dns
- - name: Create cobbler profile for new VM with unmanaged dns
- command: "cobbler system add --name {{ inventory_hostname }} --dns-name {{ inventory_hostname }} --hostname {{ inventory_hostname }} --profile {{ cobbler_profile }} --interface eth0 --mac {{ mac_address }} --ip {{ ipvalue }} --subnet {{ cobbler_subnet_mask }} --gateway {{ cobbler_gateway }} --static true --netboot-enabled true --netboot 1"
- when: exists.rc != 0 and not cobbler_managed_dns
- - name: Update cobbler profile
- command: "cobbler system edit --name {{ inventory_hostname }} --dns-name {{ inventory_hostname }} --hostname {{ inventory_hostname }} --profile {{ cobbler_profile }} --interface eth0 --mac {{ mac_address }} --subnet {{ cobbler_subnet_mask }} --gateway {{ cobbler_gateway }} --static true --netboot-enabled true --netboot 1"
- when: exists.rc == 0
- - name: sync cobbler
- command: "cobbler sync"
- run_once: true
- no_log: true
- delegate_to: "{{ cobbler_host }}"
- tags:
- - cobbler
- - vm_config_cobbler
- - block:
- - name: starting the VM
- ovirt_vms:
- name: "{{ inventory_hostname }}"
- auth: "{{ ovirt_auth }}"
- state: running
- - name: wait to start
- pause:
- prompt: "Pausing for 1 minutes, to give time for the VM to start PXE"
- minutes: 1
- - name: setting VM boot to HD
- ovirt_vms:
- name: "{{ inventory_hostname }}"
- auth: "{{ ovirt_auth }}"
- boot_devices:
- - hd
- delegate_to: "{{ rhev_host }}"
- tags:
- - rhv
- - vm_start
- - name: edit the cobbler to disable PXE
- command: "cobbler system edit --name {{ inventory_hostname }} --netboot-enabled false"
- delegate_to: "{{ cobbler_host }}"
- tags:
- - cobbler
- - vm_start
- - block:
- - name: wait for provision
- pause:
- prompt: "Pausing for 30 minutes. Make sure the VM is installed before continuing"
- minutes: 30
- tags:
- - cobbler
- - vm_start
- - name: stopping the VM
- ovirt_vms:
- name: "{{ inventory_hostname }}"
- auth: "{{ ovirt_auth }}"
- state: stopped
- - name: creating additional disks
- ovirt_disks:
- auth: "{{ ovirt_auth }}"
- vm_name: "{{ inventory_hostname }}"
- state: "attached"
- #bootable: "{{ item.bootable }}"
- name: "{{ inventory_hostname }}_{{ item.name }}"
- size: "{{ item.size | default('20Gib') }}"
- format: "{{ item.format | default('cow') }}"
- storage_domain: "{{ random_sd }}"
- interface: "{{ item.interface | default('virtio') }}"
- with_items: "{{ rhev_additional_volumes }}"
- - name: starting the VM
- ovirt_vms:
- name: "{{ inventory_hostname }}"
- auth: "{{ ovirt_auth }}"
- state: running
- delegate_to: "{{ rhev_host }}"
- when: rhev_additional_volumes is defined
- tags:
- - rhv
- - vm_start
- - always:
- - ovirt_auth:
- state: absent
- ovirt_auth: "{{ ovirt_auth }}"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement