Unverified Commit e2453e1c authored by Yifan Xiong's avatar Yifan Xiong Committed by GitHub
Browse files

Runner - Fix inventory issue in ansible_runner (#185)

__Description__

Fix inventory bug in ansible_runner when host list is provided with multiple hosts.

It ought to be handled by ansible_runner lib, workaround by using `--inventory` arg in cmdline.
parent ab71bbb4
......@@ -23,7 +23,6 @@ def __init__(self, config):
self._playbook_path = Path(__file__).parent / 'playbooks'
self._config = {
'private_data_dir': None,
'inventory': None,
'host_pattern': 'localhost',
'cmdline': '--forks 128',
}
......@@ -33,7 +32,6 @@ def __init__(self, config):
if inventory_list:
inventory_list = inventory_list.strip(',')
if inventory_file or inventory_list:
self._config['inventory'] = inventory_file or inventory_list
self._config['host_pattern'] = 'all'
inventory = InventoryManager(loader=DataLoader(), sources=inventory_file or f'{inventory_list},')
host_list = inventory.get_groups_dict()['all']
......@@ -41,6 +39,7 @@ def __init__(self, config):
self._config['cmdline'] = '--forks {}'.format(len(host_list))
if inventory_list in ['localhost', '127.0.0.1']:
self._config['cmdline'] += ' --connection local'
self._config['cmdline'] += ' --inventory {}'.format(inventory_file or f'{inventory_list},')
username = getattr(config, 'host_username', None)
if username:
self._config['cmdline'] += ' --user {}'.format(username)
......
......@@ -48,9 +48,8 @@ def test_init_config(self):
self.assertDictEqual(
self.ansible_client._config, {
'private_data_dir': None,
'inventory': self.host_file,
'host_pattern': 'all',
'cmdline': '--forks 5 --user user --ask-pass --ask-become-pass',
'cmdline': f'--forks 5 --inventory {self.host_file} --user user --ask-pass --ask-become-pass',
'passwords': {
'password': 'pass',
'passphrase': 'pass',
......@@ -73,9 +72,8 @@ def test_get_shell_config(self):
self.assertDictEqual(
self.ansible_client.get_shell_config(cmd), {
'private_data_dir': None,
'inventory': self.host_file,
'host_pattern': 'all',
'cmdline': '--forks 5 --user user --ask-pass --ask-become-pass',
'cmdline': f'--forks 5 --inventory {self.host_file} --user user --ask-pass --ask-become-pass',
'passwords': {
'password': 'pass',
'passphrase': 'pass',
......@@ -90,9 +88,8 @@ def test_get_playbook_config(self):
self.assertDictEqual(
self.ansible_client.get_playbook_config('play', {'foo': 'bar'}), {
'private_data_dir': None,
'inventory': self.host_file,
'host_pattern': 'all',
'cmdline': '--forks 5 --user user --ask-pass --ask-become-pass',
'cmdline': f'--forks 5 --inventory {self.host_file} --user user --ask-pass --ask-become-pass',
'passwords': {
'password': 'pass',
'passphrase': 'pass',
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment