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(