mirror of
https://github.com/ansible/awx.git
synced 2026-02-20 04:30:05 -03:30
Merge pull request #2478 from AlanCoding/std_env
Move static inventory update options to constants
This commit is contained in:
@@ -7,7 +7,7 @@ from django.utils.translation import ugettext_lazy as _
|
|||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
'CLOUD_PROVIDERS', 'SCHEDULEABLE_PROVIDERS', 'PRIVILEGE_ESCALATION_METHODS',
|
'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
|
CHOICES_PRIVILEGE_ESCALATION_METHODS = [('', _('None'))] + PRIVILEGE_ESCALATION_METHODS
|
||||||
ANSI_SGR_PATTERN = re.compile(r'\x1b\[[0-9;]*m')
|
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')
|
CAN_CANCEL = ('new', 'pending', 'waiting', 'running')
|
||||||
ACTIVE_STATES = CAN_CANCEL
|
ACTIVE_STATES = CAN_CANCEL
|
||||||
TOKEN_CENSOR = '************'
|
TOKEN_CENSOR = '************'
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ from awx.main.utils import (
|
|||||||
)
|
)
|
||||||
from awx.main.utils.mem_inventory import MemInventory, dict_to_mem_data
|
from awx.main.utils.mem_inventory import MemInventory, dict_to_mem_data
|
||||||
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
|
||||||
|
|
||||||
logger = logging.getLogger('awx.main.commands.inventory_import')
|
logger = logging.getLogger('awx.main.commands.inventory_import')
|
||||||
|
|
||||||
@@ -82,7 +83,10 @@ class AnsibleInventoryLoader(object):
|
|||||||
env = dict(os.environ.items())
|
env = dict(os.environ.items())
|
||||||
env['VIRTUAL_ENV'] = settings.ANSIBLE_VENV_PATH
|
env['VIRTUAL_ENV'] = settings.ANSIBLE_VENV_PATH
|
||||||
env['PATH'] = os.path.join(settings.ANSIBLE_VENV_PATH, "bin") + ":" + env['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")
|
venv_libdir = os.path.join(settings.ANSIBLE_VENV_PATH, "lib")
|
||||||
env.pop('PYTHONPATH', None) # default to none if no python_ver matches
|
env.pop('PYTHONPATH', None) # default to none if no python_ver matches
|
||||||
if os.path.isdir(os.path.join(venv_libdir, "python2.7")):
|
if os.path.isdir(os.path.join(venv_libdir, "python2.7")):
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ from crum import impersonate
|
|||||||
|
|
||||||
# AWX
|
# AWX
|
||||||
from awx import __version__ as awx_application_version
|
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.access import access_registry
|
||||||
from awx.main.models import * # noqa
|
from awx.main.models import * # noqa
|
||||||
from awx.main.constants import ACTIVE_STATES
|
from awx.main.constants import ACTIVE_STATES
|
||||||
@@ -2002,8 +2002,7 @@ class RunInventoryUpdate(BaseTask):
|
|||||||
# Pass inventory source ID to inventory script.
|
# Pass inventory source ID to inventory script.
|
||||||
env['INVENTORY_SOURCE_ID'] = str(inventory_update.inventory_source_id)
|
env['INVENTORY_SOURCE_ID'] = str(inventory_update.inventory_source_id)
|
||||||
env['INVENTORY_UPDATE_ID'] = str(inventory_update.pk)
|
env['INVENTORY_UPDATE_ID'] = str(inventory_update.pk)
|
||||||
# Always use the --export option for ansible-inventory
|
env.update(STANDARD_INVENTORY_UPDATE_ENV)
|
||||||
env['ANSIBLE_INVENTORY_EXPORT'] = str(True)
|
|
||||||
plugin_name = inventory_update.get_inventory_plugin_name()
|
plugin_name = inventory_update.get_inventory_plugin_name()
|
||||||
if plugin_name is not None:
|
if plugin_name is not None:
|
||||||
env['ANSIBLE_INVENTORY_ENABLED'] = plugin_name
|
env['ANSIBLE_INVENTORY_ENABLED'] = plugin_name
|
||||||
|
|||||||
Reference in New Issue
Block a user