Get rid of ansible version checking

This commit is contained in:
Alan Rominger
2020-08-27 14:23:50 -04:00
committed by Ryan Petrello
parent 03ad1aa141
commit 99aff93930
5 changed files with 11 additions and 38 deletions

View File

@@ -39,7 +39,6 @@ from awx.main.utils import (
build_proot_temp_dir, build_proot_temp_dir,
get_licenser get_licenser
) )
from awx.main.utils.common import _get_ansible_version
from awx.main.signals import disable_activity_stream from awx.main.signals import disable_activity_stream
from awx.main.constants import STANDARD_INVENTORY_UPDATE_ENV from awx.main.constants import STANDARD_INVENTORY_UPDATE_ENV
from awx.main.utils.pglock import advisory_lock from awx.main.utils.pglock import advisory_lock
@@ -136,15 +135,10 @@ class AnsibleInventoryLoader(object):
# inside of /venv/ansible, so we override the specified interpreter # inside of /venv/ansible, so we override the specified interpreter
# https://github.com/ansible/ansible/issues/50714 # https://github.com/ansible/ansible/issues/50714
bargs = ['python', ansible_inventory_path, '-i', self.source] bargs = ['python', ansible_inventory_path, '-i', self.source]
ansible_version = _get_ansible_version(ansible_inventory_path[:-len('-inventory')]) bargs.extend(['--playbook-dir', self.source_dir])
if ansible_version != 'unknown': if self.verbosity:
this_version = Version(ansible_version) # INFO: -vvv, DEBUG: -vvvvv, for inventory, any more than 3 makes little difference
if this_version >= Version('2.5'): bargs.append('-{}'.format('v' * min(5, self.verbosity * 2 + 1)))
bargs.extend(['--playbook-dir', self.source_dir])
if this_version >= Version('2.8'):
if self.verbosity:
# INFO: -vvv, DEBUG: -vvvvv, for inventory, any more than 3 makes little difference
bargs.append('-{}'.format('v' * min(5, self.verbosity * 2 + 1)))
logger.debug('Using base command: {}'.format(' '.join(bargs))) logger.debug('Using base command: {}'.format(' '.join(bargs)))
return bargs return bargs

View File

@@ -1373,10 +1373,6 @@ class PluginFileInjector(object):
collection = None collection = None
collection_migration = '2.9' # Starting with this version, we use collections collection_migration = '2.9' # Starting with this version, we use collections
def __init__(self, ansible_version):
# This is InventoryOptions instance, could be source or inventory update
self.ansible_version = ansible_version
@classmethod @classmethod
def get_proper_name(cls): def get_proper_name(cls):
if cls.plugin_name is None: if cls.plugin_name is None:

View File

@@ -73,7 +73,7 @@ from awx.main.utils import (update_scm_url,
ignore_inventory_group_removal, extract_ansible_vars, schedule_task_manager, ignore_inventory_group_removal, extract_ansible_vars, schedule_task_manager,
get_awx_version) get_awx_version)
from awx.main.utils.ansible import read_ansible_config from awx.main.utils.ansible import read_ansible_config
from awx.main.utils.common import _get_ansible_version, get_custom_venv_choices from awx.main.utils.common import get_custom_venv_choices
from awx.main.utils.external_logging import reconfigure_rsyslog from awx.main.utils.external_logging import reconfigure_rsyslog
from awx.main.utils.safe_yaml import safe_dump, sanitize_jinja from awx.main.utils.safe_yaml import safe_dump, sanitize_jinja
from awx.main.utils.reload import stop_local_services from awx.main.utils.reload import stop_local_services
@@ -841,12 +841,6 @@ class BaseTask(object):
logger.error('Failed to update %s after %d retries.', logger.error('Failed to update %s after %d retries.',
self.model._meta.object_name, _attempt) self.model._meta.object_name, _attempt)
def get_ansible_version(self, instance):
if not hasattr(self, '_ansible_version'):
self._ansible_version = _get_ansible_version(
ansible_path=self.get_path_to_ansible(instance, executable='ansible'))
return self._ansible_version
def get_path_to(self, *args): def get_path_to(self, *args):
''' '''
Return absolute path relative to this file. Return absolute path relative to this file.
@@ -2460,7 +2454,7 @@ class RunInventoryUpdate(BaseTask):
If no private data is needed, return None. If no private data is needed, return None.
""" """
if inventory_update.source in InventorySource.injectors: if inventory_update.source in InventorySource.injectors:
injector = InventorySource.injectors[inventory_update.source](self.get_ansible_version(inventory_update)) injector = InventorySource.injectors[inventory_update.source]()
return injector.build_private_data(inventory_update, private_data_dir) return injector.build_private_data(inventory_update, private_data_dir)
def build_env(self, inventory_update, private_data_dir, isolated, private_data_files=None): def build_env(self, inventory_update, private_data_dir, isolated, private_data_files=None):
@@ -2488,7 +2482,7 @@ class RunInventoryUpdate(BaseTask):
injector = None injector = None
if inventory_update.source in InventorySource.injectors: if inventory_update.source in InventorySource.injectors:
injector = InventorySource.injectors[inventory_update.source](self.get_ansible_version(inventory_update)) injector = InventorySource.injectors[inventory_update.source]()
if injector is not None: if injector is not None:
env = injector.build_env(inventory_update, env, private_data_dir, private_data_files) env = injector.build_env(inventory_update, env, private_data_dir, private_data_files)
@@ -2601,7 +2595,7 @@ class RunInventoryUpdate(BaseTask):
injector = None injector = None
if inventory_update.source in InventorySource.injectors: if inventory_update.source in InventorySource.injectors:
injector = InventorySource.injectors[src](self.get_ansible_version(inventory_update)) injector = InventorySource.injectors[src]()
if injector is not None: if injector is not None:
content = injector.inventory_contents(inventory_update, private_data_dir) content = injector.inventory_contents(inventory_update, private_data_dir)

View File

@@ -1880,13 +1880,6 @@ class TestProjectUpdateCredentials(TestJobExecution):
assert env['FOO'] == 'BAR' assert env['FOO'] == 'BAR'
@pytest.fixture
def mock_ansible_version():
with mock.patch('awx.main.tasks._get_ansible_version', mock.MagicMock(return_value='2.10')) as _fixture:
yield _fixture
@pytest.mark.usefixtures("mock_ansible_version")
class TestInventoryUpdateCredentials(TestJobExecution): class TestInventoryUpdateCredentials(TestJobExecution):
@pytest.fixture @pytest.fixture
def inventory_update(self): def inventory_update(self):

View File

@@ -162,13 +162,14 @@ def memoize_delete(function_name):
return cache.delete(function_name) return cache.delete(function_name)
def _get_ansible_version(ansible_path): @memoize()
def get_ansible_version():
''' '''
Return Ansible version installed. Return Ansible version installed.
Ansible path needs to be provided to account for custom virtual environments Ansible path needs to be provided to account for custom virtual environments
''' '''
try: try:
proc = subprocess.Popen([ansible_path, '--version'], proc = subprocess.Popen(['ansible', '--version'],
stdout=subprocess.PIPE) stdout=subprocess.PIPE)
result = smart_str(proc.communicate()[0]) result = smart_str(proc.communicate()[0])
return result.split('\n')[0].replace('ansible', '').strip() return result.split('\n')[0].replace('ansible', '').strip()
@@ -176,11 +177,6 @@ def _get_ansible_version(ansible_path):
return 'unknown' return 'unknown'
@memoize()
def get_ansible_version():
return _get_ansible_version('ansible')
def get_awx_version(): def get_awx_version():
''' '''
Return AWX version as reported by setuptools. Return AWX version as reported by setuptools.