From bb9c6694a7b9529e7d7e85bd9ac6b84832c18f0e Mon Sep 17 00:00:00 2001 From: Alvaro Aleman Date: Fri, 11 Aug 2017 18:00:59 +0200 Subject: [PATCH] Allow the Openstack dynamic inventory to discover ansible_user (#17944) --- contrib/inventory/openstack.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/contrib/inventory/openstack.py b/contrib/inventory/openstack.py index 38819c33cd..b451f312a0 100755 --- a/contrib/inventory/openstack.py +++ b/contrib/inventory/openstack.py @@ -47,6 +47,9 @@ # has failed (for example, bad credentials or being offline). # When set to False, the inventory will return hosts from # whichever other clouds it can contact. (Default: True) +# +# Also it is possible to pass the correct user by setting an ansible_user: $myuser +# metadata attribute. import argparse import collections @@ -126,6 +129,11 @@ def append_hostvars(hostvars, groups, key, server, namegroup=False): ansible_ssh_host=server['interface_ip'], ansible_host=server['interface_ip'], openstack=server) + + metadata = server.get('metadata', {}) + if 'ansible_user' in metadata: + hostvars[key]['ansible_user'] = metadata['ansible_user'] + for group in get_groups_from_server(server, namegroup=namegroup): groups[group].append(key)