From 41e5b8428f6de9ace84a9639c2157eb57b9916b4 Mon Sep 17 00:00:00 2001 From: Adam Miller Date: Tue, 5 Jan 2021 17:23:15 -0600 Subject: [PATCH 1/7] mount return backup_file Fixes https://github.com/ansible-collections/ansible.posix/issues/126 Signed-off-by: Adam Miller --- .../126_mount_not_returning_backup_file.yml | 2 + plugins/modules/mount.py | 11 +- .../integration/targets/mount/tasks/main.yml | 241 ++++++++---------- 3 files changed, 123 insertions(+), 131 deletions(-) create mode 100644 changelogs/fragments/126_mount_not_returning_backup_file.yml diff --git a/changelogs/fragments/126_mount_not_returning_backup_file.yml b/changelogs/fragments/126_mount_not_returning_backup_file.yml new file mode 100644 index 0000000..b4746f4 --- /dev/null +++ b/changelogs/fragments/126_mount_not_returning_backup_file.yml @@ -0,0 +1,2 @@ +minor_changes: +- mount - returns ``backup_file`` value when a backup fstab is created. diff --git a/plugins/modules/mount.py b/plugins/modules/mount.py index dd7a5c0..e077ccf 100644 --- a/plugins/modules/mount.py +++ b/plugins/modules/mount.py @@ -171,7 +171,6 @@ EXAMPLES = r''' fstype: nfs ''' - import errno import os import platform @@ -184,8 +183,11 @@ from ansible.module_utils.parsing.convert_bool import boolean def write_fstab(module, lines, path): + if module.params['backup']: - module.backup_local(path) + backup_file = module.backup_local(path) + else: + backup_file = "" fs_w = open(path, 'w') @@ -195,6 +197,8 @@ def write_fstab(module, lines, path): fs_w.flush() fs_w.close() + return backup_file + def _escape_fstab(v): """Escape invalid characters in fstab fields. @@ -317,7 +321,7 @@ def _set_mount_save_old(module, args): changed = True if changed and not module.check_mode: - write_fstab(module, to_write, args['fstab']) + args['backup_file'] = write_fstab(module, to_write, args['fstab']) return (args['name'], old_lines, changed) @@ -692,6 +696,7 @@ def main(): if platform.system() == 'FreeBSD': args['opts'] = 'rw' + args['backup_file'] = "" linux_mounts = [] # Cache all mounts here in order we have consistent results if we need to diff --git a/tests/integration/targets/mount/tasks/main.yml b/tests/integration/targets/mount/tasks/main.yml index 7eacc59..56036b8 100644 --- a/tests/integration/targets/mount/tasks/main.yml +++ b/tests/integration/targets/mount/tasks/main.yml @@ -109,128 +109,110 @@ - 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') -- name: Create fstab record with missing last two fields - copy: - dest: /etc/fstab - content: '//nas/photo /home/jik/pictures cifs defaults,credentials=/etc/security/nas.creds,uid=jik,gid=users,forceuid,forcegid,noserverino,_netdev - - ' - when: ansible_system in ('Linux') -- name: Try to change the fstab record with the missing last two fields - mount: - src: //nas/photo - path: /home/jik/pictures - fstype: cifs - opts: defaults,credentials=/etc/security/nas.creds,uid=jik,gid=users,forceuid,forcegid,noserverino,_netdev,x-systemd.mount-timeout=0 - state: present - register: optional_fields_update - when: ansible_system in ('Linux') -- name: Get the content of the fstab file - shell: cat /etc/fstab - register: optional_fields_content - when: ansible_system in ('Linux') -- name: Check if the line containing the missing last two fields was changed - assert: - that: - - optional_fields_update['changed'] - - ''' 0 0'' in optional_fields_content.stdout' - - 1 == optional_fields_content.stdout_lines | length - when: ansible_system in ('Linux') - name: Block to test remounted option block: + - name: Create fstab record for the first swap file + mount: + name: none + src: /tmp/swap1 + opts: sw + fstype: swap + state: present + register: swap1_created + - 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 + - name: Check that we created the swap1 record + assert: + that: + - swap1_created['changed'] + - not swap1_created_again['changed'] + - name: Create fstab record for the second swap file + mount: + name: none + src: /tmp/swap2 + opts: sw + fstype: swap + state: present + register: swap2_created + - 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 + - name: Check that we created the swap2 record + assert: + that: + - swap2_created['changed'] + - not swap2_created_again['changed'] + - name: Remove the fstab record for the first swap file + mount: + name: none + src: /tmp/swap1 + state: absent + register: swap1_removed + - 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 + - name: Check that we removed the swap1 record + assert: + that: + - swap1_removed['changed'] + - not swap1_removed_again['changed'] + - name: Remove the fstab record for the second swap file + mount: + name: none + src: /tmp/swap2 + state: absent + register: swap2_removed + - 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 + - name: Check that we removed the swap2 record + assert: + that: + - swap2_removed['changed'] + - not swap2_removed_again['changed'] + - name: Create fstab record with missing last two fields + copy: + dest: /etc/fstab + content: '//nas/photo /home/jik/pictures cifs defaults,credentials=/etc/security/nas.creds,uid=jik,gid=users,forceuid,forcegid,noserverino,_netdev + + ' + - name: Try to change the fstab record with the missing last two fields + mount: + src: //nas/photo + path: /home/jik/pictures + fstype: cifs + opts: defaults,credentials=/etc/security/nas.creds,uid=jik,gid=users,forceuid,forcegid,noserverino,_netdev,x-systemd.mount-timeout=0 + state: present + register: optional_fields_update + - name: Get the content of the fstab file + shell: cat /etc/fstab + register: optional_fields_content + - name: Check if the line containing the missing last two fields was changed + assert: + that: + - optional_fields_update['changed'] + - ''' 0 0'' in optional_fields_content.stdout' + - 1 == optional_fields_content.stdout_lines | length - name: Create empty file command: dd if=/dev/zero of=/tmp/myfs.img bs=1048576 count=20 - when: ansible_system in ('Linux') - name: Format FS - when: ansible_system in ('Linux') community.general.system.filesystem: fstype: ext3 dev: /tmp/myfs.img @@ -240,44 +222,48 @@ src: /tmp/myfs.img fstype: ext2 state: mounted - when: ansible_system in ('Linux') - name: Get the last write time shell: 'dumpe2fs /tmp/myfs.img 2>/dev/null | grep -i last write time: |cut -d: -f2-' register: last_write_time - when: ansible_system in ('Linux') - name: Wait 2 second pause: seconds: 2 - when: ansible_system in ('Linux') - name: Test if the FS is remounted mount: path: /tmp/myfs state: remounted - when: ansible_system in ('Linux') - name: Get again the last write time shell: 'dumpe2fs /tmp/myfs.img 2>/dev/null | grep -i last write time: |cut -d: -f2-' register: last_write_time2 - when: ansible_system in ('Linux') - name: Fail if they are the same fail: msg: Filesytem was not remounted, testing of the module failed! - when: last_write is defined and last_write_time2 is defined and last_write_time.stdout == last_write_time2.stdout and ansible_system in ('Linux') + when: last_write is defined and last_write_time2 is defined and last_write_time.stdout == last_write_time2.stdout - name: Remount filesystem with different opts using remounted option (Linux only) mount: path: /tmp/myfs state: remounted opts: rw,noexec - when: ansible_system == 'Linux' - name: Get remounted options (Linux only) shell: mount | grep myfs | grep -E -w 'noexec' | wc -l register: remounted_options - when: ansible_system == 'Linux' - name: Make sure the filesystem now has the new opts after using remounted (Linux only) assert: that: - "'1' in remounted_options.stdout" - "1 == remounted_options.stdout_lines | length" - when: ansible_system == 'Linux' + - name: Mount the FS again to test backup + mount: + path: /tmp/myfs + src: /tmp/myfs.img + fstype: ext2 + state: mounted + backup: yes + register: mount_backup_out + - name: ensure backup_file in returned output + assert: + that: + - "'backup_file' in mount_backup_out" always: - name: Umount the test FS mount: @@ -285,7 +271,6 @@ src: /tmp/myfs.img opts: loop state: absent - when: ansible_system in ('Linux') - name: Remove the test FS file: path: '{{ item }}' @@ -293,4 +278,4 @@ loop: - /tmp/myfs.img - /tmp/myfs - when: ansible_system in ('Linux') + when: ansible_system in ('Linux') From 957a7420caf6f90d6de619504ade1cf079781120 Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Wed, 30 Jun 2021 15:26:33 -0700 Subject: [PATCH 2/7] Update main.yml --- tests/integration/targets/mount/tasks/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/integration/targets/mount/tasks/main.yml b/tests/integration/targets/mount/tasks/main.yml index 3747c85..f020f7e 100644 --- a/tests/integration/targets/mount/tasks/main.yml +++ b/tests/integration/targets/mount/tasks/main.yml @@ -226,6 +226,7 @@ - optional_fields_update['changed'] - ''' 0 0'' in optional_fields_content.stdout' - 1 == optional_fields_content.stdout_lines | length + when: ansible_system in ('Linux') - name: Create empty file command: dd if=/dev/zero of=/tmp/myfs.img bs=1048576 count=20 - name: Format FS From 6d51660be467300c3113753be7f4481b030a550d Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Wed, 30 Jun 2021 15:57:39 -0700 Subject: [PATCH 3/7] Update main.yml --- .../integration/targets/mount/tasks/main.yml | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/integration/targets/mount/tasks/main.yml b/tests/integration/targets/mount/tasks/main.yml index f020f7e..3181ec5 100644 --- a/tests/integration/targets/mount/tasks/main.yml +++ b/tests/integration/targets/mount/tasks/main.yml @@ -125,6 +125,7 @@ - unmount_result['changed'] - not dest_stat['stat']['exists'] when: ansible_system in ('FreeBSD', 'Linux') + - name: Block to test remounted option block: - name: Create fstab record for the first swap file @@ -135,6 +136,8 @@ 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 @@ -143,11 +146,15 @@ 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 @@ -156,6 +163,8 @@ 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 @@ -164,51 +173,69 @@ 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') + - name: Create fstab record with missing last two fields copy: dest: /etc/fstab content: '//nas/photo /home/jik/pictures cifs defaults,credentials=/etc/security/nas.creds,uid=jik,gid=users,forceuid,forcegid,noserverino,_netdev ' + when: ansible_system in ('Linux') + - name: Try to change the fstab record with the missing last two fields mount: src: //nas/photo @@ -217,9 +244,13 @@ opts: defaults,credentials=/etc/security/nas.creds,uid=jik,gid=users,forceuid,forcegid,noserverino,_netdev,x-systemd.mount-timeout=0 state: present register: optional_fields_update + when: ansible_system in ('Linux') + - name: Get the content of the fstab file shell: cat /etc/fstab register: optional_fields_content + when: ansible_system in ('Linux') + - name: Check if the line containing the missing last two fields was changed assert: that: @@ -227,6 +258,7 @@ - ''' 0 0'' in optional_fields_content.stdout' - 1 == optional_fields_content.stdout_lines | length when: ansible_system in ('Linux') + - name: Create empty file command: dd if=/dev/zero of=/tmp/myfs.img bs=1048576 count=20 - name: Format FS @@ -329,6 +361,7 @@ mount: path: /tmp/myfs state: absent + when: ansible_system in ('Linux') - name: Remove the test FS file: From 23fadc9f02a9e610d323fa92f9161f74d5ed6461 Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Wed, 30 Jun 2021 16:25:01 -0700 Subject: [PATCH 4/7] Update main.yml --- .../integration/targets/mount/tasks/main.yml | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/integration/targets/mount/tasks/main.yml b/tests/integration/targets/mount/tasks/main.yml index 3181ec5..b5f6f7d 100644 --- a/tests/integration/targets/mount/tasks/main.yml +++ b/tests/integration/targets/mount/tasks/main.yml @@ -1,3 +1,10 @@ +- name: System details + debug: msg="{{ item }}" + with_items: + - "{{ ansible_distribution }}" + - "{{ ansible_system }}" + + - name: Create the mount point file: state: directory @@ -272,36 +279,48 @@ src: /tmp/myfs.img fstype: ext2 state: mounted + - name: Get the last write time shell: 'dumpe2fs /tmp/myfs.img 2>/dev/null | grep -i last write time: |cut -d: -f2-' register: last_write_time + - name: Wait 2 second pause: seconds: 2 + - name: Test if the FS is remounted mount: path: /tmp/myfs state: remounted + - name: Get again the last write time shell: 'dumpe2fs /tmp/myfs.img 2>/dev/null | grep -i last write time: |cut -d: -f2-' register: last_write_time2 + - name: Fail if they are the same fail: msg: Filesytem was not remounted, testing of the module failed! when: last_write is defined and last_write_time2 is defined and last_write_time.stdout == last_write_time2.stdout + - name: Remount filesystem with different opts using remounted option (Linux only) mount: path: /tmp/myfs state: remounted opts: rw,noexec + when: ansible_system == 'Linux' + - name: Get remounted options (Linux only) shell: mount | grep myfs | grep -E -w 'noexec' | wc -l register: remounted_options + when: ansible_system == 'Linux' + - name: Make sure the filesystem now has the new opts after using remounted (Linux only) assert: that: - "'1' in remounted_options.stdout" - "1 == remounted_options.stdout_lines | length" + when: ansible_system == 'Linux' + - name: Mount the FS again to test backup mount: path: /tmp/myfs @@ -310,10 +329,12 @@ state: mounted backup: yes register: mount_backup_out + - name: ensure backup_file in returned output assert: that: - "'backup_file' in mount_backup_out" + always: - name: Umount the test FS mount: @@ -321,6 +342,7 @@ src: /tmp/myfs.img opts: loop state: absent + - name: Remove the test FS file: path: '{{ item }}' From 606e3cfe078b3a74956817655fed35670be08379 Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Wed, 30 Jun 2021 16:52:16 -0700 Subject: [PATCH 5/7] Update main.yml --- tests/integration/targets/mount/tasks/main.yml | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/tests/integration/targets/mount/tasks/main.yml b/tests/integration/targets/mount/tasks/main.yml index b5f6f7d..00ea23f 100644 --- a/tests/integration/targets/mount/tasks/main.yml +++ b/tests/integration/targets/mount/tasks/main.yml @@ -1,10 +1,3 @@ -- name: System details - debug: msg="{{ item }}" - with_items: - - "{{ ansible_distribution }}" - - "{{ ansible_system }}" - - - name: Create the mount point file: state: directory @@ -268,7 +261,9 @@ - name: Create empty file command: dd if=/dev/zero of=/tmp/myfs.img bs=1048576 count=20 + - name: Format FS + when: ansible_system in ('Linux') community.general.system.filesystem: fstype: ext3 dev: /tmp/myfs.img @@ -279,23 +274,28 @@ src: /tmp/myfs.img fstype: ext2 state: mounted + when: ansible_system in ('Linux') - name: Get the last write time shell: 'dumpe2fs /tmp/myfs.img 2>/dev/null | grep -i last write time: |cut -d: -f2-' register: last_write_time + when: ansible_system in ('Linux') - name: Wait 2 second pause: seconds: 2 + when: ansible_system in ('Linux') - name: Test if the FS is remounted mount: path: /tmp/myfs state: remounted + when: ansible_system in ('Linux') - name: Get again the last write time shell: 'dumpe2fs /tmp/myfs.img 2>/dev/null | grep -i last write time: |cut -d: -f2-' register: last_write_time2 + when: ansible_system in ('Linux') - name: Fail if they are the same fail: @@ -329,11 +329,13 @@ state: mounted backup: yes register: mount_backup_out + when: ansible_system in ('Linux') - name: ensure backup_file in returned output assert: that: - "'backup_file' in mount_backup_out" + when: ansible_system in ('Linux') always: - name: Umount the test FS @@ -342,6 +344,7 @@ src: /tmp/myfs.img opts: loop state: absent + when: ansible_system in ('Linux') - name: Remove the test FS file: From dd7d29495d68c82590974f7aa5e701deb968a382 Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Thu, 1 Jul 2021 09:27:04 -0700 Subject: [PATCH 6/7] Clean, use blocks in main.yml --- .../integration/targets/mount/tasks/main.yml | 36 +++---------------- 1 file changed, 5 insertions(+), 31 deletions(-) diff --git a/tests/integration/targets/mount/tasks/main.yml b/tests/integration/targets/mount/tasks/main.yml index 00ea23f..4e91cf5 100644 --- a/tests/integration/targets/mount/tasks/main.yml +++ b/tests/integration/targets/mount/tasks/main.yml @@ -136,7 +136,6 @@ 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: @@ -146,14 +145,12 @@ 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: @@ -163,7 +160,6 @@ 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: @@ -173,14 +169,12 @@ 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: @@ -188,7 +182,6 @@ 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: @@ -196,14 +189,12 @@ 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: @@ -211,7 +202,6 @@ 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: @@ -219,14 +209,12 @@ 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') - name: Create fstab record with missing last two fields copy: @@ -234,7 +222,6 @@ content: '//nas/photo /home/jik/pictures cifs defaults,credentials=/etc/security/nas.creds,uid=jik,gid=users,forceuid,forcegid,noserverino,_netdev ' - when: ansible_system in ('Linux') - name: Try to change the fstab record with the missing last two fields mount: @@ -244,12 +231,10 @@ opts: defaults,credentials=/etc/security/nas.creds,uid=jik,gid=users,forceuid,forcegid,noserverino,_netdev,x-systemd.mount-timeout=0 state: present register: optional_fields_update - when: ansible_system in ('Linux') - name: Get the content of the fstab file shell: cat /etc/fstab register: optional_fields_content - when: ansible_system in ('Linux') - name: Check if the line containing the missing last two fields was changed assert: @@ -257,14 +242,14 @@ - optional_fields_update['changed'] - ''' 0 0'' in optional_fields_content.stdout' - 1 == optional_fields_content.stdout_lines | length - when: ansible_system in ('Linux') - name: Create empty file - command: dd if=/dev/zero of=/tmp/myfs.img bs=1048576 count=20 + community.general.filesize: + path: /tmp/myfs.img + size: 20M - name: Format FS - when: ansible_system in ('Linux') - community.general.system.filesystem: + community.general.filesystem: fstype: ext3 dev: /tmp/myfs.img @@ -274,28 +259,23 @@ src: /tmp/myfs.img fstype: ext2 state: mounted - when: ansible_system in ('Linux') - name: Get the last write time shell: 'dumpe2fs /tmp/myfs.img 2>/dev/null | grep -i last write time: |cut -d: -f2-' register: last_write_time - when: ansible_system in ('Linux') - name: Wait 2 second pause: seconds: 2 - when: ansible_system in ('Linux') - name: Test if the FS is remounted mount: path: /tmp/myfs state: remounted - when: ansible_system in ('Linux') - name: Get again the last write time shell: 'dumpe2fs /tmp/myfs.img 2>/dev/null | grep -i last write time: |cut -d: -f2-' register: last_write_time2 - when: ansible_system in ('Linux') - name: Fail if they are the same fail: @@ -307,19 +287,16 @@ path: /tmp/myfs state: remounted opts: rw,noexec - when: ansible_system == 'Linux' - name: Get remounted options (Linux only) shell: mount | grep myfs | grep -E -w 'noexec' | wc -l register: remounted_options - when: ansible_system == 'Linux' - name: Make sure the filesystem now has the new opts after using remounted (Linux only) assert: that: - "'1' in remounted_options.stdout" - "1 == remounted_options.stdout_lines | length" - when: ansible_system == 'Linux' - name: Mount the FS again to test backup mount: @@ -329,13 +306,11 @@ state: mounted backup: yes register: mount_backup_out - when: ansible_system in ('Linux') - name: ensure backup_file in returned output assert: that: - "'backup_file' in mount_backup_out" - when: ansible_system in ('Linux') always: - name: Umount the test FS @@ -344,7 +319,6 @@ src: /tmp/myfs.img opts: loop state: absent - when: ansible_system in ('Linux') - name: Remove the test FS file: @@ -353,7 +327,7 @@ loop: - /tmp/myfs.img - /tmp/myfs - when: ansible_system in ('Linux') + when: ansible_system in ('Linux') - name: Block to test boot option for Linux block: From ed573a8223cfda5dd9ef123c847fee140b79a6e1 Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Thu, 1 Jul 2021 10:12:33 -0700 Subject: [PATCH 7/7] Clean up main.yml --- tests/integration/targets/mount/tasks/main.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/integration/targets/mount/tasks/main.yml b/tests/integration/targets/mount/tasks/main.yml index 4e91cf5..64d40e5 100644 --- a/tests/integration/targets/mount/tasks/main.yml +++ b/tests/integration/targets/mount/tasks/main.yml @@ -360,7 +360,6 @@ mount: path: /tmp/myfs state: absent - when: ansible_system in ('Linux') - name: Remove the test FS file: @@ -369,4 +368,4 @@ loop: - /tmp/myfs.img - /tmp/myfs - when: ansible_system in ('Linux') + when: ansible_system in ('Linux') \ No newline at end of file