How to save stdout at awx-host filesystem

838 views
Skip to first unread message

Guilherme Torres

unread,
Apr 11, 2022, 1:11:17 PM4/11/22
to AWX Project
Hello,
I'm trying to save an output of switch configuration at my awx-host filesystem without success. I'm using awx 20. It used to work at awx 17 version. Now, it seems that the playbook is trying to create the file at a "temporary" pod that exists only at execution time.

Sample of playbook:
---
- name: IOS ROUTERS
  hosts: all
  gather_facts: false
  connection: local

  tasks:
    - name: IOS CONFIG
      ios_command:
        commands: show version
      register: output_router
      when: ansible_network_os == 'ios'

    - name: SAVE IOS CONFIG
      delegate_to: localhost
      copy:
        content: "{{ output_router.stdout[0] }}"
        dest: "/tmp/output.txt"
       
 Below you can see part of debug. There is no user runner at my awx-host.        

TASK [SAVE IOS CONFIG] *********************************************************
task path: /runner/project/backup_ios_teste.yml:15
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: runner
<localhost> EXEC /bin/sh -c 'echo ~runner && sleep 0'
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/runner/.ansible/tmp `"&& mkdir

Even if I put the IP of awx-host like "delegate_to: <IP>" the output of debug is the same.

Thanks for any help!

yeowtiong tan

unread,
Apr 16, 2023, 10:05:57 AM4/16/23
to AWX Project
Anyone got a solution to this so far?

I am also trying to solve this issue....
Thx!

Avinash Jadhav

unread,
Apr 16, 2023, 10:36:08 AM4/16/23
to awx-p...@googlegroups.com

Replace "/path/to/awx-host/filesystem" with the actual path to the directory where you want to save the output file.

Alternatively, you could use the "copy" module to copy the output file from the temporary pod to the AWX host's filesystem.

- name: Save switch configuration shell: command to save switch configuration > switch_config.txt delegate_to: localhost register: switch_config_output - name: Copy switch configuration output to AWX host copy: content: "{{ switch_config_output.stdout }}" dest: /path/to/awx-host/filesystem/switch_config.txt



--
You received this message because you are subscribed to the Google Groups "AWX Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to awx-project...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/awx-project/cace5f48-9a3c-44c8-aa50-359198bac382n%40googlegroups.com.

yeowtiong tan

unread,
Apr 16, 2023, 11:50:28 AM4/16/23
to AWX Project
Hi

 Thanks for your reply. As i pretty new to this, i like to share my setup. Basically i have setup a custom execution image and loaded into a docker on localhost. My AWX is installed on Ks3.

In my playbook, I have this:

- name: cisco_sh_ver
  hosts: awx-cisco-ios-r1 [This is a cisco router]
  gather_facts: true

  tasks:
    - name: run show ip interface brief on remote devices
      ios_command:
        commands: show ip interface brief
      register: ip_int_output

    - name: Print IP Interface brief
      debug:
        var: ip_int_output.stdout_lines

    - name: set fact for date and time
      shell: date +"%Y-%m-%d-%H-%M"
      register: date_time

    - name: save IP Interface brief to file
      delegate_to: localhost
      copy:
        content: "{{ ip_int_output.stdout }}"
        dest: "/runner/project/ip_interface_brief_{{ date_time.stdout }}.txt"

But once i run the job template from AWX, although successful i cannot find the file at all.

<localhost> EXEC /bin/sh -c '/usr/bin/python3 /root/.ansible/tmp/ansible-tmp-1681660001.381904-78-44273424326509/AnsiballZ_stat.py && sleep 0'
<localhost> PUT /home/runner/.ansible/tmp/ansible-local-191tqi55nq/tmpu8el6gja TO /root/.ansible/tmp/ansible-tmp-1681660001.381904-78-44273424326509/source
<localhost> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1681660001.381904-78-44273424326509/ /root/.ansible/tmp/ansible-tmp-1681660001.381904-78-44273424326509/source && sleep 0'
Using module file /usr/local/lib/python3.8/site-packages/ansible/modules/copy.py
<localhost> PUT /home/runner/.ansible/tmp/ansible-local-191tqi55nq/tmpxu921f4m TO /root/.ansible/tmp/ansible-tmp-1681660001.381904-78-44273424326509/AnsiballZ_copy.py
<localhost> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1681660001.381904-78-44273424326509/ /root/.ansible/tmp/ansible-tmp-1681660001.381904-78-44273424326509/AnsiballZ_copy.py && sleep 0'
<localhost> EXEC /bin/sh -c '/usr/bin/python3 /root/.ansible/tmp/ansible-tmp-1681660001.381904-78-44273424326509/AnsiballZ_copy.py && sleep 0'
<localhost> EXEC /bin/sh -c 'rm -f -r /root/.ansible/tmp/ansible-tmp-1681660001.381904-78-44273424326509/ > /dev/null 2>&1 && sleep 0'
changed: [awx-cisco-ios-r1 -> localhost] => {
    "changed": true,
    "checksum": "f41d04c0206136d7feca531350a1b4fce31d5e5d",
    "dest": "/runner/project/ip_interface_brief_2023-04-16-15-46.txt",
    "diff": [],
    "gid": 0,
    "group": "root",
    "invocation": {
        "module_args": {
            "_original_basename": "tmpu8el6gja",
            "attributes": null,
            "backup": false,
            "checksum": "f41d04c0206136d7feca531350a1b4fce31d5e5d",
            "content": null,
            "dest": "/runner/project/ip_interface_brief_2023-04-16-15-46.txt",
            "directory_mode": null,
            "follow": false,
            "force": true,
            "group": null,
            "local_follow": null,
            "mode": null,
     …
META: ran handlers
META: ran handlers

AWX Project

unread,
Apr 19, 2023, 2:56:40 PM4/19/23
to AWX Project
On AWX the jobs are running a pod separate from the control plane, so files saved in the pod filesystem would likely get cleaned up after the job runs.

You can use the settings Paths to expose to isolated jobs, which allows you to mount folders on the control node to the running pods. Then in your playbook you can write the files to that location


AWX Team

yeowtiong tan

unread,
Apr 20, 2023, 9:36:25 AM4/20/23
to awx-p...@googlegroups.com
Hi AWX team,

 Thanks for sharing. I am currently running AWX version 22. Under job settings, I dont see exposed host path for container group this option. I tried to specify my ubuntu path under Paths to expose to isolated jobs

image.png
However, though the playbook is successful, but I couldnt get the studout file.

I have changed ownership to root for both user and group but not really help.

Seek your advice again,.

Tracelog:
changed: [awx-cisco-ios-r1] => {

    "changed": true,
    "checksum": "f41d04c0206136d7feca531350a1b4fce31d5e5d",
    "dest": "/tmp/ip_interface_brief.txt",
    "diff": [
        {
            "after": "[\"Interface                  IP-Address      OK? Method Status                Protocol\\nFastEthernet0/0            192.168.11.60   YES NVRAM  up                    up      \\nSerial0/0                  unassigned      YES NVRAM  administratively down down    \\nFastEthernet0/1            unassigned      YES NVRAM  administratively down down    \\nSerial0/1                  unassigned      YES NVRAM  administratively down down    \\nSerial0/2                  unassigned      YES NVRAM  administratively down down    \\nFastEthernet1/0            unassigned      YES NVRAM  administratively down down    \\nSerial2/0                  unassigned      YES NVRAM  administratively down down    \\nSerial2/1                  unassigned     …
TASK [fetch file from remote device to local Ubuntu machine] *******************
task path: /runner/project/fetch4.yml:23
redirecting (type: connection) ansible.builtin.network_cli to ansible.netcommon.network_cli
redirecting (type: terminal) ansible.builtin.ios to cisco.ios.ios
redirecting (type: cliconf) ansible.builtin.ios to cisco.ios.ios
<192.168.11.60> ESTABLISH LOCAL CONNECTION FOR USER: root
<192.168.11.60> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/runner/.ansible/tmp/ansible-local-19ah400x6z `"&& mkdir "` echo /home/runner/.ansible/tmp/ansible-local-19ah400x6z/ansible-tmp-1681997446.7857811-88-241249696992527 `" && echo ansible-tmp-1681997446.7857811-88-241249696992527="` echo /home/runner/.ansible/tmp/ansible-local-19ah400x6z/ansible-tmp-1681997446.7857811-88-241249696992527 `" ) && sleep 0'
Using module file /usr/local/lib/python3.8/site-packages/ansible/modules/stat.py
<192.168.11.60> PUT /home/runner/.ansible/tmp/ansible-local-19ah400x6z/tmp9fjsms6f TO /home/runner/.ansible/tmp/ansible-local-19ah400x6z/ansible-tmp-1681997446.7857811-88-241249696992527/AnsiballZ_stat.py
<192.168.11.60> EXEC /bin/sh -c 'chmod u+x /home/runner/.ansible/tmp/ansible-local-19ah400x6z/ansible-tmp-1681997446.7857811-88-241249696992527/ /home/runner/.ansible/tmp/ansible-local-19ah400x6z/ansible-tmp-1681997446.7857811-88-241249696992527/AnsiballZ_stat.py && sleep 0'
<192.168.11.60> EXEC /bin/sh -c '/usr/bin/python3 /home/runner/.ansible/tmp/ansible-local-19ah400x6z/ansible-tmp-1681997446.7857811-88-241249696992527/AnsiballZ_stat.py && sleep 0'
<192.168.11.60> FETCH /tmp/ip_interface_brief.txt TO /data/projects/first-project/output/ip_interface_brief.txt
<192.168.11.60> PUT /tmp/ip_interface_brief.txt TO /data/projects/first-project/output/ip_interface_brief.txt
<192.168.11.60> EXEC /bin/sh -c 'rm -f -r /home/runner/.ansible/tmp/ansible-local-19ah400x6z/ansible-tmp-1681997446.7857811-88-241249696992527/ > /dev/null 2>&1 && sleep 0'
changed: [awx-cisco-ios-r1] => {

    "changed": true,
    "checksum": "f41d04c0206136d7feca531350a1b4fce31d5e5d",
    "dest": "/data/projects/first-project/output/ip_interface_brief.txt",
    "md5sum": "d18193eb730c6371c716328ebc687a04",
    "remote_checksum": "f41d04c0206136d7feca531350a1b4fce31d5e5d",
    "remote_md5sum": null

}
META: ran handlers
META: ran handlers
PLAY RECAP *********************************************************************
awx-cisco-ios-r1           : ok=5    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

You received this message because you are subscribed to a topic in the Google Groups "AWX Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/awx-project/QoJdFMcYYws/unsubscribe.
To unsubscribe from this group and all its topics, send an email to awx-project...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/awx-project/66ee7e9e-042e-4a31-a90c-05c851c37dd0n%40googlegroups.com.


--
Best Regards
Yeow Tiong

Wei-Yen Tan

unread,
Apr 20, 2023, 9:51:01 AM4/20/23
to awx-p...@googlegroups.com
Yoy can also download the job output from the ui iirc 

Sent from Outlook for iOS

From: awx-p...@googlegroups.com <awx-p...@googlegroups.com> on behalf of yeowtiong tan <yeow...@gmail.com>
Sent: Friday, April 21, 2023 1:36:04 AM
To: awx-p...@googlegroups.com <awx-p...@googlegroups.com>
Subject: Re: [awx-project] Re: How to save stdout at awx-host filesystem
 

yeowtiong tan

unread,
Apr 21, 2023, 9:35:22 AM4/21/23
to AWX Project
Hi Weiye,

 Many thanks. However, if i have multiple network equipment to sort them out according to different text file based on IP address, it will be better if i can actually create a txt file for each of them.

yeowtiong tan

unread,
May 1, 2023, 3:20:12 AM5/1/23
to AWX Project
Hi anyone or kind souls able to advise?

Somehow the enable job isolation option is also not available to be disabled unlike ansible tower.


Has anyone else used  AWX_PROOT_HIDE_PATHS = ['/list/of/', '/paths'] before? Not sure if it helps

This kub container is the hosted on the same machine as my ubuntu.

kubectl exec -it awx-task-6667fc866f-abcde  -n awx --container awx-task -- /bin/bash
bash-5.1$ whoami
awx
bash-5.1$ pwd
/tmp
bash-5.1$ ls

Inside the kub container i have a mounted volume where i can see the playbooks on my local machine. 
bash-5.1$ pwd
/var/lib/awx/projects/first-project

is it then possible for the awx job template to copy into this path since it can see the files?

Thanks!

AWX Project

unread,
May 3, 2023, 2:46:41 PM5/3/23
to AWX Project
can you provide your exact settings for exposed isolated paths? also can you paste the playbook that you are running, or at least the portion that writes the file to this mounted in location?

AWX Team

AWX Project

unread,
May 3, 2023, 2:53:41 PM5/3/23
to AWX Project
Hi, also be sure to use the latest Controller docs. The doc you linked was for v3.8, which is pretty old and doesn't align with newer AWX versions

vivek shete

unread,
Jul 18, 2023, 1:51:18 PM7/18/23
to AWX Project
Hi OP, were you able to resolve this? I am also trying to save output locally and eventually copy it to remote server.
Reply all
Reply to author
Forward
0 new messages