Fix for creation and removal of swap record in fstab (fixes #42706, #31437 and #30090) (#42837)

pull/43522/head
Jiri Tyr 6 years ago committed by ansibot
parent fd839d7a67
commit c93f24b45b

@ -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…
Cancel
Save