diff --git a/tripleo_common/actions/ansible.py b/tripleo_common/actions/ansible.py index 249d11eda..2db6020b4 100644 --- a/tripleo_common/actions/ansible.py +++ b/tripleo_common/actions/ansible.py @@ -30,7 +30,7 @@ from mistral_lib import actions from oslo_concurrency import processutils from tripleo_common.actions import base -from tripleo_common.inventory import TripleoInventory +from tripleo_common import inventory LOG = logging.getLogger(__name__) @@ -634,7 +634,7 @@ class AnsibleGenerateInventoryAction(base.TripleOAction): inventory_path = os.path.join( self.work_dir, 'tripleo-ansible-inventory.yaml') - inventory = TripleoInventory( + inv = inventory.TripleoInventory( session=self.get_session(context, 'heat'), hclient=self.get_orchestration_client(context), auth_url=context.security.auth_uri, @@ -642,9 +642,10 @@ class AnsibleGenerateInventoryAction(base.TripleOAction): project_name=context.security.project_name, username=context.security.user_name, ansible_ssh_user=self.ansible_ssh_user, + undercloud_connection=inventory.UNDERCLOUD_CONNECTION_SSH, ansible_python_interpreter=self.ansible_python_interpreter, plan_name=self.plan_name, host_network=self.ssh_network) - inventory.write_static_inventory(inventory_path) + inv.write_static_inventory(inventory_path) return inventory_path diff --git a/tripleo_common/inventory.py b/tripleo_common/inventory.py index 2341384bd..9180b3394 100644 --- a/tripleo_common/inventory.py +++ b/tripleo_common/inventory.py @@ -24,6 +24,10 @@ from heatclient.exc import HTTPNotFound HOST_NETWORK = 'ctlplane' +UNDERCLOUD_CONNECTION_SSH = 'ssh' + +UNDERCLOUD_CONNECTION_LOCAL = 'local' + class TemplateDumper(yaml.SafeDumper): def represent_ordered_dict(self, data): @@ -87,7 +91,8 @@ class TripleoInventory(object): def __init__(self, session=None, hclient=None, plan_name=None, auth_url=None, project_name=None, cacert=None, username=None, ansible_ssh_user=None, - host_network=None, ansible_python_interpreter=None): + host_network=None, ansible_python_interpreter=None, + undercloud_connection=UNDERCLOUD_CONNECTION_LOCAL): self.session = session self.hclient = hclient self.hosts_format_dict = False @@ -101,6 +106,7 @@ class TripleoInventory(object): self.ansible_python_interpreter = ansible_python_interpreter self.stack_outputs = StackOutputs(self.plan_name, self.hclient) self.hostvars = {} + self.undercloud_connection = undercloud_connection @staticmethod def get_roles_by_service(enabled_services): @@ -150,8 +156,8 @@ class TripleoInventory(object): 'hosts': self._hosts(['undercloud']), 'vars': { 'ansible_host': 'localhost', - 'ansible_ssh_user': self.ansible_ssh_user, 'ansible_python_interpreter': sys.executable, + 'ansible_connection': self.undercloud_connection, # see https://github.com/ansible/ansible/issues/41808 'ansible_remote_tmp': '/tmp/ansible-${USER}', 'auth_url': self.auth_url, @@ -169,6 +175,10 @@ class TripleoInventory(object): ret['Undercloud']['vars']['ansible_python_interpreter'] = \ self.ansible_python_interpreter + if self.undercloud_connection == UNDERCLOUD_CONNECTION_SSH: + ret['Undercloud']['vars']['ansible_ssh_user'] = \ + self.ansible_ssh_user + swift_url = None if self.session: swift_url = self.session.get_endpoint(service_type='object-store', diff --git a/tripleo_common/tests/test_inventory.py b/tripleo_common/tests/test_inventory.py index 451bf8267..bc5c0b33d 100644 --- a/tripleo_common/tests/test_inventory.py +++ b/tripleo_common/tests/test_inventory.py @@ -170,6 +170,7 @@ class TestInventory(base.TestCase): set([o for o in self.outputs])) def test_inventory_list(self): + self.inventory.undercloud_connection = 'local' self._inventory_list(self.inventory) def _inventory_list(self, inventory): @@ -198,7 +199,7 @@ class TestInventory(base.TestCase): 'redis_vip': 'x.x.x.6'}}, 'Undercloud': { 'hosts': ['undercloud'], - 'vars': {'ansible_ssh_user': 'heat-admin', + 'vars': {'ansible_connection': 'local', 'ansible_host': 'localhost', 'ansible_python_interpreter': sys.executable, 'ansible_remote_tmp': '/tmp/ansible-${USER}', @@ -225,14 +226,17 @@ class TestInventory(base.TestCase): def test_ansible_ssh_user(self): self._try_alternative_args( ansible_ssh_user='my-custom-admin', + undercloud_connection='ssh', session=self.session,) def test_no_session(self): self._try_alternative_args( ansible_ssh_user='my-custom-admin', + undercloud_connection='ssh', session=None) - def _try_alternative_args(self, ansible_ssh_user, session): + def _try_alternative_args(self, ansible_ssh_user, session, + undercloud_connection): self.inventory = TripleoInventory( session=session, hclient=self.hclient, @@ -242,6 +246,7 @@ class TestInventory(base.TestCase): username='admin', cacert='acacert', ansible_ssh_user=ansible_ssh_user, + undercloud_connection=undercloud_connection, ansible_python_interpreter='foo') self.inventory.stack_outputs = self.outputs @@ -272,7 +277,8 @@ class TestInventory(base.TestCase): 'redis_vip': 'x.x.x.6'}}, 'Undercloud': { 'hosts': ['undercloud'], - 'vars': {'ansible_ssh_user': 'my-custom-admin', + 'vars': {'ansible_connection': 'ssh', + 'ansible_ssh_user': 'my-custom-admin', 'ansible_host': 'localhost', 'ansible_python_interpreter': 'foo', 'ansible_remote_tmp': '/tmp/ansible-${USER}', @@ -300,9 +306,11 @@ class TestInventory(base.TestCase): self.assertEqual(expected[k], inv_list[k]) def test_inventory_write_static(self): + self.inventory.undercloud_connection = 'local' self._inventory_write_static() def test_inventory_write_static_extra_vars(self): + self.inventory.undercloud_connection = 'local' extra_vars = {'Undercloud': {'anextravar': 123}} self._inventory_write_static(extra_vars=extra_vars) @@ -370,7 +378,7 @@ class TestInventory(base.TestCase): 'sh': {'children': {'CustomRole': {}}, 'vars': {'ansible_ssh_user': 'heat-admin'}}, 'Undercloud': {'hosts': {'undercloud': {}}, - 'vars': {'ansible_ssh_user': 'heat-admin', + 'vars': {'ansible_connection': 'local', 'ansible_host': 'localhost', 'ansible_python_interpreter': sys.executable,