Skip to content
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

ansible-playbook --check mode/diff support for virt module #98

Open
nodiscc opened this issue Dec 16, 2021 · 2 comments
Open

ansible-playbook --check mode/diff support for virt module #98

nodiscc opened this issue Dec 16, 2021 · 2 comments
Labels
enhancement New feature or request

Comments

@nodiscc
Copy link

nodiscc commented Dec 16, 2021

SUMMARY

The virt module does not seem to support ansible-playbook --check mode - in check mode, tasks that use the virt module will always return skipped.

ISSUE TYPE
  • Feature Idea
COMPONENT NAME

virt

ADDITIONAL INFORMATION

This would allow reviewing changes in "dry-run" mode before actually applying them. Running the virt module in check mode should return the expected ok/changed state, and a diff of the VM XML definition when relevant (for example when command: define).

ansible-playbook playbook.yml --tags libvirt --check --diff
@csmart csmart added the enhancement New feature or request label Dec 27, 2021
@csmart
Copy link
Collaborator

csmart commented Dec 27, 2021

Hi @nodiscc, thanks for the suggestion! I'll need to think about this some more and have some conversations with others more knowledgeable than I am. I think that check returning OK is normal for tasks, so we could probably improve the check code there. I can see the benefit of the diff mode, but I'm not sure about how to implement it exactly. I think we should also take a look at what other modules do, for inspiration and consistency. (For future reference, https://docs.ansible.com/ansible/latest/user_guide/playbooks_checkmode.html#using-diff-mode)

What sort of things would you expect to see in the diff? For example, if you had a task to power a VM off which was currently on, or to add another device to an existing VM, etc?

Cheers,
-c

@nodiscc
Copy link
Author

nodiscc commented Mar 31, 2022

Hi @csmart , sorry for the late reply

A very basic use case for --check mode would be simulating VM startup/shutdown, for example I have a task that starts 3 VMs:

- name: start libvirt VMs
  community.libvirt.virt:
    name: "{{ item.name }}"
    state: "{{ item.state }}"
  with_items:
    - name: vm1.example.org
      state: running
    - name: vm2.example.org
      state: running
    - name: vm3.example.org
      state: running

When executed in check mode, the task returns skipping for all items:

# ansible-playbook --check playbook.yml --tags libvirt --limit hv.example.org
TASK [hv.example.org : start libvirt VMs] **************************************************************
skipping: [hv.example.org] => (item={'name': 'vm1.example.org', 'state': 'running'}) 
skipping: [hv.example.org] => (item={'name': 'vm2.example.org', 'state': 'running'}) 
skipping: [hv.example.org] => (item={'name': 'vm3.example.org', 'state': 'running'}) 

But I would expect it to return the same output as without --check:

# ansible-playbook playbook.yml --tags libvirt --limit hv.example.org
TASK [hv.example.org : start libvirt VMs] **************************************************************
ok: [hv.example.org] => (item={'name': 'vm1.example.org', 'state': 'running'})
changed: [hv.example.org] => (item={'name': 'vm2.example.org', 'state': 'running'})
changed: [hv.example.org] => (item={'name': 'vm3.example.org', 'state': 'running'})

(vm1 was already on, vm2 and vm3 were just started)

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants