VM Deployment ist nun funktionstüchtig

This commit is contained in:
Martin Wohlert 2021-06-07 23:11:12 +02:00
parent 09d4930cd2
commit 5ca763a72f
5 changed files with 55 additions and 4 deletions

View File

@ -1,3 +1,4 @@
ansible_ssh_private_key_file: private/keyfile ansible_ssh_private_key_file: private/keyfile
ansible_user: ansible
libvirt: libvirt:
images: /var/lib/libvirt/images images: /var/lib/libvirt/images

2
hosts
View File

@ -2,7 +2,7 @@
localhost ansible_connection=local localhost ansible_connection=local
[docker_nodes] [docker_nodes]
docker[1:3] docker1
[gitlab] [gitlab]

View File

@ -41,10 +41,16 @@
src: ci-userdata.j2 src: ci-userdata.j2
dest: "{{ cidata.path }}/user-data" 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 - name: create CI ISO
delegate_to: "{{ virt.host }}" delegate_to: "{{ virt.host }}"
shell: 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 }}" chdir: "{{ cidata.path }}"
# VM INIT # VM INIT
@ -52,10 +58,36 @@
- name: attach CI to vm - name: attach CI to vm
delegate_to: "{{ virt.host }}" delegate_to: "{{ virt.host }}"
shell: 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 # 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 - name: delete CI temp dir
delegate_to: "{{ virt.host }}" delegate_to: "{{ virt.host }}"
file: file:

View File

@ -1,5 +1,8 @@
#cloud-config #cloud-config
preserve_hostname: False
hostname: {{ inventory_hostname }}
users: users:
- name: ansible - name: ansible
ssh_authorized_keys: ssh_authorized_keys:
@ -7,3 +10,7 @@ users:
sudo: ['ALL=(ALL) NOPASSWD:ALL'] sudo: ['ALL=(ALL) NOPASSWD:ALL']
groups: sudo groups: sudo
shell: /bin/bash shell: /bin/bash
runcmd:
- eject /dev/sr0
- systemctl disable cloud-init

View File

@ -38,6 +38,12 @@
<target dev="vda" bus="virtio"/> <target dev="vda" bus="virtio"/>
<address type="pci" domain="0x0000" bus="0x04" slot="0x00" function="0x0"/> <address type="pci" domain="0x0000" bus="0x04" slot="0x00" function="0x0"/>
</disk> </disk>
<disk type="file" device="cdrom">
<driver name="qemu" type="raw"/>
<target dev="sda" bus="sata"/>
<readonly/>
<address type="drive" controller="0" bus="0" target="0" unit="0"/>
</disk>
<controller type="usb" index="0" model="qemu-xhci" ports="15"> <controller type="usb" index="0" model="qemu-xhci" ports="15">
<address type="pci" domain="0x0000" bus="0x02" slot="0x00" function="0x0"/> <address type="pci" domain="0x0000" bus="0x02" slot="0x00" function="0x0"/>
</controller> </controller>
@ -84,10 +90,15 @@
<address type="pci" domain="0x0000" bus="0x03" slot="0x00" function="0x0"/> <address type="pci" domain="0x0000" bus="0x03" slot="0x00" function="0x0"/>
</controller> </controller>
<interface type="network"> <interface type="network">
<source network="docker"/> <source network="default"/>
<model type="virtio"/> <model type="virtio"/>
<address type="pci" domain="0x0000" bus="0x01" slot="0x00" function="0x0"/> <address type="pci" domain="0x0000" bus="0x01" slot="0x00" function="0x0"/>
</interface> </interface>
<interface type="network">
<source network="docker"/>
<model type="virtio"/>
<address type="pci" domain="0x0000" bus="0x07" slot="0x00" function="0x0"/>
</interface>
<serial type="pty"> <serial type="pty">
<target type="isa-serial" port="0"> <target type="isa-serial" port="0">
<model name="isa-serial"/> <model name="isa-serial"/>