From 76bec48bc911e4b8d3e9f94b9129d4c71dc5cef7 Mon Sep 17 00:00:00 2001 From: Logan V Date: Mon, 4 Jun 2018 18:13:22 -0500 Subject: [PATCH] Update physical host mapping for ansible 2.4+ On ansible 2.4+, when 'ansible_host' is defined in the inventory ini file, the physical host mapping in the strategy plugin works as expected. However, if the ansible_host setting is in host_vars/.yml, then the mapping does not work. Change-Id: I22c09c4de86233329f337b535b709cd5320c40d3 --- strategy/linear.py | 4 +++- tests/host_vars/localhost_alt.yml | 18 ++++++++++++++++++ tests/inventory | 2 +- 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 tests/host_vars/localhost_alt.yml diff --git a/strategy/linear.py b/strategy/linear.py index 67a3a0e4..495c2b3a 100644 --- a/strategy/linear.py +++ b/strategy/linear.py @@ -132,7 +132,9 @@ class StrategyModule(LINEAR.StrategyModule): physical_hosts = groups.get('hosts', groups.get('all', {})) physical_host_addrs = {} for physical_host in physical_hosts: - physical_host_vars = self._inventory.get_host(physical_host).vars + physical_host_vars = self._variable_manager.get_vars( + host=self._inventory.get_host(physical_host) + ) physical_host_addr = physical_host_vars.get('ansible_host', physical_host) physical_host_addrs[physical_host] = physical_host_addr diff --git a/tests/host_vars/localhost_alt.yml b/tests/host_vars/localhost_alt.yml new file mode 100644 index 00000000..d639b9a9 --- /dev/null +++ b/tests/host_vars/localhost_alt.yml @@ -0,0 +1,18 @@ +--- +# Copyright 2018, Logan Vig +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Defining this here instead of the inventory ini file tests +# I22c09c4de86233329f337b535b709cd5320c40d3 +ansible_host: 127.0.0.1 diff --git a/tests/inventory b/tests/inventory index d28bbe2a..f82c6dc4 100644 --- a/tests/inventory +++ b/tests/inventory @@ -7,7 +7,7 @@ container2 # This is used to test I75f9d0f55ecd875caa1bf608a77c92f950b679a1 [hosts] -localhost_alt ansible_host=localhost +localhost_alt [all_containers] container3 physical_host=localhost_alt