Can you try this

Use this to write several strings into a file:

- name: save output to a file
  lineinfile:
    create: yes
    line: "{{item}}"
    path: ./output/{{ inventory_hostname }}.txt
  with_items: "{{ print_output.stdout[1] }}"


On Mon, May 31, 2021 at 11:28 AM Djay wadhwa <[email protected]> wrote:

> Hi All
>
>
> I have this ansible code where i need output of all these commands in one
> file, however, all i am getting is either output of first command or second
> command if i change the following to 0,1,2 however ansible is not
> appending/writing all outputs into a single file.
>
>
> Appreciate if there is a method which members could suggest to make it
> work.
>
>
> "{{ print_output.stdout[1] }}
>
>
> - name: Name servers
>
> ios_command:
>
> authorize: yes
>
> provider: "{{ cli }}"
>
> commands:
>
> - show ip name-servers
>
> - show ip int brief
>
> - show logging | in host
>
> register: print_output
>
> - name: save output to a file
>
> copy: content="{{ print_output.stdout[1] }}"
> dest="/opt/ansible/dev/Dheeraj/verf/adnan/NTP/{{ inventory_hostname }}.txt"
>
> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/60f51826-3f20-4421-97ed-1e79724c8473n%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/60f51826-3f20-4421-97ed-1e79724c8473n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>


-- 

Thanks,

Pushparaj G

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAE5Yv1TRcXzK-fQWFxw4UxOje3gCGMTwgHBOxBDvJL0mFAjR%2BQ%40mail.gmail.com.

Reply via email to