diff options
author | Matt Martz <matt@sivel.net> | 2022-08-31 17:42:11 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-31 15:42:11 -0700 |
commit | 1cef7245440213b9fe065962b8988977be3544e6 (patch) | |
tree | 996ae366dc72f24bbe5ecf144f51b4a2df7c65c8 /lib | |
parent | 47d34ce582eadd65268a4e212184e671f66bdb2b (diff) | |
download | ansible-1cef7245440213b9fe065962b8988977be3544e6.tar.gz |
[stable-2.13] Fix --role-file arg detection (#78475) (#78522)
* Fix --role-file arg detection. Fixes #78204
* Do not traceback, give better error
* Add coverage for compound shortopts to match -r. Fixes #78491
(cherry picked from commit 86298b7)
Co-authored-by: Matt Martz <matt@sivel.net>
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/ansible/cli/galaxy.py | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/lib/ansible/cli/galaxy.py b/lib/ansible/cli/galaxy.py index 288318aa27..4ab2fe4995 100755 --- a/lib/ansible/cli/galaxy.py +++ b/lib/ansible/cli/galaxy.py @@ -487,7 +487,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') @@ -1315,7 +1320,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) |