Skip to content

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

Description

@FSangouard

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions