Updated to use cloud-init images
This commit is contained in:
+41
-8
@@ -26,20 +26,53 @@
|
|||||||
remote_src: yes
|
remote_src: yes
|
||||||
mode: 0660
|
mode: 0660
|
||||||
register: copy_results
|
register: copy_results
|
||||||
- name: Define vm
|
|
||||||
community.libvirt.virt:
|
- name: Generate cloud-init user-data from template
|
||||||
command: define
|
delegate_to: localhost
|
||||||
xml: "{{ lookup('template', 'vm-template.xml.j2') }}"
|
ansible.builtin.copy:
|
||||||
|
src: files/leander.pub
|
||||||
|
dest: /tmp/ansible_cloudinit_ssh.pub
|
||||||
|
|
||||||
|
- name: Generate cloud-init user-data from template
|
||||||
|
delegate_to: localhost
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: cloud-init.yml.j2
|
||||||
|
dest: /tmp/ansible_cloudinit_userdata.config
|
||||||
|
|
||||||
|
- name: Copy network-config from file
|
||||||
|
delegate_to: localhost
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: templates/cloud-init-network.yml.j2
|
||||||
|
dest: /tmp/ansible_cloudinit_network.config
|
||||||
|
|
||||||
- name: Configure the image
|
- name: Configure the image
|
||||||
command: |
|
command: |
|
||||||
virt-customize -a {{ libvirt_pool_dir }}/{{ vm_name }}.qcow2 \
|
virt-customize -a {{ libvirt_pool_dir }}/{{ vm_name }}.qcow2 \
|
||||||
--hostname {{ vm_name }} \
|
--hostname {{ vm_name }} \
|
||||||
--password {{ vm_user }}:password:{{ vm_pass }} \
|
--root-password password:{{ root_passwd }} \
|
||||||
--firstboot-command '/usr/bin/ssh-keygen -A'
|
--firstboot-command '/usr/bin/ssh-keygen -A'
|
||||||
when: copy_results is changed
|
when: copy_results is changed
|
||||||
|
|
||||||
when: "vm_name not in existing_vms.list_vms"
|
- name: Install the vm via virt-install
|
||||||
|
ansible.builtin.command: |
|
||||||
|
virt-install \
|
||||||
|
--name "{{ vm_name }}" \
|
||||||
|
--boot uefi \
|
||||||
|
--machine q35 \
|
||||||
|
--memory "{{ vm_ram_mb }}" \
|
||||||
|
--vcpus "{{ vm_vcpus }}" \
|
||||||
|
--disk "path={{ vm_pool_dir }}/{{ vm_name }}.qcow2" \
|
||||||
|
--import \
|
||||||
|
--os-variant "debian11" \
|
||||||
|
--network "network={{ vm_net }},model=virtio,driver.iommu=on" \
|
||||||
|
--rng /dev/urandom,driver.iommu=on \
|
||||||
|
--memballoon driver.iommu=on \
|
||||||
|
--virt-type kvm \
|
||||||
|
--graphics vnc \
|
||||||
|
--noautoconsole \
|
||||||
|
--cloud-init user-data=/tmp/ansible_cloudinit_userdata.config,network-config=/tmp/ansible_cloudinit_network.config
|
||||||
|
--noreboot \
|
||||||
|
--qemu-commandline="-smbios type=1,serial=ds=nocloud;h={{ vm_name }}"
|
||||||
|
|
||||||
- name: Ensure VM is started
|
- name: Ensure VM is started
|
||||||
community.libvirt.virt:
|
community.libvirt.virt:
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
#cloud-config
|
||||||
|
network:
|
||||||
|
version: 2
|
||||||
|
ethernets:
|
||||||
|
all-en:
|
||||||
|
match:
|
||||||
|
name: {{ iface }}
|
||||||
|
dhcp4: false
|
||||||
|
addresses:
|
||||||
|
- {{ ip_addr }}
|
||||||
|
routes:
|
||||||
|
- to: default
|
||||||
|
via: {{ gateway }}
|
||||||
|
nameservers:
|
||||||
|
addresses:
|
||||||
|
- {{ dns_server_1 }}
|
||||||
|
- {{ dns_server_2 }}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
#cloud-config
|
||||||
|
users:
|
||||||
|
- name: {{ ci_user_name }}
|
||||||
|
shell: /bin/bash
|
||||||
|
groups: [sudo]
|
||||||
|
ssh-authorized-keys:
|
||||||
|
- "{{ ssh_public_key }}"
|
||||||
|
|
||||||
|
chpasswd:
|
||||||
|
list: |
|
||||||
|
{{ ci_user_name }}:{{ ci_user_passwd_hash}}
|
||||||
|
expire: False
|
||||||
|
|
||||||
|
ssh_pwauth: True
|
||||||
|
disable_root: True
|
||||||
|
|
||||||
|
package_update: true
|
||||||
|
package_upgrade: true
|
||||||
|
packages:
|
||||||
|
- htop
|
||||||
|
- nftables
|
||||||
|
- vim
|
||||||
|
- git
|
||||||
Reference in New Issue
Block a user