CI: Fix ansible-lint failure

Currently ansible-lint is failing with:

    KeyError: 'hostvars'

This change fixes the issue by making the hostvars key optional. This
should not affect real usage, since an error is raised in this case.

Change-Id: I6dd482e95fa4f5508452d83bb64613d55eb1985f
This commit is contained in:
Mark Goddard 2020-11-24 15:37:18 +00:00
parent 6d1fa48bca
commit c9515e0ca8
1 changed files with 1 additions and 1 deletions

View File

@ -56,7 +56,7 @@ def _get_hostvar(context, var_name, inventory_hostname=None):
if inventory_hostname is None:
namespace = context
else:
if inventory_hostname not in context['hostvars']:
if inventory_hostname not in context.get('hostvars', []):
raise AnsibleFilterError(
"Inventory hostname '%s' not in hostvars" % inventory_hostname)
namespace = context['hostvars'][inventory_hostname]