summaryrefslogtreecommitdiff
path: root/lib/ansible/cli
diff options
context:
space:
mode:
authorMatt Martz <matt@sivel.net>2022-08-11 14:30:00 -0500
committerGitHub <noreply@github.com>2022-08-11 14:30:00 -0500
commit86298b7a47bc7d6f030ca503afa74c896686ab46 (patch)
treea5151a5d918b49144edb8eea878097d03803e0cb /lib/ansible/cli
parent740864869ef589d453ac8cdadd6017e84c1ff6ab (diff)
downloadansible-86298b7a47bc7d6f030ca503afa74c896686ab46.tar.gz
Fix --role-file arg detection (#78475)
* Fix --role-file arg detection. Fixes #78204 * Do not traceback, give better error * Add coverage for compound shortopts to match -r. Fixes #78491
Diffstat (limited to 'lib/ansible/cli')
-rwxr-xr-xlib/ansible/cli/galaxy.py18
1 files changed, 16 insertions, 2 deletions
diff --git a/lib/ansible/cli/galaxy.py b/lib/ansible/cli/galaxy.py
index b2998eab69..f11150f834 100755
--- a/lib/ansible/cli/galaxy.py
+++ b/lib/ansible/cli/galaxy.py
@@ -501,7 +501,12 @@ class GalaxyCLI(CLI):
else:
install_parser.add_argument('-r', '--role-file', dest='requirements',
help='A file containing a list of roles to be installed.')
- if self._implicit_role and ('-r' in self._raw_args or '--role-file' in self._raw_args):
+
+ r_re = re.compile(r'^(?<!-)-[a-zA-Z]*r[a-zA-Z]*') # -r, -fr
+ contains_r = bool([a for a in self._raw_args if r_re.match(a)])
+ role_file_re = re.compile(r'--role-file($|=)') # --role-file foo, --role-file=foo
+ contains_role_file = bool([a for a in self._raw_args if role_file_re.match(a)])
+ if self._implicit_role and (contains_r or contains_role_file):
# Any collections in the requirements files will also be installed
install_parser.add_argument('--keyring', dest='keyring', default=C.GALAXY_GPG_KEYRING,
help='The keyring used during collection signature verification')
@@ -1344,7 +1349,16 @@ class GalaxyCLI(CLI):
ignore_errors = context.CLIARGS['ignore_errors']
no_deps = context.CLIARGS['no_deps']
force_with_deps = context.CLIARGS['force_with_deps']
- disable_gpg_verify = context.CLIARGS['disable_gpg_verify']
+ try:
+ disable_gpg_verify = context.CLIARGS['disable_gpg_verify']
+ except KeyError:
+ if self._implicit_role:
+ raise AnsibleError(
+ 'Unable to properly parse command line arguments. Please use "ansible-galaxy collection install" '
+ 'instead of "ansible-galaxy install".'
+ )
+ raise
+
# If `ansible-galaxy install` is used, collection-only options aren't available to the user and won't be in context.CLIARGS
allow_pre_release = context.CLIARGS.get('allow_pre_release', False)
upgrade = context.CLIARGS.get('upgrade', False)