ansible.posix/tests/integration/targets/mount/tasks/bind_mount.yml
quidame eafd8f8935 feature: mount - implement swapon/swapoff (#106)
* Declare functions swapon() & swapoff(), is_swap() & reswap().
* Apply swapon/swapoff for states mounted, unmounted, remounted and
  absent.
* Override default opts and boot when fstype=swap.
* Do not honor 'fstab' when fstype=swap (fail instead).
* Also fail when fstype=swap and 'path' is not 'none' ('-' for Solaris).
* Update module documentation accordingly.
+ Replace all platform.system() calls by a variable.

refactor integration tests

* Improve readability/understanding of what is tested, and what OS is
  targeted.
* Move 'swap' related test cases into dedicated file (swap.yml).
* Add new test cases about swap enabling/disabling.
* Extend tests to FreeBSD when possible.
2021-03-28 01:21:08 +01:00

95 lines
2.6 KiB
YAML

---
# Tasks to validate bind mounts (i.e. mount of a directory to another one).
# Linux and FreeBSD only.
- name: Create the mount point (the target of the mount)
file:
state: directory
path: '{{ output_dir }}/mount_dest'
- name: Create a directory to bind mount (the source of the mount)
file:
state: directory
path: '{{ output_dir }}/mount_source'
- name: Put something in the directory so we see that it worked
copy:
content: 'Testing
'
dest: '{{ output_dir }}/mount_source/test_file'
register: orig_info
- name: Bind mount a directory
mount:
src: '{{ output_dir }}/mount_source'
name: '{{ output_dir }}/mount_dest'
state: mounted
fstype: "{{ 'none' if ansible_system == 'Linux' else 'nullfs' }}"
opts: "{{ 'bind' if ansible_system == 'Linux' else omit }}"
register: bind_result
- name: get checksum for bind mounted file
stat:
path: '{{ output_dir }}/mount_dest/test_file'
when: ansible_system in ('FreeBSD', 'Linux')
register: dest_stat
- name: assert the bind mount was successful
assert:
that:
- bind_result is changed
- dest_stat.stat.exists
- orig_info.checksum == dest_stat.stat.checksum
- name: Bind mount a directory again
mount:
src: '{{ output_dir }}/mount_source'
name: '{{ output_dir }}/mount_dest'
state: mounted
fstype: "{{ 'none' if ansible_system == 'Linux' else 'nullfs' }}"
opts: "{{ 'bind' if ansible_system == 'Linux' else omit }}"
register: bind_result
- name: Make sure we didn't mount a second time
assert:
that:
- bind_result is not changed
- name: Remount directory with different options
mount:
src: '{{ output_dir }}/mount_source'
name: '{{ output_dir }}/mount_dest'
state: mounted
fstype: "{{ 'none' if ansible_system == 'Linux' else 'nullfs' }}"
opts: "{{ 'bind,' if ansible_system == 'Linux' else '' }}ro"
register: bind_result
- name: Get mount options
shell:
cmd: "mount | grep mount_dest | grep -E -w '(ro|read-only)' | wc -l"
register: remount_options
- name: Make sure the filesystem now has the new opts
assert:
that:
- bind_result is changed
- '''1'' in remount_options.stdout'
- 1 == remount_options.stdout_lines | length
- name: Unmount the bind mount
mount:
name: '{{ output_dir }}/mount_dest'
state: absent
register: unmount_result
- name: Check if the file still exists in dest
stat:
path: '{{ output_dir }}/mount_dest/test_file'
register: dest_stat
- name: Assert that we unmounted
assert:
that:
- unmount_result is changed
- not dest_stat.stat.exists