mirror of
https://github.com/ansible-collections/ansible.posix.git
synced 2026-11-24 18:03:41 +00:00
A new `absent_keep_mountpoint` option has been added to the state. This option keeps the mount point from being deleted when the state is absent. Co-authored-by: Michael Sprott <165604036+sprottm@users.noreply.github.com>
This commit is contained in:
co-authored by
Michael Sprott
parent
7811740296
commit
e03234e855
@@ -297,10 +297,17 @@
|
||||
when: ansible_system in ('FreeBSD', 'Linux')
|
||||
register: dest_stat
|
||||
|
||||
- name: Check if the mountpoint still exists
|
||||
ansible.builtin.stat:
|
||||
path: '{{ output_dir }}/mount_dest'
|
||||
when: ansible_system in ('FreeBSD', 'Linux')
|
||||
register: mountpoint_stat
|
||||
|
||||
- name: Check that we did not unmount
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- unmount_result['changed']
|
||||
- mountpoint_stat['stat']['exists']
|
||||
- dest_stat['stat']['exists']
|
||||
when: ansible_system in ('FreeBSD', 'Linux')
|
||||
|
||||
@@ -318,10 +325,65 @@
|
||||
when: ansible_system in ('FreeBSD', 'Linux')
|
||||
register: dest_stat
|
||||
|
||||
- name: Check that the mountpoint no longer exists
|
||||
ansible.builtin.stat:
|
||||
path: '{{ output_dir }}/mount_dest'
|
||||
when: ansible_system in ('FreeBSD', 'Linux')
|
||||
register: mountpoint_stat
|
||||
|
||||
- name: Check that we unmounted
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- unmount_result['changed']
|
||||
- not mountpoint_stat['stat']['exists']
|
||||
- not dest_stat['stat']['exists']
|
||||
when: ansible_system in ('FreeBSD', 'Linux')
|
||||
|
||||
# unmount (absent_keep_mountpoint)
|
||||
- name: Bind mount a filesystem (Linux)
|
||||
ansible.posix.mount:
|
||||
src: '{{ output_dir }}/mount_source'
|
||||
name: '{{ output_dir }}/mount_dest'
|
||||
state: mounted
|
||||
fstype: None
|
||||
opts: bind
|
||||
when: ansible_system == 'Linux'
|
||||
register: bind_result_linux
|
||||
|
||||
- name: Bind mount a filesystem (FreeBSD)
|
||||
ansible.posix.mount:
|
||||
src: '{{ output_dir }}/mount_source'
|
||||
name: '{{ output_dir }}/mount_dest'
|
||||
state: mounted
|
||||
fstype: nullfs
|
||||
when: ansible_system == 'FreeBSD'
|
||||
register: bind_result_freebsd
|
||||
|
||||
- name: Unmount the bind mount while keeping the mountpoint
|
||||
ansible.posix.mount:
|
||||
name: '{{ output_dir }}/mount_dest'
|
||||
state: absent_keep_mountpoint
|
||||
when: ansible_system in ('Linux', 'FreeBSD')
|
||||
register: unmount_result
|
||||
|
||||
- name: Make sure the file no longer exists in dest
|
||||
ansible.builtin.stat:
|
||||
path: '{{ output_dir }}/mount_dest/test_file'
|
||||
when: ansible_system in ('FreeBSD', 'Linux')
|
||||
register: dest_stat
|
||||
|
||||
- name: Check if the mountpoint still exists
|
||||
ansible.builtin.stat:
|
||||
path: '{{ output_dir }}/mount_dest'
|
||||
when: ansible_system in ('FreeBSD', 'Linux')
|
||||
register: mountpoint_stat
|
||||
|
||||
- name: Check that we unmounted and that the mountpoint still exists
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- (ansible_system == 'Linux' and bind_result_linux['changed']) or (ansible_system == 'FreeBSD' and bind_result_freebsd['changed'])
|
||||
- unmount_result['changed']
|
||||
- mountpoint_stat['stat']['exists']
|
||||
- not dest_stat['stat']['exists']
|
||||
when: ansible_system in ('FreeBSD', 'Linux')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user