Advertisement
Guest User

Untitled

a guest
Feb 14th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. ---
  2. # This playbook creates VM from the QCOW2 Image
  3.  
  4. - name: Create VM Playbook
  5. hosts: localhost
  6. become: yes
  7. become_method: sudo
  8.  
  9. vars_files:
  10. - vars/guests.yml
  11.  
  12. tasks:
  13. - name: Start libvirtd
  14. service: name=libvirtd state=started enabled=yes
  15. register: libvirtd
  16.  
  17. - name: Wait for libvirtd to start
  18. wait_for:
  19. timeout: 30
  20. when: libvirtd.changed
  21.  
  22. - name: Create domain message display
  23. shell: echo 'Creating domain "{{ item.domain }}"'
  24. with_items: guests
  25.  
  26.  
  27. - name: Create tmpdir for cloud-init
  28. shell:
  29. mktemp -d
  30. register: tmpdir
  31.  
  32. - debug: msg="{{ tmpdir.stdout }}"
  33.  
  34. - name: Create cloud-init meta-data and user-data destinations
  35. file: path={{ item }} state=touch
  36. with_items:
  37. - "{{ tmpdir.stdout }}"/meta-data
  38. - "{{ tmpdir.stdout }}"/user-data
  39.  
  40. - name: cloud-init meta-data
  41. lineinfile: dest="{{ tmpdir.stdout }}"/meta-data line='instance-id{{':'}} "{{ item.domain }}"-iid\nlocal-hostname{{':'}} "{{ item.domain }}"'
  42. with_items: guests
  43.  
  44. - name: cloud-init user-data
  45. lineinfile: dest="{{ tmpdir.stdout }}"/user-data line='user{{':'}} atomic-user\npassword{{':'}} atomic\nchpasswd{{':'}} {expire{{':'}} False}\nssh_pwauth{{':'}} True'
  46.  
  47.  
  48. - name: Create a cloud-init metadata ISO Image
  49. shell: genisoimage -input-charset default
  50. -output "{{ item.path }}"/"{{ item.domain }}".cidata.iso
  51. -volid "{{ item.path }}"/"{{ item.domain }}".cidata.iso
  52. -joliet
  53. -rock
  54. -quiet
  55. "{{ tmpdir.stdout }}"/user-data
  56. "{{ tmpdir.stdout }}"/meta-data
  57. with_items: guests
  58.  
  59. - name: Create VM from QCOW2
  60. shell: virt-install --quiet --install --name="{{ item.domain }}"
  61. --os-variant="{{ item.os.variant }}" --ram="{{ item.mem }}"
  62. --vcpus="{{ item.cpu }}" --disk path="{{ item.path }}"/"{{ item.domain }}".qcow2,
  63. format=qcow2,bust=virtio --disk path="{{ item.path }}"/"{{ item.domain }}".cidata.iso,
  64. device=cdrom,readonly=on --network network=default --noautoconsole
  65. with_items: guests
  66.  
  67.  
  68. - name: Make sure that the VM is running
  69. virt: name="{{ item.domain }}" command=start
  70. with_items: guests
  71.  
  72. - name: Display username and password
  73. shell:
  74. echo "You can log in with username: atomic-user/password:atomic"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement