get it actually working, with the correct cloudimage and stuff ;P
This commit is contained in:
parent
67c9db90a0
commit
c7a431916f
6 changed files with 48 additions and 31 deletions
|
@ -18,7 +18,6 @@
|
|||
module: template
|
||||
src: vm_hostvars.j2
|
||||
dest: ./host_vars/{{ vmname }}/vars.yml
|
||||
#mode: 0666
|
||||
|
||||
- name: add vm to hosts
|
||||
local_action:
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
---
|
||||
- include_vars: vault
|
||||
|
||||
- name: check if vm name exists in hostvars
|
||||
local_action: stat path="host_vars/{{ vmname }}"
|
||||
register: register_name
|
||||
|
@ -7,13 +9,9 @@
|
|||
debug:
|
||||
msg: "The file or directory exists"
|
||||
failed_when: register_name.stat.exists
|
||||
when:
|
||||
- register_name.stat.exists
|
||||
- not recreate
|
||||
|
||||
- name: add new vm to hostvars
|
||||
include_tasks: create_hostvars.yml
|
||||
when: not recreate
|
||||
|
||||
- name: install libvirt and co
|
||||
package:
|
||||
|
@ -50,10 +48,12 @@
|
|||
url: '{{ image_url }}'
|
||||
dest: '{{ images_dir }}'
|
||||
checksum: 'sha512:{{ image_checksum }}'
|
||||
owner: libvirt-qemu
|
||||
group: libvirt-qemu
|
||||
when: not recent_cloudimage.matched
|
||||
|
||||
- name: Create VM image from base image
|
||||
command: qemu-img create -b {{ base_image }} -f qcow2 -F qcow2 {{ images_dir }}{{ vmname }}.img {{ image_capacity }}
|
||||
command: qemu-img create -b {{ base_image }} -f qcow2 -F qcow2 {{ images_dir }}{{ vmname }}.img {{ hdd }}
|
||||
|
||||
- name: Create user-data
|
||||
template:
|
||||
|
@ -65,16 +65,11 @@
|
|||
src: meta-data.j2
|
||||
dest: '{{ images_dir }}/meta-data'
|
||||
|
||||
- name: Create cloud-init configuration image
|
||||
command: genisoimage -output {{ images_dir }}/{{ vmname }}-cidata.iso -V cidata -r -J {{ images_dir }}/user-data {{ images_dir }}/meta-data
|
||||
become: true
|
||||
|
||||
- name: make sure setuid for qemu-bridge-helper is set
|
||||
file:
|
||||
path: /usr/lib/qemu/qemu-bridge-helper
|
||||
mode: 04755
|
||||
become: true
|
||||
|
||||
|
||||
- name: Create the VM
|
||||
command: virt-install --name={{ vmname }} --ram={{ ram }} --vcpus={{ vcpus }} --import --disk path={{ images_dir }}{{ vmname }}.img,format=qcow2 --disk path={{ images_dir }}{{ vmname }}-cidata.iso,device=cdrom --os-variant {{ os }} --network bridge=br0,model=virtio --graphics vnc,listen=0.0.0.0 --noautoconsole
|
||||
command: virt-install --name={{ vmname }} --ram={{ ram }} --vcpus={{ vcpus }} --import --disk path={{ images_dir }}{{ vmname }}.img,format=qcow2 --cloud-init meta-data={{ images_dir }}meta-data,user-data={{ images_dir }}user-data --os-variant {{ os }} --network bridge=br0,model=virtio --graphics vnc,listen=0.0.0.0 --noautoconsole
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue