summaryrefslogtreecommitdiff
path: root/cloudinit/distros/__init__.py
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@gmail.com>2012-11-10 10:15:16 -0800
committerJoshua Harlow <harlowja@gmail.com>2012-11-10 10:15:16 -0800
commita17a69c35c1de0a6bd6f054f76d3da9e4a9c5364 (patch)
treea7091c10d9bf07ed3f743a111fecf5a9135fbb98 /cloudinit/distros/__init__.py
parent2c79c14b510751ab455888ab46f70c27b219bd19 (diff)
downloadvyos-cloud-init-a17a69c35c1de0a6bd6f054f76d3da9e4a9c5364.tar.gz
vyos-cloud-init-a17a69c35c1de0a6bd6f054f76d3da9e4a9c5364.zip
Sudoers.d creation cleanups + tests.
Diffstat (limited to 'cloudinit/distros/__init__.py')
-rw-r--r--cloudinit/distros/__init__.py20
1 files changed, 14 insertions, 6 deletions
diff --git a/cloudinit/distros/__init__.py b/cloudinit/distros/__init__.py
index 2d01efc3..d2cb0a8b 100644
--- a/cloudinit/distros/__init__.py
+++ b/cloudinit/distros/__init__.py
@@ -283,8 +283,10 @@ class Distro(object):
# Ensure the dir is included and that
# it actually exists as a directory
sudoers_contents = ''
+ base_exists = False
if os.path.exists(sudo_base):
sudoers_contents = util.load_file(sudo_base)
+ base_exists = True
found_include = False
for line in sudoers_contents.splitlines():
line = line.strip()
@@ -299,18 +301,24 @@ class Distro(object):
found_include = True
break
if not found_include:
- sudoers_contents += "\n#includedir %s\n" % (path)
try:
- if not os.path.exists(sudo_base):
+ if not base_exists:
+ lines = [('# See sudoers(5) for more information'
+ ' on "#include" directives:'), '',
+ '# Added by cloud-init',
+ "#includedir %s" % (path), '']
+ sudoers_contents = "\n".join(lines)
util.write_file(sudo_base, sudoers_contents, 0440)
else:
- with open(sudo_base, 'a') as f:
- f.write(sudoers_contents)
- LOG.debug("added '#includedir %s' to %s" % (path, sudo_base))
+ lines = ['', '# Added by cloud-init',
+ "#includedir %s" % (path), '']
+ sudoers_contents = "\n".join(lines)
+ util.append_file(sudo_base, sudoers_contents)
+ LOG.debug("Added '#includedir %s' to %s" % (path, sudo_base))
except IOError as e:
util.logexc(LOG, "Failed to write %s" % sudo_base, e)
raise e
- util.ensure_dir(path, 0755)
+ util.ensure_dir(path, 0750)
def write_sudo_rules(self,
user,