From eb64fde88528a00d7c8cd8bb253eac9844f227c5 Mon Sep 17 00:00:00 2001 From: Alan Rominger Date: Wed, 15 Dec 2021 16:20:20 -0500 Subject: [PATCH 1/3] Pass ident to "process" cmd and disable stdout file This requires corresponding ansible-runner changes which are only available in devel branch to do this, requirements are changed to install ansible-runner devel as it did before Revert "Use ansible-runner 2.1.1 build" This reverts commit f0ede010176bd6bfcb45b4fee4194096a91c0003. Add back in change from updater.sh that we want to keep --- awx/main/tasks/jobs.py | 1 + requirements/requirements.in | 5 ++++- requirements/requirements.txt | 5 +++-- requirements/requirements_git.txt | 2 ++ 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/awx/main/tasks/jobs.py b/awx/main/tasks/jobs.py index c1a5baf363..80ebdf171d 100644 --- a/awx/main/tasks/jobs.py +++ b/awx/main/tasks/jobs.py @@ -673,6 +673,7 @@ class BaseTask(object): 'settings': { 'job_timeout': self.get_instance_timeout(self.instance), 'suppress_ansible_output': True, + 'suppress_output_file': True, }, } diff --git a/requirements/requirements.in b/requirements/requirements.in index cc8e2941c7..48ae627caf 100644 --- a/requirements/requirements.in +++ b/requirements/requirements.in @@ -1,5 +1,4 @@ aiohttp -ansible-runner==2.1.1 ansiconv==1.0.0 # UPGRADE BLOCKER: from 2013, consider replacing instead of upgrading asciichartpy autobahn>=20.12.3 # CVE-2020-35678 @@ -61,3 +60,7 @@ uwsgitop wheel pip==21.2.4 # see UPGRADE BLOCKERs setuptools==58.2.0 # see UPGRADE BLOCKERs + +# Temporarily added to use ansible-runner from git branch, to be removed +# when ansible-runner moves from requirements_git.txt to here +pbr diff --git a/requirements/requirements.txt b/requirements/requirements.txt index 6d84bbfc55..637f0dd9e0 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -4,8 +4,7 @@ aiohttp==3.6.2 # via -r /awx_devel/requirements/requirements.in aioredis==1.3.1 # via channels-redis -ansible-runner==2.1.1 - # via -r /awx_devel/requirements/requirements.in + # via -r /awx_devel/requirements/requirements_git.txt ansiconv==1.0.0 # via -r /awx_devel/requirements/requirements.in asciichartpy==1.5.25 @@ -225,6 +224,8 @@ oauthlib==3.1.0 # social-auth-core openshift==0.11.0 # via -r /awx_devel/requirements/requirements.in +pbr==5.6.0 + # via -r /awx_devel/requirements/requirements.in pexpect==4.7.0 # via # -r /awx_devel/requirements/requirements.in diff --git a/requirements/requirements_git.txt b/requirements/requirements_git.txt index 340cbfdcc7..01b668ee18 100644 --- a/requirements/requirements_git.txt +++ b/requirements/requirements_git.txt @@ -1 +1,3 @@ git+https://github.com/ansible/system-certifi.git@devel#egg=certifi +# Remove pbr from requirements.in when moving ansible-runner to requirements.in +git+https://github.com/ansible/ansible-runner.git@devel#egg=ansible-runner From 8fac1c18c8c0ad04d4a32ed3e7f24e883b6e5261 Mon Sep 17 00:00:00 2001 From: Alan Rominger Date: Fri, 7 Jan 2022 11:16:40 -0500 Subject: [PATCH 2/3] Make task logic use consistent artifact dir location --- awx/main/tasks/jobs.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/awx/main/tasks/jobs.py b/awx/main/tasks/jobs.py index 80ebdf171d..51aa89408d 100644 --- a/awx/main/tasks/jobs.py +++ b/awx/main/tasks/jobs.py @@ -403,10 +403,11 @@ class BaseTask(object): Hook for any steps to run after job/task is marked as complete. """ instance.log_lifecycle("finalize_run") - job_profiling_dir = os.path.join(private_data_dir, 'artifacts/playbook_profiling') + artifact_dir = os.path.join(private_data_dir, 'artifacts', str(self.instance.id)) + job_profiling_dir = os.path.join(artifact_dir, 'playbook_profiling') awx_profiling_dir = '/var/log/tower/playbook_profiling/' - collections_info = os.path.join(private_data_dir, 'artifacts/', 'collections.json') - ansible_version_file = os.path.join(private_data_dir, 'artifacts/', 'ansible_version.txt') + collections_info = os.path.join(artifact_dir, 'collections.json') + ansible_version_file = os.path.join(artifact_dir, 'ansible_version.txt') if not os.path.exists(awx_profiling_dir): os.mkdir(awx_profiling_dir) @@ -1160,7 +1161,7 @@ class RunJob(BaseTask): return if job.use_fact_cache: job.finish_job_fact_cache( - os.path.join(private_data_dir, 'artifacts', 'fact_cache'), + os.path.join(private_data_dir, 'artifacts', str(job.id), 'fact_cache'), fact_modification_times, ) @@ -1896,7 +1897,7 @@ class RunInventoryUpdate(BaseTask): return # nothing to save, step out of the way to allow error reporting private_data_dir = inventory_update.job_env['AWX_PRIVATE_DATA_DIR'] - expected_output = os.path.join(private_data_dir, 'artifacts', 'output.json') + expected_output = os.path.join(private_data_dir, 'artifacts', str(inventory_update.id), 'output.json') with open(expected_output) as f: data = json.load(f) From 2609ee5ed0a7b7bbdef4a5ea648297bf527c844d Mon Sep 17 00:00:00 2001 From: Alan Rominger Date: Tue, 18 Jan 2022 14:51:40 -0500 Subject: [PATCH 3/3] Delete artifact dir after transmit phase is finished --- awx/main/tasks/receptor.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/awx/main/tasks/receptor.py b/awx/main/tasks/receptor.py index 0a68800a4d..91151bf3e2 100644 --- a/awx/main/tasks/receptor.py +++ b/awx/main/tasks/receptor.py @@ -4,6 +4,8 @@ from collections import namedtuple import concurrent.futures from enum import Enum import logging +import os +import shutil import socket import sys import threading @@ -330,6 +332,12 @@ class AWXReceptorJob: transmitter_thread.join() + # Artifacts are an output, but sometimes they are an input as well + # this is the case with fact cache, where clearing facts deletes a file, and this must be captured + artifact_dir = os.path.join(self.runner_params['private_data_dir'], 'artifacts') + if os.path.exists(artifact_dir): + shutil.rmtree(artifact_dir) + resultsock, resultfile = receptor_ctl.get_work_results(self.unit_id, return_socket=True, return_sockfile=True) # Both "processor" and "cancel_watcher" are spawned in separate threads. # We wait for the first one to return. If cancel_watcher returns first,