From f96529d20e81ca31831a00d8fd0b20901adab503 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Fri, 24 May 2019 10:52:36 -0400 Subject: [PATCH] warn on systemd globs (#56645) * warn on systemd globs * added note to docs fixes 55476 --- changelogs/fragments/warn_systemd_glob.yml | 2 ++ lib/ansible/modules/system/systemd.py | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/warn_systemd_glob.yml diff --git a/changelogs/fragments/warn_systemd_glob.yml b/changelogs/fragments/warn_systemd_glob.yml new file mode 100644 index 00000000000..3d079feaa9e --- /dev/null +++ b/changelogs/fragments/warn_systemd_glob.yml @@ -0,0 +1,2 @@ +bugfixes: + - warn user when attempting to use service with globs in systemd module. diff --git a/lib/ansible/modules/system/systemd.py b/lib/ansible/modules/system/systemd.py index 10c9e42f253..820c804bc2e 100644 --- a/lib/ansible/modules/system/systemd.py +++ b/lib/ansible/modules/system/systemd.py @@ -83,6 +83,7 @@ notes: - Since 2.4, one of the following options is required 'state', 'enabled', 'masked', 'daemon_reload', ('daemon_reexec' since 2.8), and all except 'daemon_reload' (and 'daemon_reexec' since 2.8) also require 'name'. - Before 2.4 you always required 'name'. + - Globs are not supported in name, i.e ``postgres*.service``. requirements: - A system managed by systemd. ''' @@ -339,6 +340,11 @@ def main(): mutually_exclusive=[['scope', 'user']], ) + unit = module.params['name'] + for globpattern in (r"*", r"?", r"["): + if globpattern in unit: + module.fail_json(msg="This module does not currently support using glob patterns, found '%s' in service name: %s" % (globpattern, unit)) + systemctl = module.get_bin_path('systemctl', True) if os.getenv('XDG_RUNTIME_DIR') is None: @@ -364,7 +370,6 @@ def main(): if module.params['force']: systemctl += " --force" - unit = module.params['name'] rc = 0 out = err = '' result = dict(