Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.86 KB | None | 0 0
  1. ---
  2. - block:
  3. - name: authenticating to rhev
  4. ovirt_auth:
  5. url: "https://localhost/ovirt-engine/api"
  6. username: "{{ rhev_user | regex_replace('(.*)','\\1@redhat.com') }}"
  7. password: "{{ rhev_pass }}"
  8. insecure: true
  9.  
  10. - ovirt_storage_domains_facts:
  11. pattern: "{{ rhev_storage_pattern }}"
  12. auth: "{{ ovirt_auth }}"
  13.  
  14. - set_fact:
  15. random_sd: "{{ (ovirt_storage_domains|random).name }}"
  16.  
  17. - name: creating the VM
  18. ovirt_vms:
  19. name: "{{ inventory_hostname }}"
  20. auth: "{{ ovirt_auth }}"
  21. type: 'server'
  22. high_availability: True
  23. cluster: "{{ rhev_cluster }}"
  24. boot_devices:
  25. - network
  26. - hd
  27. cpu_cores: "{{ rhev_cpu_cores }}"
  28. cpu_sockets: "{{ rhev_cpu_sockets }}"
  29. comment: "Created by Ansicloud"
  30. description: "{{ inventory_hostname }}"
  31. memory: "{{ rhev_memory }}"
  32. state: stopped
  33.  
  34. - name: creating eth0
  35. ovirt_nics:
  36. vm: "{{ inventory_hostname }}"
  37. name: eth0
  38. auth: "{{ ovirt_auth }}"
  39. profile: "{{ rhev_network }}"
  40. network: "{{ rhev_network }}"
  41. state: present
  42. register: vm_nic
  43.  
  44. - debug:
  45. var: vm_nic
  46.  
  47. - name: creating initial disks
  48. ovirt_disks:
  49. auth: "{{ ovirt_auth }}"
  50. vm_name: "{{ inventory_hostname }}"
  51. state: "attached"
  52. bootable: "{{ item.bootable }}"
  53. name: "{{ inventory_hostname }}_{{ item.name }}"
  54. size: "{{ item.size | default('20GiB') }}"
  55. format: "{{ item.format | default('cow') }}"
  56. storage_domain: "{{ random_sd }}"
  57. interface: "{{ item.interface | default('virtio') }}"
  58. with_items: "{{ rhev_disks }}"
  59.  
  60. - set_fact:
  61. mac_address: "{{ vm_nic['nic']['mac']['address'] }}"
  62.  
  63. - pause:
  64. prompt: "Due to a bug in ansible <= 2.3.0, please log into RHV and set the network card profile/vlan manually"
  65.  
  66. - debug:
  67. var: mac_address
  68.  
  69. delegate_to: "{{ rhev_host }}"
  70. tags:
  71. - rhv
  72. - vm_creation
  73.  
  74. - block:
  75. - command: "cobbler system report --name={{ inventory_hostname }}"
  76. register: exists
  77. changed_when: false
  78. ignore_errors: True
  79.  
  80. - shell: "cobbler_find_ip -s {{ cobbler_host }} -n {{ cobbler_subnet }} | grep 'IP Address:'| awk '{print $3}'"
  81. register: freeip
  82. changed_when: false
  83. when: exists.rc != 0 and cobbler_managed_dns
  84.  
  85. - set_fact:
  86. freeipvalue: "{{ freeip.stdout }}"
  87. when: exists.rc != 0 and cobbler_managed_dns
  88.  
  89. - debug: var=freeipvalue
  90. when: exists.rc != 0 and cobbler_managed_dns
  91.  
  92. - name: Create cobbler profile for new VM with managed dns
  93. 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"
  94. when: exists.rc != 0 and cobbler_managed_dns
  95.  
  96. - name: Create cobbler profile for new VM with unmanaged dns
  97. 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"
  98. when: exists.rc != 0 and not cobbler_managed_dns
  99.  
  100. - name: Update cobbler profile
  101. 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"
  102. when: exists.rc == 0
  103.  
  104. - name: sync cobbler
  105. command: "cobbler sync"
  106. run_once: true
  107. no_log: true
  108.  
  109. delegate_to: "{{ cobbler_host }}"
  110. tags:
  111. - cobbler
  112. - vm_config_cobbler
  113.  
  114. - block:
  115. - name: starting the VM
  116. ovirt_vms:
  117. name: "{{ inventory_hostname }}"
  118. auth: "{{ ovirt_auth }}"
  119. state: running
  120.  
  121. - name: wait to start
  122. pause:
  123. prompt: "Pausing for 1 minutes, to give time for the VM to start PXE"
  124. minutes: 1
  125.  
  126. - name: setting VM boot to HD
  127. ovirt_vms:
  128. name: "{{ inventory_hostname }}"
  129. auth: "{{ ovirt_auth }}"
  130. boot_devices:
  131. - hd
  132.  
  133. delegate_to: "{{ rhev_host }}"
  134. tags:
  135. - rhv
  136. - vm_start
  137.  
  138. - name: edit the cobbler to disable PXE
  139. command: "cobbler system edit --name {{ inventory_hostname }} --netboot-enabled false"
  140. delegate_to: "{{ cobbler_host }}"
  141. tags:
  142. - cobbler
  143. - vm_start
  144.  
  145. - block:
  146. - name: wait for provision
  147. pause:
  148. prompt: "Pausing for 30 minutes. Make sure the VM is installed before continuing"
  149. minutes: 30
  150. tags:
  151. - cobbler
  152. - vm_start
  153.  
  154. - name: stopping the VM
  155. ovirt_vms:
  156. name: "{{ inventory_hostname }}"
  157. auth: "{{ ovirt_auth }}"
  158. state: stopped
  159.  
  160. - name: creating additional disks
  161. ovirt_disks:
  162. auth: "{{ ovirt_auth }}"
  163. vm_name: "{{ inventory_hostname }}"
  164. state: "attached"
  165. #bootable: "{{ item.bootable }}"
  166. name: "{{ inventory_hostname }}_{{ item.name }}"
  167. size: "{{ item.size | default('20Gib') }}"
  168. format: "{{ item.format | default('cow') }}"
  169. storage_domain: "{{ random_sd }}"
  170. interface: "{{ item.interface | default('virtio') }}"
  171. with_items: "{{ rhev_additional_volumes }}"
  172.  
  173. - name: starting the VM
  174. ovirt_vms:
  175. name: "{{ inventory_hostname }}"
  176. auth: "{{ ovirt_auth }}"
  177. state: running
  178.  
  179. delegate_to: "{{ rhev_host }}"
  180. when: rhev_additional_volumes is defined
  181. tags:
  182. - rhv
  183. - vm_start
  184.  
  185. - always:
  186. - ovirt_auth:
  187. state: absent
  188. ovirt_auth: "{{ ovirt_auth }}"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement