Use connection type supplied from nodepool

For supporting windows nodes we need the connection type to be
configurable. This adds the ansible_connection host variable if
nodepool defines it.

Change-Id: I6d2f81c7586ae0d533add95ea96a9ea8ce8c3ab5
This commit is contained in:
Tobias Henkel 2017-09-08 08:53:47 +02:00 committed by Ricardo Carrillo Cruz
parent 17a4ae8c78
commit c5043212ea
5 changed files with 22 additions and 1 deletions

View File

@ -1432,6 +1432,7 @@ class RecordingAnsibleJob(zuul.executor.server.AnsibleJob):
self.log.debug("hostlist")
hosts = super(RecordingAnsibleJob, self).getHostList(args)
for host in hosts:
if not host['host_vars'].get('ansible_connection'):
host['host_vars']['ansible_connection'] = 'local'
hosts.append(dict(
@ -1738,6 +1739,9 @@ class FakeNodepool(object):
executor='fake-nodepool')
if 'fakeuser' in node_type:
data['username'] = 'fakeuser'
if 'windows' in node_type:
data['connection_type'] = 'winrm'
data = json.dumps(data).encode('utf8')
path = self.client.create(path, data,
makepath=True,

View File

@ -38,6 +38,8 @@
label: default-label
- name: fakeuser
label: fakeuser-label
- name: windows
label: windows-label
- job:
name: base

View File

@ -119,5 +119,15 @@ class TestInventory(ZuulTestCase):
self.assertEqual(
inventory['all']['hosts'][node_name]['ansible_user'], username)
# check if the nodes use the correct or no ansible_connection
if node_name == 'windows':
self.assertEqual(
inventory['all']['hosts'][node_name]['ansible_connection'],
'winrm')
else:
self.assertEqual(
'local',
inventory['all']['hosts'][node_name]['ansible_connection'])
self.executor_server.release()
self.waitUntilSettled()

View File

@ -931,6 +931,10 @@ class AnsibleJob(object):
if username:
host_vars['ansible_user'] = username
connection_type = node.get('connection_type')
if connection_type:
host_vars['ansible_connection'] = connection_type
host_keys = []
for key in node.get('host_keys'):
if port != 22:

View File

@ -384,6 +384,7 @@ class Node(object):
self.private_ipv4 = None
self.public_ipv6 = None
self.connection_port = 22
self.connection_type = None
self._keys = []
self.az = None
self.provider = None