ansible-collections / ansible.posix

Ansible Collection for Posix
Other
153 stars 150 forks source link

Ephemeral mount point is not idempotent #452

Open paulo-dev-xpectral opened 1 year ago

paulo-dev-xpectral commented 1 year ago
SUMMARY

With the following task, and with the target drive not mounted:

    - name: Disk is mounted
      mount:
        path: /media/external-drive
        src: UUID={{ UUID }}
        fstype: ext4
        opts: "rw"
        state: ephemeral
      become: true

The playbook runs successfully the first time, and the drive is mounted. However, upon a second run I get the following error:

fatal: [127.0.0.1]: FAILED! => {"changed": false, "msg": "Ephemeral mount point is already mounted with a different source than the specified one. Failing in order to prevent an unwanted unmount or override operation. Try replacing this command with a \"state: unmounted\" followed by a \"state: ephemeral\", or use a different destination path."}

I don't think the error's suggestion is appropriate because I do not wish to trigger a remount when one is already present. I would assume that ansible would recognize that a disk with the same UUID is already mounted on that destination path, and thus not do anything at all. I also specifically want to use the "ephemeral" option because I don't want to change the fstab file.

ISSUE TYPE
COMPONENT NAME

ansible.posix.mount

ANSIBLE VERSION
ansible [core 2.14.4]
  config file = /home/edgar/.config/ansible/ansible.cfg
  configured module search path = ['/home/edgar/.config/ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.10/site-packages/ansible
  ansible collection location = /home/edgar/.config/ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.10.10 (main, Mar  5 2023, 22:26:53) [GCC 12.2.1 20230201] (/usr/bin/python)
  jinja version = 3.1.2
  libyaml = True
COLLECTION VERSION
# /usr/lib/python3.10/site-packages/ansible_collections
Collection        Version
----------------- -------
community.general 6.5.0
CONFIGURATION
ANSIBLE_HOME(env: ANSIBLE_HOME) = /home/edgar/.config/ansible
CONFIG_FILE() = /home/edgar/.config/ansible/ansible.cfg
DEFAULT_HOST_LIST(/home/edgar/.config/ansible/ansible.cfg) = ['/home/edgar/git/personal/home_management/ansible/hosts']
DEFAULT_ROLES_PATH(/home/edgar/.config/ansible/ansible.cfg) = ['/home/edgar/git/personal/home_management/ansible/tasks']
PLAYBOOK_DIR(/home/edgar/.config/ansible/ansible.cfg) = /home/edgar/git/personal/home_management/ansible/tasks
OS / ENVIRONMENT

os: arch linux

STEPS TO REPRODUCE

Run the aforementioned playbook with a sample UUID passed as argument

- name: Disk is mounted
      mount:
        path: /media/external-drive
        src: UUID={{ UUID }}
        fstype: ext4
        opts: "rw"
        state: ephemeral
      become: true
EXPECTED RESULTS

I expected that running the playbook a second time around would output ok = 1 and changed = 0, because the mount point is already there

ACTUAL RESULTS
ok: [127.0.0.1]

TASK [Disk is mounted] ******************************************************************************************************************
fatal: [127.0.0.1]: FAILED! => {"changed": false, "msg": "Ephemeral mount point is already mounted with a different source than the specified one. Failing in order to prevent an unwanted unmount or override operation. Try replacing this command with a \"state: unmounted\" followed by a \"state: ephemeral\", or use a different destination path."}

PLAY RECAP ******************************************************************************************************************************
127.0.0.1                  : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0
darkdragon-001 commented 8 months ago

I observe the same issue with an ephemeral btrfs mount also using UUID as src.