Hi Dick I think if we use print_output.stdout[1] }} without 0 or 1 in it,
it will throw a syntax error.
Print_output.stdout alone might be invalid.
Thanks
On Tuesday, June 1, 2021 at 4:23:59 PM UTC+10 new_ansible wrote:
> I think you can test once with
>
> with_items: "{{ print_output.stdout }}
>
>
> On Tue, 1 Jun 2021 at 8:12 AM, Djay wadhwa <[email protected]> wrote:
>
>> Hi Pushp,
>>
>> Script worked but desired outcome not achieved. still getting output of
>> only 1st command ( show ip name-servers) in the file.
>>
>> - name: Check Ip routes
>> hosts: routers
>> gather_facts: false
>> connection: local
>>
>> vars:
>> cli:
>> username: "{{ hdn_user_rw }}"
>> password: "{{ hdn_pass_rw }}"
>>
>> tasks:
>>
>>
>> - name: Name servers
>> ios_command:
>> authorize: yes
>> provider: "{{ cli }}"
>> commands:
>> - show ip name-servers
>> - show run | in ntp
>> - show run | in host
>> - show run | in address ipv4
>> - show run | in logging host
>> register: print_output
>>
>> #- name: save output to a file
>> #copy: content="{{ print_output.stdout[0] }}"
>> dest="/opt/ansible/dev/Dheeraj/verf/adnan/Log/{{ inventory_hostname }}.txt"
>>
>> - name: save output to a file
>> lineinfile:
>> create: yes
>> line: "{{item}}"
>> path: /opt/ansible/dev/Dheeraj/verf/adnan/Log/{{
>> inventory_hostname }}.txt
>> with_items: "{{ print_output.stdout[0] }}"
>>
>>
>> On Tuesday, June 1, 2021 at 11:19:13 AM UTC+10 rajthecomputerguy wrote:
>>
>>> There is a indentation error in your playbook
>>>
>>> - name: save output to a file
>>> lineinfile:
>>> create: yes
>>> line: "{{item}}"
>>> path: /opt/ansible/dev/Dheeraj/verf/adnan/Log/{{
>>> inventory_hostname }}.txt
>>> with_items: "{{ print_output.stdout[1] }}"
>>>
>>>
>> On Tue, Jun 1, 2021 at 5:19 AM Djay wadhwa <[email protected]> wrote:
>>>
>>>> Hi Pushpraj,
>>>>
>>>> I am getting the error below if i try to run this with lineinfile as
>>>> per suggestion.
>>>>
>>>> Please see my playbook as attached. Appreciate your help
>>>>
>>>> ---
>>>> - name: Routers data
>>>> hosts: routers
>>>> gather_facts: false
>>>> connection: local
>>>>
>>>> vars:
>>>> cli:
>>>> username: "{{ hdn_user_rw }}"
>>>> password: "{{ hdn_pass_rw }}"
>>>>
>>>> tasks:
>>>>
>>>> - name: Name servers
>>>> ios_command:
>>>> authorize: yes
>>>> provider: "{{ cli }}"
>>>> commands:
>>>> - show ip name-servers
>>>> - show ip interface brief
>>>> - show run | in host
>>>>
>>>> register: print_output
>>>>
>>>>
>>>> - name: save output to a file
>>>> lineinfile:
>>>> create: yes
>>>> line: "{{item}}"
>>>> path: /opt/ansible/dev/Dheeraj/verf/adnan/Log/{{
>>>> inventory_hostname }}.txt
>>>> with_items: "{{ print_output.stdout[1] }}"
>>>>
>>>>
>>>> =================================================================================
>>>>
>>>> TASK [save output to a file]
>>>> ***********************************************************************************************************************************************************************************************************************************
>>>> fatal: [SURRDEN-NRT001]: FAILED! => {
>>>> "changed": false
>>>> }
>>>>
>>>> MSG:
>>>>
>>>> Unsupported parameters for (lineinfile) module: with_items Supported
>>>> parameters include:
>>>> attributes,backrefs,backup,content,create,delimiter,directory_mode,follow,force,group,insertafter,insertbefore,line,mode,owner,path,regexp,remote_src,selevel,serole,setype,seuser,src,state,unsafe_writes,validate
>>>> fatal: [POWHHSP-NRT002]: FAILED! => {
>>>> "changed": false
>>>> }
>>>>
>>>> MSG:
>>>>
>>>> Unsupported parameters for (lineinfile) module: with_items Supported
>>>> parameters include:
>>>> attributes,backrefs,backup,content,create,delimiter,directory_mode,follow,force,group,insertafter,insertbefore,line,mode,owner,path,regexp,remote_src,selevel,serole,setype,seuser,src,state,unsafe_writes,validate
>>>> fatal: [ROCKDEN-NRT001]: FAILED! => {
>>>> "changed": false
>>>> }
>>>>
>>>> MSG:
>>>>
>>>> Unsupported parameters for (lineinfile) module: with_items Supported
>>>> parameters include:
>>>> attributes,backrefs,backup,content,create,delimiter,directory_mode,follow,force,group,insertafter,insertbefore,line,mode,owner,path,regexp,remote_src,selevel,serole,setype,seuser,src,state,unsafe_writes,validate
>>>> to retry, use: --limit @/opt/ansible/dev/Dheeraj/Splunk.retry
>>>>
>>>>
>>>>
>>>>
>>>> On Tuesday, June 1, 2021 at 1:29:44 AM UTC+10 rajthecomputerguy wrote:
>>>>
>>>>> 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/93146581-f3b0-4bf4-8625-011b5c5a8d59n%40googlegroups.com
>>>>
>>>> <https://groups.google.com/d/msgid/ansible-project/93146581-f3b0-4bf4-8625-011b5c5a8d59n%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/730ddb05-3e2a-4561-9034-8f06a59def97n%40googlegroups.com
>>
>> <https://groups.google.com/d/msgid/ansible-project/730ddb05-3e2a-4561-9034-8f06a59def97n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>
--
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/bee89234-e1d2-4382-8956-7658f60f1cc9n%40googlegroups.com.