diff --git a/app_setup/templates/local_settings.py.j2 b/app_setup/templates/local_settings.py.j2 index 4e1d9e6cc8..57235a0808 100644 --- a/app_setup/templates/local_settings.py.j2 +++ b/app_setup/templates/local_settings.py.j2 @@ -103,3 +103,7 @@ LOGGING['handlers']['syslog'] = { # 'filename': os.path.join(BASE_DIR, 'awx.log'), # 'formatter': 'simple', #} + +# Define additional environment variables to be passed to subprocess started by +# the celery task. +#AWX_TASK_ENV['FOO'] = 'BAR' diff --git a/awx/main/tasks.py b/awx/main/tasks.py index f759d81eac..f7d1222d06 100644 --- a/awx/main/tasks.py +++ b/awx/main/tasks.py @@ -84,18 +84,21 @@ class RunJob(Task): env = dict(os.environ.items()) # question: when running over CLI, generate a random ID or grab next, etc? # answer: TBD + # Add ANSIBLE_* settings to the subprocess environment. + for attr in dir(settings): + if attr == attr.upper() and attr.startswith('ANSIBLE_'): + env[attr] = str(getattr(settings, attr)) + # Also set environment variables configured in AWX_TASK_ENV setting. + for key, value in settings.AWX_TASK_ENV.items(): + env[key] = str(value) + # Set environment variables needed for inventory and job event + # callbacks to work. env['JOB_ID'] = str(job.pk) env['INVENTORY_ID'] = str(job.inventory.pk) env['ANSIBLE_CALLBACK_PLUGINS'] = plugin_dir - if hasattr(settings, 'ANSIBLE_TRANSPORT'): - env['ANSIBLE_TRANSPORT'] = getattr(settings, 'ANSIBLE_TRANSPORT') + env['ANSIBLE_NOCOLOR'] = '1' # Prevent output of escape sequences. env['REST_API_URL'] = settings.INTERNAL_API_URL env['REST_API_TOKEN'] = job.task_auth_token or '' - env['ANSIBLE_NOCOLOR'] = '1' # Prevent output of escape sequences. - # do not want AWX to ask interactive questions and want it to be friendly with reprovisioning - env['ANSIBLE_HOST_KEY_CHECKING'] = 'False' - # RHEL has too old of an SSH so ansible will select paramiko and this is VERY slow - env['ANSIBLE_PARAMIKO_RECORD_HOST_KEYS'] = 'False' return env def build_args(self, job, **kwargs): diff --git a/awx/settings/defaults.py b/awx/settings/defaults.py index 7dbd7a731d..7edd2d6015 100644 --- a/awx/settings/defaults.py +++ b/awx/settings/defaults.py @@ -245,6 +245,21 @@ CELERYD_TASK_SOFT_TIME_LIMIT = 3540 CELERYBEAT_SCHEDULER = 'djcelery.schedulers.DatabaseScheduler' CELERYBEAT_MAX_LOOP_INTERVAL = 60 +# Any ANSIBLE_* settings will be passed to the subprocess environment by the +# celery task. + +# Do not want AWX to ask interactive questions and want it to be friendly with +# reprovisioning +ANSIBLE_HOST_KEY_CHECKING = False + +# RHEL has too old of an SSH so ansible will select paramiko and this is VERY +# .slow +ANSIBLE_PARAMIKO_RECORD_HOST_KEYS = False + +# Additional environment variables to be passed to the subprocess started by +# the celery task. +AWX_TASK_ENV = {} + if 'devserver' in INSTALLED_APPS: INTERNAL_API_URL = 'http://127.0.0.1:%s' % DEVSERVER_DEFAULT_PORT else: diff --git a/awx/settings/local_settings.py.example b/awx/settings/local_settings.py.example index 99bbf8058d..88c1f5897b 100644 --- a/awx/settings/local_settings.py.example +++ b/awx/settings/local_settings.py.example @@ -105,3 +105,7 @@ LOGGING['handlers']['syslog'] = { # 'filename': os.path.join(BASE_DIR, 'awx.log'), # 'formatter': 'simple', #} + +# Define additional environment variables to be passed to subprocess started by +# the celery task. +#AWX_TASK_ENV['FOO'] = 'BAR' diff --git a/config/awx_supervisor.conf b/config/awx_supervisor.conf index bf5cfe746a..f81156f1d0 100644 --- a/config/awx_supervisor.conf +++ b/config/awx_supervisor.conf @@ -10,5 +10,3 @@ directory = /var/lib/awx log_stderr = true logfile_maxbytes = 50MB logfile_backups = 999 -environment=HOME=/var/lib/awx/,USER=awx - diff --git a/config/deb/settings.py b/config/deb/settings.py index f1f58153c4..50ac050710 100644 --- a/config/deb/settings.py +++ b/config/deb/settings.py @@ -42,6 +42,9 @@ LOGGING['handlers']['syslog'] = { 'formatter': 'simple', } +AWX_TASK_ENV['HOME'] = '/var/lib/awx' +AWX_TASK_ENV['USER'] = 'awx' + SERVER_EMAIL = 'root@localhost' DEFAULT_FROM_EMAIL = 'webmaster@localhost' EMAIL_SUBJECT_PREFIX = '[AnsibleWorks] ' diff --git a/config/rpm/settings.py b/config/rpm/settings.py index f1f58153c4..50ac050710 100644 --- a/config/rpm/settings.py +++ b/config/rpm/settings.py @@ -42,6 +42,9 @@ LOGGING['handlers']['syslog'] = { 'formatter': 'simple', } +AWX_TASK_ENV['HOME'] = '/var/lib/awx' +AWX_TASK_ENV['USER'] = 'awx' + SERVER_EMAIL = 'root@localhost' DEFAULT_FROM_EMAIL = 'webmaster@localhost' EMAIL_SUBJECT_PREFIX = '[AnsibleWorks] '