Skip to content

Fix lvm #62

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ Example Playbook
- 'mon1.example.org'
- 'mon2.example.org'
- 'mon3.example.org'

interfaces:
- network: 'br-datacentre'

Expand All @@ -236,6 +236,22 @@ Example Playbook
source:
dev: 'br-datacentre'

- state: present
name: 'vm3'
memory_mb: 1024
vcpus: 1
volumes:
- name: 'lv_vm3'
type: 'block'
capacity: '10GB'
pool: 'lvm_pool'
format: 'raw'
- name: 'debian-10.5.0-amd64-netinst.iso'
type: 'file'
device: 'cdrom'
format: 'raw'
interfaces:
- network: 'test'

Author Information
------------------
Expand Down
2 changes: 1 addition & 1 deletion tasks/volumes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
{% endif %}
-a {{ ansible_check_mode }}
with_items: "{{ volumes }}"
when: item.type | default(libvirt_volume_default_type) == 'volume'
when: item.type | default(libvirt_volume_default_type) == 'volume' or ( item.type | default(libvirt_volume_default_type) == 'block' and item.pool is defined )

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this makes sense for a block device.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,
It's a workaround (only for block device in LVM) otherwise the tasks is skipped so the volume is not created.
as the variable need to be like this :

  volumes:
    - name: 'ns2'
      type: 'block'
      capacity: '10GB'
      pool: 'lvm_pool'
      format: 'raw'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, but I don't think it makes sense in the general case. Typically a block device would not be associated with a volume, AFAIU.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general case, volume.pool will not exist so it's will skip, so same behaviour than before

environment: "{{ libvirt_vm_script_env }}"
register: volume_result
changed_when:
Expand Down
2 changes: 2 additions & 0 deletions templates/vm.xml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
<driver name='qemu' type='{{ volume.format | default(libvirt_volume_default_format) }}'/>
{% if volume.type | default(libvirt_volume_default_type) == 'file' %}
<source file='{{ volume.file_path |default(libvirt_volume_default_images_path) }}/{{ volume.name}}'/>
{% elif volume.pool is defined %}
<source dev='/dev/{{ volume.pool }}/{{ volume.name }}'/>
{% elif volume.type is defined and volume.type == 'network' %}
{% if volume.auth.username is defined %}
<auth username='{{ volume.auth.username }}'>
Expand Down