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
|
@ -11,7 +11,7 @@
|
|||
- name: vmname
|
||||
prompt: Name of the VM
|
||||
private: no
|
||||
- name: image_capacity
|
||||
- name: hdd
|
||||
prompt: Disk capacity
|
||||
private: no
|
||||
default: 10G
|
||||
|
@ -24,5 +24,6 @@
|
|||
private: no
|
||||
default: 1
|
||||
become: false
|
||||
gather_subset: ['!all']
|
||||
roles:
|
||||
- create-vm
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
---
|
||||
image_url: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-nocloud-amd64.qcow2
|
||||
image_checksum: fd77540aa77f4f5ed3a817d530adfc52d142e93e61c73a85f15422a68c56dcbd39799e5bb2195e521f99a8fa301fa6bf07a478cd27bd380d4c7054901b4c8256
|
||||
base_image: "{{ image_url | urlsplit('path') | basename }}"
|
||||
images_dir: /var/vm/
|
||||
os: debian11
|
||||
vm_host_bridge_interface: eno1
|
||||
recreate: false
|
|
@ -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
|
||||
|
|
|
@ -1,11 +1,32 @@
|
|||
#cloud-config
|
||||
locale: "de_DE.UTF-8"
|
||||
packages:
|
||||
- screen
|
||||
- ripgrep
|
||||
- ranger
|
||||
users:
|
||||
- default:
|
||||
hostname: '{{ vmname }}'
|
||||
ssh_pwauth: false
|
||||
# sets authorized ssh-keys keys for probably all users
|
||||
ssh_authorized_keys:
|
||||
- ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEGThAm6K/gH+36Q616He7Hykd3HEMVMifsbSlXuw9j7 carl@work
|
||||
{% for key in ssh_pubkeys %}
|
||||
- {{ key }}
|
||||
# sets the default's users password
|
||||
password:{{ vms_pass }}
|
||||
|
||||
##
|
||||
# use the following, to set individual user passwords
|
||||
##
|
||||
# chpasswd:
|
||||
# expire: false
|
||||
# list:
|
||||
# - user:{{ vms_pass }}
|
||||
# - root:{{ vms_pass }}
|
||||
#
|
||||
# users:
|
||||
# - name: user
|
||||
# groups: sudo
|
||||
# shell: /bin/bash
|
||||
# ssh_authorized_keys:
|
||||
#{% for key in ssh_pubkeys %}
|
||||
# - {{ key }}
|
||||
#{% endfor %}
|
||||
# - name: root
|
||||
# ssh_authorized_keys:
|
||||
#{% for key in ssh_pubkeys %}
|
||||
# - {{ key }}
|
||||
#{% endfor %}
|
||||
|
|
9
roles/create-vm/vars/main.yml
Normal file
9
roles/create-vm/vars/main.yml
Normal file
|
@ -0,0 +1,9 @@
|
|||
---
|
||||
image_url: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-generic-amd64.qcow2
|
||||
image_checksum: b90e042b6d1ada948a34fda8fb8ae6d41358f490512f963e9abdd6f7864d97d0394f08a2df974d31df44bd19b84df8a9bfc396d5628ee7b2f695b4565db410e5
|
||||
base_image: "{{ image_url | urlsplit('path') | basename }}"
|
||||
images_dir: /var/vm/
|
||||
os: debian11
|
||||
vm_host_bridge_interface: eno1
|
||||
# create a new vault with this key in vars, to change the default login pass
|
||||
vms_pass: "{{ vaulted_vms_pass }}"
|
Loading…
Reference in a new issue