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

[gluster_volume] Setting state=absent fails when volume doesn't exist #21

Open
FSangouard opened this issue Dec 8, 2021 · 3 comments
Open

Comments

@FSangouard
Copy link

Context:

  • Ansible version : 2.7
  • GlusterFS version : 9.4
  • target OS : CentOS 7.4

I have a task that uses the gluster_volume module like this :

- name: delete glusterfs volume
  gluster_volume:
    state: absent
    name: "{{ volume.name }}"
  run_once: true

Problem:

When the volume exists, it is correctly deleted, but when it doesn't exist, the task is failed with the following message :

TASK [glusterfs/init/delete/server : delete glusterfs volume] ******************
fatal: [vm_sto1]: FAILED! => {"changed": false, "msg": "volume not found volume1"}

As a consequence, the play stops with FAILURE status.

Expected result:

Task result is "ok", indicating no change happened, and the play continues on.

Workarounds:

Setting ignore_errors to "yes" on the task is not satisfactory because I don't want to ignore errors when actually failing to delete an existing volume, plus I would like the task to have the "ok" status, not "failed but ignored".
I've been playing with failed_when conditions to try and mimic the behaviour I want. I ended up with this :

- name: delete glusterfs volume
  gluster_volume:
    state: absent
    name: "{{ volume.name }}"
  run_once: true
  register: output
  failed_when:
    - '"volume not found" not in output.msg'
    - not output.changed

but I'm not sure if this is robust and it definitely isn't elegant, so I would like to get rid of it if possible.

@pkesavap
Copy link
Member

pkesavap commented Dec 9, 2021

Hi @FSangouard
That is expected.
I don't see a reason why the play needs to continue if there no glusterfs volumes to be found

@FSangouard
Copy link
Author

It seems odd to me that a task that has nothing to do should fail. The play might have other tasks to do after this one, so stopping in that case is wrong IMO.

An analogy I can think of is when we want to delete a file using the file module, we specify state=absent and if the file doesn't exist on the machine, the task does nothing and is marked 'ok', and the play continues.

@bluikko
Copy link

bluikko commented Jan 14, 2023

This definitely is an idempotency problem which is against the main principles of Ansible.

If something missing is attempted to be deleted, then the proper way is to just return changed=false.

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

No branches or pull requests

3 participants