Export debug msg to a file

35 views
Skip to first unread message

bilel....@gmail.com

unread,
Nov 24, 2020, 5:47:06 PM11/24/20
to Ansible Project
Hello 

Need some assistance to send to a text file a message that appears in debug msg.
my uri task give me the flow msg 
 "msg": [
        "JOB-1",
        "JOB-2",
        " JOB- 3 ",
        " JOB- 4 ",
        " JOB- 5 ",
        " JOB- 6 ",
        " JOB- 7 "
    ]
and I need to add task on the playbook to send this msg to specific file like this 

cat jobs_lists.txt 

        JOB-1
        JOB-2
        JOB- 3 
        JOB- 4 
        JOB- 5 
        JOB- 6 
        JOB- 7 

Appreciate your help. 
Regards 
 

Roberto Paz

unread,
Nov 25, 2020, 2:15:10 AM11/25/20
to Ansible Project
The text you print in the debug task is previously stored in a variable?
If that's the case, you can write the variable stdout_lines attribute to a local file using lineinfile module and delegate_to: localhost, so this is writted locally.

BILKAM

unread,
Nov 25, 2020, 3:20:35 AM11/25/20
to ansible...@googlegroups.com
The text you print in the debug task is previously stored in a variable? No 
nameDisplay all Jobs Names
    ansible.builtin.debug:
     msg"{{ Jobs.json | json_query('Jobs.Jobs[*].Name')}}"

ok: [localhost] => {
    "changed": false,

    "msg": [
        "JOB-1",
        "JOB-2",
        "JOB-3",
        "JOB-4",
        "JOB-9",
        "JOB-8",
        "JOB-7"
    ]
}

and then I need task to save the list of the job name on specific file: 

cat jobs_lists.txt 

        JOB-1
        JOB-2
        JOB- 3 
        JOB- 4 
        JOB- 5 
        JOB- 6 
        JOB- 7

Regards, 
 
--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/3gjhknUWLiE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/a5a6c191-e5a0-4438-a8b6-edc27466a347n%40googlegroups.com.


--

Stefan Hornburg (Racke)

unread,
Nov 25, 2020, 3:53:08 AM11/25/20
to ansible...@googlegroups.com
On 11/25/20 9:19 AM, BILKAM wrote:
> The text you print in the debug task is previously stored in a variable? *No* 
> - name: Display all Jobs Names
>     ansible.builtin.debug:
>      msg: "{{ Jobs.json | json_query('Jobs.Jobs[*].Name')}}"
>
> ok: [localhost] => {
>     "changed": false,
>     "msg": [
>         "JOB-1",
>         "JOB-2",
>         "JOB-3",
>         "JOB-4",
>         "JOB-9",
>         "JOB-8",
>         "JOB-7"
>     ]
> }
>
> and then I need task to save the list of the job name on specific file: 
>
> cat jobs_lists.txt 
>
>         JOB-1
>         JOB-2
>         JOB- 3 
>         JOB- 4 
>         JOB- 5 
>         JOB- 6 
>         JOB- 7
>
> Regards, 
>  

You can use a copy task with is delegated to localhost:

- name: Write job file
copy:
content: "{{ Jobs.json | json_query('Jobs.Jobs[*].Name') | join('\n') }}"
dest: /tmp/job_lists.txt
delegate_to: localhost

Regards
Racke

>
> On Wed, Nov 25, 2020 at 8:15 AM Roberto Paz <rjr...@gmail.com <mailto:rjr...@gmail.com>> wrote:
>
> The text you print in the debug task is previously stored in a variable?
> If that's the case, you can write the variable *stdout_lines *attribute to a local file using *lineinfile*
> module and *delegate_to: localhost*, so this is writted locally.
> <https://groups.google.com/d/topic/ansible-project/3gjhknUWLiE/unsubscribe>.
> To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com
> <mailto:ansible-proje...@googlegroups.com>.
> <https://groups.google.com/d/msgid/ansible-project/a5a6c191-e5a0-4438-a8b6-edc27466a347n%40googlegroups.com?utm_medium=email&utm_source=footer>.
>
>
>
> --
> BILKAM <https://twitter.com/BILKAM2>
> vinception.fr <http://www.vinception.fr>
>
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CAHY7qGpSn5%3DCf08%2B6T%3DcSD82miN16Fk4w6jHiYajfKetWZo4qQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/ansible-project/CAHY7qGpSn5%3DCf08%2B6T%3DcSD82miN16Fk4w6jHiYajfKetWZo4qQ%40mail.gmail.com?utm_medium=email&utm_source=footer>.


--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

OpenPGP_signature

BILKAM

unread,
Nov 25, 2020, 4:15:17 AM11/25/20
to ansible...@googlegroups.com
Just what I need.
Thanks for your support 

To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/c9bc7ea4-aefc-7ba2-a09b-5458cfc29697%40linuxia.de.


--
Reply all
Reply to author
Forward
0 new messages