diff --git a/awx/main/constants.py b/awx/main/constants.py index e7c8a943fc..98802f5ef0 100644 --- a/awx/main/constants.py +++ b/awx/main/constants.py @@ -7,7 +7,7 @@ from django.utils.translation import ugettext_lazy as _ __all__ = [ 'CLOUD_PROVIDERS', 'SCHEDULEABLE_PROVIDERS', 'PRIVILEGE_ESCALATION_METHODS', - 'ANSI_SGR_PATTERN', 'CAN_CANCEL', 'ACTIVE_STATES' + 'ANSI_SGR_PATTERN', 'CAN_CANCEL', 'ACTIVE_STATES', 'STANDARD_INVENTORY_UPDATE_ENV' ] @@ -20,6 +20,12 @@ PRIVILEGE_ESCALATION_METHODS = [ ] CHOICES_PRIVILEGE_ESCALATION_METHODS = [('', _('None'))] + PRIVILEGE_ESCALATION_METHODS ANSI_SGR_PATTERN = re.compile(r'\x1b\[[0-9;]*m') +STANDARD_INVENTORY_UPDATE_ENV = { + # Failure to parse inventory should always be fatal + 'ANSIBLE_INVENTORY_UNPARSED_FAILED': 'True', + # Always use the --export option for ansible-inventory + 'ANSIBLE_INVENTORY_EXPORT': 'True' +} CAN_CANCEL = ('new', 'pending', 'waiting', 'running') ACTIVE_STATES = CAN_CANCEL TOKEN_CENSOR = '************' diff --git a/awx/main/management/commands/inventory_import.py b/awx/main/management/commands/inventory_import.py index 021064a46b..f52cc703ca 100644 --- a/awx/main/management/commands/inventory_import.py +++ b/awx/main/management/commands/inventory_import.py @@ -30,6 +30,7 @@ from awx.main.utils import ( ) from awx.main.utils.mem_inventory import MemInventory, dict_to_mem_data from awx.main.signals import disable_activity_stream +from awx.main.constants import STANDARD_INVENTORY_UPDATE_ENV logger = logging.getLogger('awx.main.commands.inventory_import') @@ -82,7 +83,10 @@ class AnsibleInventoryLoader(object): env = dict(os.environ.items()) env['VIRTUAL_ENV'] = settings.ANSIBLE_VENV_PATH env['PATH'] = os.path.join(settings.ANSIBLE_VENV_PATH, "bin") + ":" + env['PATH'] - env['ANSIBLE_INVENTORY_UNPARSED_FAILED'] = '1' + # Set configuration items that should always be used for updates + for key, value in STANDARD_INVENTORY_UPDATE_ENV.items(): + if key not in env: + env[key] = value venv_libdir = os.path.join(settings.ANSIBLE_VENV_PATH, "lib") env.pop('PYTHONPATH', None) # default to none if no python_ver matches if os.path.isdir(os.path.join(venv_libdir, "python2.7")): diff --git a/awx/main/tasks.py b/awx/main/tasks.py index ffb646856a..5416ed5262 100644 --- a/awx/main/tasks.py +++ b/awx/main/tasks.py @@ -49,7 +49,7 @@ from crum import impersonate # AWX from awx import __version__ as awx_application_version -from awx.main.constants import CLOUD_PROVIDERS, PRIVILEGE_ESCALATION_METHODS +from awx.main.constants import CLOUD_PROVIDERS, PRIVILEGE_ESCALATION_METHODS, STANDARD_INVENTORY_UPDATE_ENV from awx.main.access import access_registry from awx.main.models import * # noqa from awx.main.constants import ACTIVE_STATES @@ -2002,8 +2002,7 @@ class RunInventoryUpdate(BaseTask): # Pass inventory source ID to inventory script. env['INVENTORY_SOURCE_ID'] = str(inventory_update.inventory_source_id) env['INVENTORY_UPDATE_ID'] = str(inventory_update.pk) - # Always use the --export option for ansible-inventory - env['ANSIBLE_INVENTORY_EXPORT'] = str(True) + env.update(STANDARD_INVENTORY_UPDATE_ENV) plugin_name = inventory_update.get_inventory_plugin_name() if plugin_name is not None: env['ANSIBLE_INVENTORY_ENABLED'] = plugin_name