Skip to content

Commit

Permalink
Parameterize libvirt image attributes (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
teddyphreak authored Mar 28, 2024
1 parent 6488f70 commit 626e898
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/libvirt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ on:
- master
paths:
- 'playbooks/prepare.yml'
- 'molecule/common/create.yml'
- 'molecule/common/templates/*.yml'
- 'molecule/common/vars.yml'
- 'molecule/hosts/*.yml'
- 'molecule/ipaddr/*.yml'
- '.github/workflows/libvirt.yml'
Expand Down
2 changes: 1 addition & 1 deletion galaxy.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
namespace: nephelaiio
name: mongodb
version: 0.2.21
version: 0.2.22
readme: README.md
authors:
- Ted Cook <[email protected]>
Expand Down
5 changes: 4 additions & 1 deletion molecule/common/create.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@
- name: Manage KVM guests
when: inventory_hostname not in guest_query.stdout_lines
block:

- name: Create KVM guest disks
ansible.builtin.copy:
remote_src: true
Expand Down Expand Up @@ -182,12 +181,16 @@
xml: "{{ lookup('ansible.builtin.template', 'vm.j2.xml') }}"
command: define
vars:
_platforms: "{{ molecule_yml.platforms }}"
_platform: "{{ _platforms | selectattr('name', 'equalto', inventory_hostname) | first }}"
guest_hostname: "{{ inventory_hostname }}"
guest_disk_format: qcow2
guest_disk_path: "{{ _libvirt_path }}/{{ inventory_hostname }}.img"
guest_iso_path: "{{ _libvirt_path }}/{{ inventory_hostname }}.iso"
guest_network: "{{ _libvirt_network }}"
guest_mac: "{{ '52:54:00' | random_mac(seed=guest_hostname) }}"
guest_mem: "{{ (_platform.mem | default(2)) * 1048576 }}"
guest_cpu: "{{ _platform.cpu | default(2) }}"
loop_control:
label: "{{ inventory_hostname }} - {{ _libvirt_path }}/{{ inventory_hostname }}.img"

Expand Down
6 changes: 3 additions & 3 deletions molecule/common/templates/vm.j2.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<domain type='kvm'>
<name>{{ guest_hostname }}</name>
<memory unit='KiB'>4194304</memory>
<currentMemory unit='KiB'>4194304</currentMemory>
<vcpu placement='static'>2</vcpu>
<memory unit='KiB'>{{ guest_mem }}</memory>
<currentMemory unit='KiB'>{{ guest_mem }}</currentMemory>
<vcpu placement='static'>{{ guest_cpu }}</vcpu>
<resource>
<partition>/machine</partition>
</resource>
Expand Down

0 comments on commit 626e898

Please sign in to comment.