From 1143f34ead08771d44cd64cda9c1b3e9bffbb78a Mon Sep 17 00:00:00 2001 From: Martin Krizek Date: Tue, 16 Oct 2018 09:50:14 +0200 Subject: [PATCH 1/2] yum/dnf: fail when space separated string of names --- lib/ansible/module_utils/yumdnf.py | 9 +++++++++ lib/ansible/modules/packaging/os/dnf.py | 5 +++-- lib/ansible/modules/packaging/os/yum.py | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/ansible/module_utils/yumdnf.py b/lib/ansible/module_utils/yumdnf.py index 21ddf5a5a40f7e..abdd2ab1a6c206 100644 --- a/lib/ansible/module_utils/yumdnf.py +++ b/lib/ansible/module_utils/yumdnf.py @@ -98,6 +98,15 @@ def __init__(self, module): self.enablerepo = self.listify_comma_sep_strings_in_list(self.enablerepo) self.exclude = self.listify_comma_sep_strings_in_list(self.exclude) + # Fail if someone passed a space separated string + # https://github.com/ansible/ansible/issues/46301 + if any((' ' in name for name in self.names)): + module.fail_json( + msg='It appears that a space separated string of packages was passed in ' + 'as an argument. To operate on several packages, pass a comma separated ' + 'string of packages or a list of packages.' + ) + # This should really be redefined by both the yum and dnf module but a # default isn't a bad idea self.lockfile = '/var/run/yum.pid' diff --git a/lib/ansible/modules/packaging/os/dnf.py b/lib/ansible/modules/packaging/os/dnf.py index 77ddaf277c2012..ec9ea430b25d49 100644 --- a/lib/ansible/modules/packaging/os/dnf.py +++ b/lib/ansible/modules/packaging/os/dnf.py @@ -26,9 +26,10 @@ options: name: description: - - "A list of package names, or package specifier with version, like C(name-1.0) + - "A package name or package specifier with version, like C(name-1.0). When using state=latest, this can be '*' which means run: dnf -y update. - You can also pass a url or a local path to a rpm file." + You can also pass a url or a local path to a rpm file. + To operate on several packages this can accept a comma separated string of packages or a list of packages." required: true aliases: - pkg diff --git a/lib/ansible/modules/packaging/os/yum.py b/lib/ansible/modules/packaging/os/yum.py index 2fcc682a455380..93c7dd909a02dc 100644 --- a/lib/ansible/modules/packaging/os/yum.py +++ b/lib/ansible/modules/packaging/os/yum.py @@ -39,7 +39,7 @@ See the C(allow_downgrade) documentation for caveats with downgrading packages. - When using state=latest, this can be C('*') which means run C(yum -y update). - You can also pass a url or a local path to a rpm file (using state=present). - To operate on several packages this can accept a comma separated list of packages or (as of 2.0) a list of packages. + To operate on several packages this can accept a comma separated string of packages or (as of 2.0) a list of packages. aliases: [ pkg ] exclude: description: From 1e0d121698f96b62ba6104643fa662ca94abf126 Mon Sep 17 00:00:00 2001 From: Martin Krizek Date: Wed, 17 Oct 2018 11:01:30 +0200 Subject: [PATCH 2/2] Groups allow spaces in names --- lib/ansible/module_utils/yumdnf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ansible/module_utils/yumdnf.py b/lib/ansible/module_utils/yumdnf.py index abdd2ab1a6c206..05c98844439fff 100644 --- a/lib/ansible/module_utils/yumdnf.py +++ b/lib/ansible/module_utils/yumdnf.py @@ -100,7 +100,7 @@ def __init__(self, module): # Fail if someone passed a space separated string # https://github.com/ansible/ansible/issues/46301 - if any((' ' in name for name in self.names)): + if any((' ' in name and '@' not in name for name in self.names)): module.fail_json( msg='It appears that a space separated string of packages was passed in ' 'as an argument. To operate on several packages, pass a comma separated '