From 127b854d2c0eda8de6954cc5eac46e6681577c65 Mon Sep 17 00:00:00 2001 From: Adrian Likins Date: Fri, 1 Jul 2016 13:10:32 -0400 Subject: [PATCH] Fix default perm for apt_repo files. (#4072) Change the file mode arg to 'raw' ala file args Following the file_common_args model, change the type of the 'mode' arg here to type='raw' with no default arg value. The default mode for file creation is the module constant DEFAULT_SOURCES_PER, and is used if no mode os specified. A default mode of 0644 (and not specified as int or str) would get converted to an octal 420, resulting in the sources file being created with mode '0420' instead of '0644' Fixes #16370 --- lib/ansible/modules/packaging/os/apt_repository.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/ansible/modules/packaging/os/apt_repository.py b/lib/ansible/modules/packaging/os/apt_repository.py index d8ccf990db1..1a19c12e47a 100644 --- a/lib/ansible/modules/packaging/os/apt_repository.py +++ b/lib/ansible/modules/packaging/os/apt_repository.py @@ -108,6 +108,7 @@ except ImportError: distro = None HAVE_PYTHON_APT = False +DEFAULT_SOURCES_PERM = int('0644', 8) VALID_SOURCE_TYPES = ('deb', 'deb-src') @@ -280,7 +281,7 @@ class SourcesList(object): # allow the user to override the default mode if filename in self.new_repos: - this_mode = self.module.params['mode'] + this_mode = self.module.params.get('mode', DEFAULT_SOURCES_PERM) self.module.set_mode_if_different(filename, this_mode, False) else: del self.files[filename] @@ -452,7 +453,7 @@ def main(): argument_spec=dict( repo=dict(required=True), state=dict(choices=['present', 'absent'], default='present'), - mode=dict(required=False, default=int('0644',8)), + mode=dict(required=False, type='raw'), update_cache = dict(aliases=['update-cache'], type='bool', default='yes'), filename=dict(required=False, default=None), # this should not be needed, but exists as a failsafe @@ -466,6 +467,8 @@ def main(): repo = module.params['repo'] state = module.params['state'] update_cache = module.params['update_cache'] + # Note: mode is referenced in SourcesList class via the passed in module (self here) + sourceslist = None if not HAVE_PYTHON_APT: