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/CAE5Yv1R2Lhix9gFWDXnYGdFX7MTB7C-VrFch-VG54K8%3DqUXQ6g%40mail.gmail.com.