ansible-galaxy - Fix role info when role is not installed (#69924)
* ansible-galaxy - Fix role info when role is not installed Only report the role not found if in offline mode, otherwise query the galaxy API to get role information. Fixes #69867 * Improve error message when role is not found in Ansible Galaxy
This commit is contained in:
parent
32c392e622
commit
3815ed67d5
2 changed files with 28 additions and 7 deletions
|
@ -927,9 +927,6 @@ class GalaxyCLI(CLI):
|
||||||
|
|
||||||
role_info = {'path': roles_path}
|
role_info = {'path': roles_path}
|
||||||
gr = GalaxyRole(self.galaxy, self.api, role)
|
gr = GalaxyRole(self.galaxy, self.api, role)
|
||||||
if not gr._exists:
|
|
||||||
data = u"- the role %s was not found" % role
|
|
||||||
break
|
|
||||||
|
|
||||||
install_info = gr.install_info
|
install_info = gr.install_info
|
||||||
if install_info:
|
if install_info:
|
||||||
|
@ -938,13 +935,25 @@ class GalaxyCLI(CLI):
|
||||||
del install_info['version']
|
del install_info['version']
|
||||||
role_info.update(install_info)
|
role_info.update(install_info)
|
||||||
|
|
||||||
remote_data = False
|
|
||||||
if not context.CLIARGS['offline']:
|
if not context.CLIARGS['offline']:
|
||||||
|
remote_data = None
|
||||||
|
try:
|
||||||
remote_data = self.api.lookup_role_by_name(role, False)
|
remote_data = self.api.lookup_role_by_name(role, False)
|
||||||
|
except AnsibleError as e:
|
||||||
|
if e.http_code == 400 and 'Bad Request' in e.message:
|
||||||
|
# Role does not exist in Ansible Galaxy
|
||||||
|
data = u"- the role %s was not found" % role
|
||||||
|
break
|
||||||
|
|
||||||
|
raise AnsibleError("Unable to find info about '%s': %s" % (role, e))
|
||||||
|
|
||||||
if remote_data:
|
if remote_data:
|
||||||
role_info.update(remote_data)
|
role_info.update(remote_data)
|
||||||
|
|
||||||
|
elif context.CLIARGS['offline'] and not gr._exists:
|
||||||
|
data = u"- the role %s was not found" % role
|
||||||
|
break
|
||||||
|
|
||||||
if gr.metadata:
|
if gr.metadata:
|
||||||
role_info.update(gr.metadata)
|
role_info.update(gr.metadata)
|
||||||
|
|
||||||
|
|
|
@ -226,6 +226,18 @@ rm -fr "${role_testdir}"
|
||||||
|
|
||||||
# Galaxy role info tests
|
# Galaxy role info tests
|
||||||
|
|
||||||
|
# Get info about role that is not installed
|
||||||
|
|
||||||
|
f_ansible_galaxy_status "role info"
|
||||||
|
galaxy_testdir=$(mktemp -d)
|
||||||
|
pushd "${galaxy_testdir}"
|
||||||
|
ansible-galaxy role info samdoran.fish | tee out.txt
|
||||||
|
|
||||||
|
[[ $(grep -c 'not found' out.txt ) -eq 0 ]]
|
||||||
|
[[ $(grep -c 'Role:.*samdoran\.fish' out.txt ) -eq 1 ]]
|
||||||
|
|
||||||
|
popd # ${galaxy_testdir}
|
||||||
|
|
||||||
f_ansible_galaxy_status \
|
f_ansible_galaxy_status \
|
||||||
"role info non-existant role"
|
"role info non-existant role"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue