diff --git a/changelogs/fragments/43931-strip-trailing-comments.yml b/changelogs/fragments/43931-strip-trailing-comments.yml new file mode 100644 index 00000000000..3a32468856d --- /dev/null +++ b/changelogs/fragments/43931-strip-trailing-comments.yml @@ -0,0 +1,2 @@ +bugfixes: + - user - Strip trailing comments in /etc/default/passwd (https://github.com/ansible/ansible/pull/43931) diff --git a/lib/ansible/modules/system/user.py b/lib/ansible/modules/system/user.py index 62e88feb855..9932798415a 100644 --- a/lib/ansible/modules/system/user.py +++ b/lib/ansible/modules/system/user.py @@ -347,6 +347,7 @@ import pwd import shutil import socket import time +import re from ansible.module_utils._text import to_native from ansible.module_utils.basic import load_platform_subclass, AnsibleModule @@ -1496,6 +1497,9 @@ class SunOS(User): line = line.strip() if (line.startswith('#') or line == ''): continue + m = re.match(r'^([^#]*)#(.*)$', line) + if m: # The line contains a hash / comment + line = m.group(1) key, value = line.split('=') if key == "MINWEEKS": minweeks = value.rstrip('\n')