diff --git a/group_vars/all.yml b/group_vars/all.yml
index 25ce831..71c6773 100644
--- a/group_vars/all.yml
+++ b/group_vars/all.yml
@@ -1,3 +1,4 @@
ansible_ssh_private_key_file: private/keyfile
+ansible_user: ansible
libvirt:
images: /var/lib/libvirt/images
diff --git a/hosts b/hosts
index e0588d6..1779224 100644
--- a/hosts
+++ b/hosts
@@ -2,7 +2,7 @@
localhost ansible_connection=local
[docker_nodes]
-docker[1:3]
+docker1
[gitlab]
diff --git a/roles/virt_vm/tasks/create_vm.yml b/roles/virt_vm/tasks/create_vm.yml
index 1bdeab3..f8f7723 100644
--- a/roles/virt_vm/tasks/create_vm.yml
+++ b/roles/virt_vm/tasks/create_vm.yml
@@ -41,10 +41,16 @@
src: ci-userdata.j2
dest: "{{ cidata.path }}/user-data"
+- name: create CI-network-config
+ delegate_to: "{{ virt.host }}"
+ template:
+ src: ci-networkconfig.j2
+ dest: "{{ cidata.path }}/network-config"
+
- name: create CI ISO
delegate_to: "{{ virt.host }}"
shell:
- cmd: genisoimage -output "{{ libvirt.images }}/{{ inventory_hostname }}-cidata.iso" -volid cidata -joliet -rock user-data meta-data
+ cmd: genisoimage -output "{{ libvirt.images }}/{{ inventory_hostname }}-cidata.iso" -volid cidata -joliet -rock user-data meta-data network-config
chdir: "{{ cidata.path }}"
# VM INIT
@@ -52,10 +58,36 @@
- name: attach CI to vm
delegate_to: "{{ virt.host }}"
shell:
- cmd: virsh attach-disk "{{ inventory_hostname }}" --source "{{ libvirt.images }}/{{ inventory_hostname }}-cidata.iso" --target sda --type cdrom --mode readonly --persistent
+ cmd: virsh change-media "{{ inventory_hostname }}" sda --source "{{ libvirt.images }}/{{ inventory_hostname }}-cidata.iso" --insert --config
+
+- name: define vm
+ delegate_to: "{{ virt.host }}"
+ virt:
+ name: "{{ inventory_hostname }}"
+ state: running
+
+- name: ping VM
+ delegate_to: "{{ virt.host }}"
+ shell:
+ cmd: "ping -c 2 {{ ansible_host }}"
+ register: pingcmd
+ retries: 12
+ delay: 10
+ until: pingcmd.rc == 0
# CLOUD-INIT CLEANUP
+- name: detach CI from vm
+ delegate_to: "{{ virt.host }}"
+ shell:
+ cmd: virsh change-media "{{ inventory_hostname }}" sda --eject
+
+- name: shutdown VM
+ delegate_to: "{{ virt.host }}"
+ virt:
+ name: "{{ inventory_hostname }}"
+ state: shutdown
+
- name: delete CI temp dir
delegate_to: "{{ virt.host }}"
file:
diff --git a/roles/virt_vm/templates/ci-userdata.j2 b/roles/virt_vm/templates/ci-userdata.j2
index 2893e7e..9e942bb 100644
--- a/roles/virt_vm/templates/ci-userdata.j2
+++ b/roles/virt_vm/templates/ci-userdata.j2
@@ -1,5 +1,8 @@
#cloud-config
+preserve_hostname: False
+hostname: {{ inventory_hostname }}
+
users:
- name: ansible
ssh_authorized_keys:
@@ -7,3 +10,7 @@ users:
sudo: ['ALL=(ALL) NOPASSWD:ALL']
groups: sudo
shell: /bin/bash
+
+runcmd:
+ - eject /dev/sr0
+ - systemctl disable cloud-init
diff --git a/roles/virt_vm/templates/fedora-34.xml.j2 b/roles/virt_vm/templates/fedora-34.xml.j2
index e134d9c..1c1448c 100644
--- a/roles/virt_vm/templates/fedora-34.xml.j2
+++ b/roles/virt_vm/templates/fedora-34.xml.j2
@@ -38,6 +38,12 @@