Skip to content

Commit

Permalink
more restrictive inventory env vars management
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanCoding committed Mar 12, 2018
1 parent c19bb79 commit 3566140
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion awx/main/management/commands/inventory_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def command_to_json(self, cmd):

if self.tmp_private_dir:
shutil.rmtree(self.tmp_private_dir, True)
if proc.returncode != 0 or 'file not found' in stderr:
if proc.returncode != 0:
raise RuntimeError('%s failed (rc=%d) with stdout:\n%s\nstderr:\n%s' % (
self.method, proc.returncode, stdout, stderr))

Expand Down
8 changes: 8 additions & 0 deletions awx/main/models/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,14 @@ def cloud_credential_validation(source, cred):
)
return None

def get_inventory_plugin_name(self):
if self.source in CLOUD_PROVIDERS or self.source == 'custom':
# TODO: today, all vendored sources are scripts
# in future release inventory plugins will replace these
return 'script'
# in other cases we do not specify which plugin to use
return None

def get_deprecated_credential(self, kind):
for cred in self.credentials.all():
if cred.credential_type.kind == kind:
Expand Down
5 changes: 5 additions & 0 deletions awx/main/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1158,6 +1158,8 @@ def build_env(self, job, **kwargs):
if job.project:
env['PROJECT_REVISION'] = job.project.scm_revision
env['ANSIBLE_RETRY_FILES_ENABLED'] = "False"
env['ANSIBLE_INVENTORY_ENABLED'] = 'script'
env['ANSIBLE_INVENTORY_UNPARSED_FAILED'] = 'True'
env['MAX_EVENT_RES'] = str(settings.MAX_EVENT_RES_DATA)
if not kwargs.get('isolated'):
env['ANSIBLE_CALLBACK_PLUGINS'] = plugin_path
Expand Down Expand Up @@ -1940,6 +1942,9 @@ def build_env(self, inventory_update, **kwargs):
env['INVENTORY_UPDATE_ID'] = str(inventory_update.pk)
# Always use the --export option for ansible-inventory
env['ANSIBLE_INVENTORY_EXPORT'] = str(True)
plugin_name = inventory_update.get_inventory_plugin_name()
if plugin_name is not None:
env['ANSIBLE_INVENTORY_ENABLED'] = plugin_name

# Set environment variables specific to each source.
#
Expand Down

0 comments on commit 3566140

Please sign in to comment.