From 52d040c689a9eb79ae4d4f68bd0c0ab6b290db73 Mon Sep 17 00:00:00 2001 From: satken2 Date: Sat, 12 Jun 2021 19:24:53 +0900 Subject: [PATCH 01/12] Add mode option for mount module --- plugins/modules/mount.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/plugins/modules/mount.py b/plugins/modules/mount.py index 5c4970d537..3020bb3ffd 100644 --- a/plugins/modules/mount.py +++ b/plugins/modules/mount.py @@ -105,6 +105,17 @@ the original file back if you somehow clobbered it incorrectly. type: bool default: no + mode: + description: + - The permission applied to create a new directory for mount point. + If the mount point already exists, this parameter is not used. + - This parameter only affects to the mount point itself. + If this module creates multiple directories recursively, + other directories follow the system's default umask. + - Note that after running this task and device being successfuly mounted, + the mode of the original directory will be hidden by the target device. + type: raw + required: false notes: - As of Ansible 2.3, the I(name) option has been changed to I(path) as default, but I(name) still works as well. @@ -122,6 +133,7 @@ fstype: iso9660 opts: ro,noauto state: present + mode: 0755 - name: Mount up device by label ansible.posix.mount: @@ -665,6 +677,7 @@ def main(): src=dict(type='path'), backup=dict(type='bool', default=False), state=dict(type='str', required=True, choices=['absent', 'mounted', 'present', 'unmounted', 'remounted']), + mode=dict(type='raw'), ), supports_check_mode=True, required_if=( @@ -761,6 +774,7 @@ def main(): state = module.params['state'] name = module.params['path'] + mode = module.params['mode'] changed = False if state == 'absent': @@ -813,6 +827,9 @@ def main(): if not (ex.errno == errno.EEXIST and os.path.isdir(b_curpath)): raise + if mode is not None: + os.chmod(name, int(mode)) + except (OSError, IOError) as e: module.fail_json( msg="Error making dir %s: %s" % (name, to_native(e))) From dce9f575ffa7a43221a061cfb29414fe54e90c33 Mon Sep 17 00:00:00 2001 From: satken2 Date: Sun, 13 Jun 2021 01:30:51 +0900 Subject: [PATCH 02/12] Add mode option for mount module --- .../fragments/209_add_mode_for_mount.yml | 3 ++ .../integration/targets/mount/tasks/main.yml | 41 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 changelogs/fragments/209_add_mode_for_mount.yml diff --git a/changelogs/fragments/209_add_mode_for_mount.yml b/changelogs/fragments/209_add_mode_for_mount.yml new file mode 100644 index 0000000000..f56dbeef33 --- /dev/null +++ b/changelogs/fragments/209_add_mode_for_mount.yml @@ -0,0 +1,3 @@ +--- +minor_changes: +- mount - add mode option to mount module (https://github.com/ansible-collections/ansible.posix/issues/163). diff --git a/tests/integration/targets/mount/tasks/main.yml b/tests/integration/targets/mount/tasks/main.yml index 44e120b370..7d94fea3d7 100644 --- a/tests/integration/targets/mount/tasks/main.yml +++ b/tests/integration/targets/mount/tasks/main.yml @@ -332,3 +332,44 @@ - /tmp/myfs.img - /tmp/myfs when: ansible_system in ('Linux') + +- name: Block to test mode option in Linux + block: + - name: Create empty file + community.general.filesize: + path: /tmp/myfs.img + size: 20M + - name: Format FS + community.general.filesystem: + fstype: ext3 + dev: /tmp/myfs.img + - name: Make sure that mount point does not exist + file: + path: /tmp/myfs + state: absent + - name: Mount the FS to non existent directory with mode option + mount: + path: /tmp/myfs + src: /tmp/myfs.img + fstype: ext3 + state: mounted + mode: 0000 + - name: Unmount FS to access underlying directory + command: | + umount /tmp/myfs.img + - name: Check status of mount point + stat: + path: /tmp/myfs + register: mount_point_stat + - name: Assert that the mount point has right permission + assert: + that: + - mount_point_stat['stat']['mode'] == '0000' + - name: Remove the test FS + file: + path: '{{ item }}' + state: absent + loop: + - /tmp/myfs.img + - /tmp/myfs + when: ansible_system in ('Linux') From d7735d3cc99a9fc1494051f51e5359e1c4c3569b Mon Sep 17 00:00:00 2001 From: Sato Kenta <33207653+satken2@users.noreply.github.com> Date: Mon, 14 Jun 2021 19:38:13 +0900 Subject: [PATCH 03/12] Fix description of the parameter Co-authored-by: Abhijeet Kasurde --- plugins/modules/mount.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/modules/mount.py b/plugins/modules/mount.py index 3020bb3ffd..d79d8ba8ad 100644 --- a/plugins/modules/mount.py +++ b/plugins/modules/mount.py @@ -107,12 +107,12 @@ default: no mode: description: - - The permission applied to create a new directory for mount point. + - The permission applied to create a new directory for the mount point. If the mount point already exists, this parameter is not used. - - This parameter only affects to the mount point itself. + - This parameter only affects the mount point itself. If this module creates multiple directories recursively, other directories follow the system's default umask. - - Note that after running this task and device being successfuly mounted, + - Note that after running this task and the device being successfully mounted, the mode of the original directory will be hidden by the target device. type: raw required: false From 30c73606dcebd2f9d229665ca3f15f9edb130b5f Mon Sep 17 00:00:00 2001 From: Sato Kenta <33207653+satken2@users.noreply.github.com> Date: Mon, 14 Jun 2021 19:41:00 +0900 Subject: [PATCH 04/12] correct changelog fragment Co-authored-by: Abhijeet Kasurde --- changelogs/fragments/209_add_mode_for_mount.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelogs/fragments/209_add_mode_for_mount.yml b/changelogs/fragments/209_add_mode_for_mount.yml index f56dbeef33..25bdbade87 100644 --- a/changelogs/fragments/209_add_mode_for_mount.yml +++ b/changelogs/fragments/209_add_mode_for_mount.yml @@ -1,3 +1,3 @@ --- minor_changes: -- mount - add mode option to mount module (https://github.com/ansible-collections/ansible.posix/issues/163). +- mount - add ``mode`` parameter to mount module (https://github.com/ansible-collections/ansible.posix/issues/163). From f919496b5e3dbd11d3b5df6cd952472cee794fe6 Mon Sep 17 00:00:00 2001 From: satken2 Date: Mon, 14 Jun 2021 19:47:19 +0900 Subject: [PATCH 05/12] Add version_added parameter to documentation --- changelogs/fragments/209_add_mode_for_mount.yml | 2 +- plugins/modules/mount.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/changelogs/fragments/209_add_mode_for_mount.yml b/changelogs/fragments/209_add_mode_for_mount.yml index f56dbeef33..25bdbade87 100644 --- a/changelogs/fragments/209_add_mode_for_mount.yml +++ b/changelogs/fragments/209_add_mode_for_mount.yml @@ -1,3 +1,3 @@ --- minor_changes: -- mount - add mode option to mount module (https://github.com/ansible-collections/ansible.posix/issues/163). +- mount - add ``mode`` parameter to mount module (https://github.com/ansible-collections/ansible.posix/issues/163). diff --git a/plugins/modules/mount.py b/plugins/modules/mount.py index 3020bb3ffd..2c612d74f5 100644 --- a/plugins/modules/mount.py +++ b/plugins/modules/mount.py @@ -115,7 +115,7 @@ - Note that after running this task and device being successfuly mounted, the mode of the original directory will be hidden by the target device. type: raw - required: false + version_added: '1.3.0' notes: - As of Ansible 2.3, the I(name) option has been changed to I(path) as default, but I(name) still works as well. From d9f85d3ce835d3d36af9af9de7e981b95be1250b Mon Sep 17 00:00:00 2001 From: satken2 Date: Mon, 14 Jun 2021 21:06:59 +0900 Subject: [PATCH 06/12] Add mode option for mount module --- plugins/modules/mount.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/plugins/modules/mount.py b/plugins/modules/mount.py index 7b8fcd64d2..f88a160bf8 100644 --- a/plugins/modules/mount.py +++ b/plugins/modules/mount.py @@ -827,13 +827,18 @@ def main(): if not (ex.errno == errno.EEXIST and os.path.isdir(b_curpath)): raise - if mode is not None: - os.chmod(name, int(mode)) - except (OSError, IOError) as e: module.fail_json( msg="Error making dir %s: %s" % (name, to_native(e))) + # Set permissions to the newly created mount point. + if mode is not None: + try: + changed = module.set_mode_if_different(name, mode, changed) + except Exception as e: + module.fail_json( + msg="Error setting permissions %s: %s" % (name, to_native(e))) + name, backup_lines, changed = _set_mount_save_old(module, args) res = 0 From c14f4d75a6db23813b13ad2e58e075ffab0b5fd6 Mon Sep 17 00:00:00 2001 From: satken2 Date: Sun, 27 Jun 2021 19:56:31 +0900 Subject: [PATCH 07/12] Add umask option for mount module --- plugins/modules/mount.py | 34 ++-- .../integration/targets/mount/tasks/main.yml | 161 +++++++++++++++++- 2 files changed, 176 insertions(+), 19 deletions(-) diff --git a/plugins/modules/mount.py b/plugins/modules/mount.py index f88a160bf8..8d75b4ae32 100644 --- a/plugins/modules/mount.py +++ b/plugins/modules/mount.py @@ -105,13 +105,10 @@ the original file back if you somehow clobbered it incorrectly. type: bool default: no - mode: + umask: description: - - The permission applied to create a new directory for the mount point. + - The permission applied to create new directory(ies) for the mount point. If the mount point already exists, this parameter is not used. - - This parameter only affects the mount point itself. - If this module creates multiple directories recursively, - other directories follow the system's default umask. - Note that after running this task and the device being successfully mounted, the mode of the original directory will be hidden by the target device. type: raw @@ -133,7 +130,7 @@ fstype: iso9660 opts: ro,noauto state: present - mode: 0755 + umask: 0022 - name: Mount up device by label ansible.posix.mount: @@ -677,7 +674,7 @@ def main(): src=dict(type='path'), backup=dict(type='bool', default=False), state=dict(type='str', required=True, choices=['absent', 'mounted', 'present', 'unmounted', 'remounted']), - mode=dict(type='raw'), + umask=dict(type='raw'), ), supports_check_mode=True, required_if=( @@ -774,7 +771,7 @@ def main(): state = module.params['state'] name = module.params['path'] - mode = module.params['mode'] + umask = module.params['umask'] changed = False if state == 'absent': @@ -832,10 +829,27 @@ def main(): msg="Error making dir %s: %s" % (name, to_native(e))) # Set permissions to the newly created mount point. - if mode is not None: + if umask is not None: + # When umask is integer, calculate logical complement of the value + # otherwise, pass it to set_mode_if_different() as is. + if isinstance(umask, int): + directory_mode = 0o0777 & ~umask + else: + try: + umask = int(umask, 8) + directory_mode = 0o0777 & ~umask + except Exception: + directory_mode = umask + try: - changed = module.set_mode_if_different(name, mode, changed) + for dirname in dirs_created: + changed = module.set_mode_if_different(dirname, directory_mode, changed) except Exception as e: + try: + for dirname in dirs_created[::-1]: + os.rmdir(dirname) + except Exception: + pass module.fail_json( msg="Error setting permissions %s: %s" % (name, to_native(e))) diff --git a/tests/integration/targets/mount/tasks/main.yml b/tests/integration/targets/mount/tasks/main.yml index 7d94fea3d7..8d4a85cea8 100644 --- a/tests/integration/targets/mount/tasks/main.yml +++ b/tests/integration/targets/mount/tasks/main.yml @@ -333,43 +333,186 @@ - /tmp/myfs when: ansible_system in ('Linux') -- name: Block to test mode option in Linux +- name: Block to test umask option block: - name: Create empty file community.general.filesize: path: /tmp/myfs.img - size: 20M + size: 1M - name: Format FS community.general.filesystem: fstype: ext3 dev: /tmp/myfs.img + when: ansible_system == 'Linux' + - name: Format FS + community.general.filesystem: + fstype: nullfs + dev: /tmp/myfs.img + when: ansible_system == 'FreeBSD' - name: Make sure that mount point does not exist file: - path: /tmp/myfs + path: /tmp/myfs_mountpoint state: absent - - name: Mount the FS to non existent directory with mode option + + - name: Mount the FS to non existent directory with raw umask mount: - path: /tmp/myfs + path: /tmp/myfs_mountpoint src: /tmp/myfs.img fstype: ext3 state: mounted - mode: 0000 + umask: 0777 + when: ansible_system == 'Linux' + - name: Mount the FS to non existent directory with raw umask(FreeBSD) + mount: + path: /tmp/myfs_mountpoint + src: /tmp/myfs.img + fstype: nullfs + state: mounted + umask: 0777 + when: ansible_system == 'FreeBSD' + - name: Check status of parent directory of mount point + stat: + path: /tmp/foobar + register: parent_dir_stat + - name: Assert that the parent directory of the mount point has right permission + assert: + that: + - parent_dir_stat['stat']['mode'] == '0000' - name: Unmount FS to access underlying directory command: | umount /tmp/myfs.img - name: Check status of mount point stat: - path: /tmp/myfs + path: /tmp/myfs_mountpoint + register: mount_point_stat + - name: Assert that the mount point has right permission + assert: + that: + - mount_point_stat['stat']['mode'] == '0000' + - name: Cleanup directory + file: + path: /tmp/myfs_mountpoint + state: absent + + - name: Mount the FS to non existent directory with string umask + mount: + path: /tmp/myfs_mountpoint + src: /tmp/myfs.img + fstype: ext3 + state: mounted + umask: "0777" + when: ansible_system == 'Linux' + - name: Mount the FS to non existent directory with string umask(FreeBSD) + mount: + path: /tmp/myfs_mountpoint + src: /tmp/myfs.img + fstype: nullfs + state: mounted + umask: "0777" + when: ansible_system == 'FreeBSD' + - name: Check status of parent directory of mount point + stat: + path: /tmp/foobar + register: parent_dir_stat + - name: Assert that the parent directory of the mount point has right permission + assert: + that: + - parent_dir_stat['stat']['mode'] == '0000' + - name: Unmount FS to access underlying directory + command: | + umount /tmp/myfs.img + - name: Check status of mount point + stat: + path: /tmp/myfs_mountpoint register: mount_point_stat - name: Assert that the mount point has right permission assert: that: - mount_point_stat['stat']['mode'] == '0000' + - name: Cleanup directory + file: + path: /tmp/myfs_mountpoint + state: absent + + - name: Remount the FS to non existent directory with symbolic umask expression + mount: + path: /tmp/myfs_mountpoint + src: /tmp/myfs.img + fstype: ext3 + state: mounted + umask: "u+rw,g-wx,o-rwx" + when: ansible_system == 'Linux' + - name: Remount the FS to non existent directory with symbolic umask expression(FreeBSD) + mount: + path: /tmp/myfs_mountpoint + src: /tmp/myfs.img + fstype: nullfs + state: mounted + umask: "u+rw,g-wx,o-rwx" + when: ansible_system == 'FreeBSD' + - name: Check status of parent directory of mount point + stat: + path: /tmp/foobar + register: parent_dir_stat + - name: Assert that the parent directory of the mount point has right permission + assert: + that: + - parent_dir_stat['stat']['mode'] == '0640' + - name: Unmount FS to access underlying directory + command: | + umount /tmp/myfs.img + - name: Check status of mount point + stat: + path: /tmp/myfs_mountpoint + register: mount_point_stat + - name: Assert that the mount point has right permission + assert: + that: + - mount_point_stat['stat']['mode'] == '0640' + - name: Cleanup directory + file: + path: /tmp/myfs_mountpoint + state: absent + + - name: Remount the FS to non existent directory with symbolic umask expression + mount: + path: /tmp/myfs_mountpoint + src: /tmp/myfs.img + fstype: ext3 + state: mounted + umask: "u=rw,g=r,o=r" + when: ansible_system == 'Linux' + - name: Remount the FS to non existent directory with symbolic umask expression(FreeBSD) + mount: + path: /tmp/myfs_mountpoint + src: /tmp/myfs.img + fstype: nullfs + state: mounted + umask: "u=rw,g=r,o=r" + when: ansible_system == 'FreeBSD' + - name: Check status of parent directory of mount point + stat: + path: /tmp/foobar + register: parent_dir_stat + - name: Assert that the parent directory of the mount point has right permission + assert: + that: + - parent_dir_stat['stat']['mode'] == '0644' + - name: Unmount FS to access underlying directory + command: | + umount /tmp/myfs.img + - name: Check status of mount point + stat: + path: /tmp/myfs_mountpoint + register: mount_point_stat + - name: Assert that the mount point has right permission + assert: + that: + - mount_point_stat['stat']['mode'] == '0644' - name: Remove the test FS file: path: '{{ item }}' state: absent loop: - /tmp/myfs.img - - /tmp/myfs - when: ansible_system in ('Linux') + - /tmp/myfs_mountpoint From d6ae0981c5b8c8c612aedc123b9b1fad8b4afe8d Mon Sep 17 00:00:00 2001 From: satken2 Date: Sun, 27 Jun 2021 23:56:42 +0900 Subject: [PATCH 08/12] Add umask option for mount module --- plugins/modules/mount.py | 41 ++-- .../integration/targets/mount/tasks/main.yml | 176 ++++-------------- 2 files changed, 49 insertions(+), 168 deletions(-) diff --git a/plugins/modules/mount.py b/plugins/modules/mount.py index 8d75b4ae32..6e3193d3ba 100644 --- a/plugins/modules/mount.py +++ b/plugins/modules/mount.py @@ -107,7 +107,7 @@ default: no umask: description: - - The permission applied to create new directory(ies) for the mount point. + - The umask to set before creating new directory(ies) for the mount point. If the mount point already exists, this parameter is not used. - Note that after running this task and the device being successfully mounted, the mode of the original directory will be hidden by the target device. @@ -801,8 +801,19 @@ def main(): changed = True elif state == 'mounted': + dirs_created = [] if not os.path.exists(name) and not module.check_mode: + old_umask = None + if umask is not None: + if not isinstance(umask, int): + try: + umask = int(umask, 8) + except ValueError as e: + module.fail_json(msg="umask must be an octal integer: %s" % (to_native(e))) + old_umask = os.umask(umask) + os.umask(umask) + try: # Something like mkdir -p but with the possibility to undo. # Based on some copy-paste from the "file" module. @@ -827,31 +838,9 @@ def main(): except (OSError, IOError) as e: module.fail_json( msg="Error making dir %s: %s" % (name, to_native(e))) - - # Set permissions to the newly created mount point. - if umask is not None: - # When umask is integer, calculate logical complement of the value - # otherwise, pass it to set_mode_if_different() as is. - if isinstance(umask, int): - directory_mode = 0o0777 & ~umask - else: - try: - umask = int(umask, 8) - directory_mode = 0o0777 & ~umask - except Exception: - directory_mode = umask - - try: - for dirname in dirs_created: - changed = module.set_mode_if_different(dirname, directory_mode, changed) - except Exception as e: - try: - for dirname in dirs_created[::-1]: - os.rmdir(dirname) - except Exception: - pass - module.fail_json( - msg="Error setting permissions %s: %s" % (name, to_native(e))) + finally: + if old_umask is not None: + os.umask(old_umask) name, backup_lines, changed = _set_mount_save_old(module, args) res = 0 diff --git a/tests/integration/targets/mount/tasks/main.yml b/tests/integration/targets/mount/tasks/main.yml index 8d4a85cea8..a7daa6cba2 100644 --- a/tests/integration/targets/mount/tasks/main.yml +++ b/tests/integration/targets/mount/tasks/main.yml @@ -335,55 +335,37 @@ - name: Block to test umask option block: - - name: Create empty file - community.general.filesize: - path: /tmp/myfs.img - size: 1M - - name: Format FS - community.general.filesystem: - fstype: ext3 - dev: /tmp/myfs.img - when: ansible_system == 'Linux' - - name: Format FS - community.general.filesystem: - fstype: nullfs - dev: /tmp/myfs.img - when: ansible_system == 'FreeBSD' - name: Make sure that mount point does not exist file: - path: /tmp/myfs_mountpoint + path: /tmp/mount_dest state: absent - - - name: Mount the FS to non existent directory with raw umask + - name: Create a directory to bind mount + file: + state: directory + path: /tmp/mount_source + - name: Bind mount a filesystem with umask mount: - path: /tmp/myfs_mountpoint - src: /tmp/myfs.img - fstype: ext3 + src: /tmp/mount_source + path: /tmp/mount_dest state: mounted + fstype: None + opts: bind umask: 0777 - when: ansible_system == 'Linux' - - name: Mount the FS to non existent directory with raw umask(FreeBSD) + when: ansible_system != 'FreeBSD' + - name: Bind mount a filesystem with umask(FreeBSD) mount: - path: /tmp/myfs_mountpoint - src: /tmp/myfs.img - fstype: nullfs + src: /tmp/mount_source + path: /tmp/mount_dest state: mounted + fstype: nullfs umask: 0777 when: ansible_system == 'FreeBSD' - - name: Check status of parent directory of mount point - stat: - path: /tmp/foobar - register: parent_dir_stat - - name: Assert that the parent directory of the mount point has right permission - assert: - that: - - parent_dir_stat['stat']['mode'] == '0000' - name: Unmount FS to access underlying directory command: | - umount /tmp/myfs.img - - name: Check status of mount point + umount /tmp/mount_dest + - name: Stat mount point directory stat: - path: /tmp/myfs_mountpoint + path: /tmp/mount_dest register: mount_point_stat - name: Assert that the mount point has right permission assert: @@ -391,128 +373,38 @@ - mount_point_stat['stat']['mode'] == '0000' - name: Cleanup directory file: - path: /tmp/myfs_mountpoint + path: /tmp/mount_dest state: absent - - - name: Mount the FS to non existent directory with string umask + - name: Bind mount a filesystem with string umask mount: - path: /tmp/myfs_mountpoint - src: /tmp/myfs.img - fstype: ext3 + src: /tmp/mount_source + path: /tmp/mount_dest state: mounted + fstype: None + opts: bind umask: "0777" - when: ansible_system == 'Linux' - - name: Mount the FS to non existent directory with string umask(FreeBSD) + when: ansible_system != 'FreeBSD' + - name: Bind mount a filesystem with string umask(FreeBSD) mount: - path: /tmp/myfs_mountpoint - src: /tmp/myfs.img - fstype: nullfs + src: /tmp/mount_source + path: /tmp/mount_dest state: mounted + fstype: nullfs umask: "0777" when: ansible_system == 'FreeBSD' - - name: Check status of parent directory of mount point - stat: - path: /tmp/foobar - register: parent_dir_stat - - name: Assert that the parent directory of the mount point has right permission - assert: - that: - - parent_dir_stat['stat']['mode'] == '0000' - name: Unmount FS to access underlying directory command: | - umount /tmp/myfs.img - - name: Check status of mount point + umount /tmp/mount_dest + - name: Stat mount point directory stat: - path: /tmp/myfs_mountpoint + path: /tmp/mount_dest register: mount_point_stat - name: Assert that the mount point has right permission assert: that: - mount_point_stat['stat']['mode'] == '0000' - - name: Cleanup directory - file: - path: /tmp/myfs_mountpoint - state: absent - - - name: Remount the FS to non existent directory with symbolic umask expression - mount: - path: /tmp/myfs_mountpoint - src: /tmp/myfs.img - fstype: ext3 - state: mounted - umask: "u+rw,g-wx,o-rwx" - when: ansible_system == 'Linux' - - name: Remount the FS to non existent directory with symbolic umask expression(FreeBSD) - mount: - path: /tmp/myfs_mountpoint - src: /tmp/myfs.img - fstype: nullfs - state: mounted - umask: "u+rw,g-wx,o-rwx" - when: ansible_system == 'FreeBSD' - - name: Check status of parent directory of mount point - stat: - path: /tmp/foobar - register: parent_dir_stat - - name: Assert that the parent directory of the mount point has right permission - assert: - that: - - parent_dir_stat['stat']['mode'] == '0640' - - name: Unmount FS to access underlying directory - command: | - umount /tmp/myfs.img - - name: Check status of mount point - stat: - path: /tmp/myfs_mountpoint - register: mount_point_stat - - name: Assert that the mount point has right permission - assert: - that: - - mount_point_stat['stat']['mode'] == '0640' - - name: Cleanup directory - file: - path: /tmp/myfs_mountpoint - state: absent - - - name: Remount the FS to non existent directory with symbolic umask expression - mount: - path: /tmp/myfs_mountpoint - src: /tmp/myfs.img - fstype: ext3 - state: mounted - umask: "u=rw,g=r,o=r" - when: ansible_system == 'Linux' - - name: Remount the FS to non existent directory with symbolic umask expression(FreeBSD) - mount: - path: /tmp/myfs_mountpoint - src: /tmp/myfs.img - fstype: nullfs - state: mounted - umask: "u=rw,g=r,o=r" - when: ansible_system == 'FreeBSD' - - name: Check status of parent directory of mount point - stat: - path: /tmp/foobar - register: parent_dir_stat - - name: Assert that the parent directory of the mount point has right permission - assert: - that: - - parent_dir_stat['stat']['mode'] == '0644' - - name: Unmount FS to access underlying directory - command: | - umount /tmp/myfs.img - - name: Check status of mount point - stat: - path: /tmp/myfs_mountpoint - register: mount_point_stat - - name: Assert that the mount point has right permission - assert: - that: - - mount_point_stat['stat']['mode'] == '0644' - name: Remove the test FS file: - path: '{{ item }}' + path: /tmp/mount_dest state: absent - loop: - - /tmp/myfs.img - - /tmp/myfs_mountpoint + when: ansible_system not in ('MacOS') From d2c5f21e8af28433392fe6cf529af93d535ce9a1 Mon Sep 17 00:00:00 2001 From: satken2 Date: Mon, 28 Jun 2021 00:02:09 +0900 Subject: [PATCH 09/12] Add umask option for mount module --- tests/integration/targets/mount/tasks/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/targets/mount/tasks/main.yml b/tests/integration/targets/mount/tasks/main.yml index a7daa6cba2..324e1335b7 100644 --- a/tests/integration/targets/mount/tasks/main.yml +++ b/tests/integration/targets/mount/tasks/main.yml @@ -407,4 +407,4 @@ file: path: /tmp/mount_dest state: absent - when: ansible_system not in ('MacOS') + when: ansible_system not in ('Darwin') From f765706b85653d3fcc8350bdc1d898277efd075d Mon Sep 17 00:00:00 2001 From: satken2 Date: Mon, 28 Jun 2021 01:04:53 +0900 Subject: [PATCH 10/12] Add umask option for mount module --- plugins/modules/mount.py | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/modules/mount.py b/plugins/modules/mount.py index 6e3193d3ba..e2557b7302 100644 --- a/plugins/modules/mount.py +++ b/plugins/modules/mount.py @@ -801,7 +801,6 @@ def main(): changed = True elif state == 'mounted': - dirs_created = [] if not os.path.exists(name) and not module.check_mode: old_umask = None From b7424f470a885680861082cbd7cc94138e6b8f14 Mon Sep 17 00:00:00 2001 From: Sato Kenta <33207653+satken2@users.noreply.github.com> Date: Mon, 28 Jun 2021 12:36:30 +0900 Subject: [PATCH 11/12] Add umask option for mount module Co-authored-by: quidame --- changelogs/fragments/209_add_mode_for_mount.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelogs/fragments/209_add_mode_for_mount.yml b/changelogs/fragments/209_add_mode_for_mount.yml index 25bdbade87..def2f90649 100644 --- a/changelogs/fragments/209_add_mode_for_mount.yml +++ b/changelogs/fragments/209_add_mode_for_mount.yml @@ -1,3 +1,3 @@ --- minor_changes: -- mount - add ``mode`` parameter to mount module (https://github.com/ansible-collections/ansible.posix/issues/163). +- mount - add ``umask`` parameter to control permissions of the directories created by the module (https://github.com/ansible-collections/ansible.posix/issues/163). From 58452777b4310e654a90c24ea346a9e96b3ccad7 Mon Sep 17 00:00:00 2001 From: satken2 Date: Mon, 28 Jun 2021 12:44:04 +0900 Subject: [PATCH 12/12] Add umask option for mount module --- plugins/modules/mount.py | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/modules/mount.py b/plugins/modules/mount.py index e2557b7302..7c12a455cb 100644 --- a/plugins/modules/mount.py +++ b/plugins/modules/mount.py @@ -811,7 +811,6 @@ def main(): except ValueError as e: module.fail_json(msg="umask must be an octal integer: %s" % (to_native(e))) old_umask = os.umask(umask) - os.umask(umask) try: # Something like mkdir -p but with the possibility to undo.