1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

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

This commit is contained in:
Jiri Tyr 2018-07-31 22:09:38 +01:00 committed by ansibot
parent fd839d7a67
commit c93f24b45b
3 changed files with 118 additions and 2 deletions

View file

@ -0,0 +1,4 @@
---
bugfixes:
- Fix the mount module's handling of swap entries in fstab
(https://github.com/ansible/ansible/pull/42837)

View file

@ -218,7 +218,13 @@ def set_mount(module, args):
) = line.split() ) = line.split()
# Check if we found the correct line # 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) to_write.append(line)
continue continue
@ -299,7 +305,13 @@ def unset_mount(module, args):
ld['passno'] ld['passno']
) = line.split() ) = 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) to_write.append(line)
continue continue

View file

@ -148,3 +148,103 @@
- "unmount_result['changed']" - "unmount_result['changed']"
- "not dest_stat['stat']['exists']" - "not dest_stat['stat']['exists']"
when: ansible_system in ('FreeBSD', 'Linux') 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')