mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
This commit is contained in:
parent
fd839d7a67
commit
c93f24b45b
3 changed files with 118 additions and 2 deletions
4
changelogs/fragments/fix-swap-mount-module.yaml
Normal file
4
changelogs/fragments/fix-swap-mount-module.yaml
Normal file
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
bugfixes:
|
||||
- Fix the mount module's handling of swap entries in fstab
|
||||
(https://github.com/ansible/ansible/pull/42837)
|
|
@ -218,7 +218,13 @@ def set_mount(module, args):
|
|||
) = line.split()
|
||||
|
||||
# Check if we found the correct line
|
||||
if ld['name'] != escaped_args['name']:
|
||||
if (
|
||||
ld['name'] != escaped_args['name'] or (
|
||||
# In the case of swap, check the src instead
|
||||
'src' in args and
|
||||
ld['name'] == 'none' and
|
||||
ld['fstype'] == 'swap' and
|
||||
ld['src'] != args['src'])):
|
||||
to_write.append(line)
|
||||
|
||||
continue
|
||||
|
@ -299,7 +305,13 @@ def unset_mount(module, args):
|
|||
ld['passno']
|
||||
) = line.split()
|
||||
|
||||
if ld['name'] != escaped_name:
|
||||
if (
|
||||
ld['name'] != escaped_name or (
|
||||
# In the case of swap, check the src instead
|
||||
'src' in args and
|
||||
ld['name'] == 'none' and
|
||||
ld['fstype'] == 'swap' and
|
||||
ld['src'] != args['src'])):
|
||||
to_write.append(line)
|
||||
|
||||
continue
|
||||
|
|
|
@ -148,3 +148,103 @@
|
|||
- "unmount_result['changed']"
|
||||
- "not dest_stat['stat']['exists']"
|
||||
when: ansible_system in ('FreeBSD', 'Linux')
|
||||
|
||||
- name: Create fstab record for the first swap file
|
||||
mount:
|
||||
name: none
|
||||
src: /tmp/swap1
|
||||
opts: sw
|
||||
fstype: swap
|
||||
state: present
|
||||
register: swap1_created
|
||||
when: ansible_system in ('Linux')
|
||||
|
||||
- name: Try to create fstab record for the first swap file again
|
||||
mount:
|
||||
name: none
|
||||
src: /tmp/swap1
|
||||
opts: sw
|
||||
fstype: swap
|
||||
state: present
|
||||
register: swap1_created_again
|
||||
when: ansible_system in ('Linux')
|
||||
|
||||
- name: Check that we created the swap1 record
|
||||
assert:
|
||||
that:
|
||||
- "swap1_created['changed']"
|
||||
- "not swap1_created_again['changed']"
|
||||
when: ansible_system in ('Linux')
|
||||
|
||||
- name: Create fstab record for the second swap file
|
||||
mount:
|
||||
name: none
|
||||
src: /tmp/swap2
|
||||
opts: sw
|
||||
fstype: swap
|
||||
state: present
|
||||
register: swap2_created
|
||||
when: ansible_system in ('Linux')
|
||||
|
||||
- name: Try to create fstab record for the second swap file again
|
||||
mount:
|
||||
name: none
|
||||
src: /tmp/swap1
|
||||
opts: sw
|
||||
fstype: swap
|
||||
state: present
|
||||
register: swap2_created_again
|
||||
when: ansible_system in ('Linux')
|
||||
|
||||
- name: Check that we created the swap2 record
|
||||
assert:
|
||||
that:
|
||||
- "swap2_created['changed']"
|
||||
- "not swap2_created_again['changed']"
|
||||
when: ansible_system in ('Linux')
|
||||
|
||||
- name: Remove the fstab record for the first swap file
|
||||
mount:
|
||||
name: none
|
||||
src: /tmp/swap1
|
||||
state: absent
|
||||
register: swap1_removed
|
||||
when: ansible_system in ('Linux')
|
||||
|
||||
- name: Try to remove the fstab record for the first swap file again
|
||||
mount:
|
||||
name: none
|
||||
src: /tmp/swap1
|
||||
state: absent
|
||||
register: swap1_removed_again
|
||||
when: ansible_system in ('Linux')
|
||||
|
||||
- name: Check that we removed the swap1 record
|
||||
assert:
|
||||
that:
|
||||
- "swap1_removed['changed']"
|
||||
- "not swap1_removed_again['changed']"
|
||||
when: ansible_system in ('Linux')
|
||||
|
||||
- name: Remove the fstab record for the second swap file
|
||||
mount:
|
||||
name: none
|
||||
src: /tmp/swap2
|
||||
state: absent
|
||||
register: swap2_removed
|
||||
when: ansible_system in ('Linux')
|
||||
|
||||
- name: Try to remove the fstab record for the second swap file again
|
||||
mount:
|
||||
name: none
|
||||
src: /tmp/swap2
|
||||
state: absent
|
||||
register: swap2_removed_again
|
||||
when: ansible_system in ('Linux')
|
||||
|
||||
- name: Check that we removed the swap2 record
|
||||
assert:
|
||||
that:
|
||||
- "swap2_removed['changed']"
|
||||
- "not swap2_removed_again['changed']"
|
||||
when: ansible_system in ('Linux')
|
||||
|
|
Loading…
Reference in a new issue