2

I'm trying to get STDOUT and STDERR of a specific task from the PostgreSQL database to use it in a commit comment.

I have difficulty with finding the right table. Has anyone tried to get a specific task results, STDOUT and STDERR from Ansible Tower/AWX?

Am I barking at the right tree?

U880D
  • 8,601
  • 6
  • 24
  • 40
MMT
  • 1,931
  • 3
  • 19
  • 35

3 Answers3

1

every task has its own output in the column stdout of the table main_jobevent.

prepare awx (text, int) as
select job_id, host_name, modified, playbook, play, role, stdout
  from main_jobevent
 where host_name = ANY (string_to_array($1, ','))
   and changed
 order by modified desc
 limit $2;

execute awx( 'localhost,192.168.1.1', 3 );

this shows the three youngest modifications of the host localhost or 192.168.1.1.

maletin
  • 585
  • 4
  • 14
0

Use the Ansible tower API to get the job stdout. Eg: https:///api/v2/jobs//stdout/?format=json

Check Ansible Tower API doc https://docs.ansible.com/ansible-tower/3.2.4/pdf/AnsibleTowerAPIGuide.pdf

Raaghu
  • 36
  • 3
0

According the Tower API Reference Guide Jobs it is possible to get the full job result log via REST API call as plain text, in example

curl --silent -u ${TOWER_USER}:${TOWER_PASSWORD} -JL https://${TOWER_URL}/api/v2/jobs/${JobID}/stdout?format=txt_download -o job_${JobID}.log

resulting into the output of a file called job_${JobID}.log. But there is no direct call for specific tasks of job.

As in maletin's answer already mentioned, one could gather specific task information from a job by JobID

SELECT job_id, host_name, modified, stdout
FROM main_jobevent 
WHERE job_id = $1
ORDER BY modified ASC;

but it looks like ANSI colored text.

U880D
  • 8,601
  • 6
  • 24
  • 40