D'oh! Test one thing and post something else. *Argh!*
How about this:
- name: Save output to file
ansible.builtin.copy:
content: |
{{ output.stdout_lines[0:1] | join('\n') }}
dest: "show-output/{{ inventory_hostname }}.ios"
when output.stdout_lines is defined
On Monday, March 13, 2023 at 11:36:25 AM UTC-4 Todd Lewis wrote:
> - name: Save output to file
> ansible.builtin.copy:
> content: |-
> {{ '\n'.join(output.stdout_lines[0:1]) }}
> dest: "show-output/{{ inventory_hostname }}.ios"
> when output.stdout_lines is defined
>
>
>
> On 3/13/23 11:13 AM, Merlijn De Wandel wrote:
>
> Hi We have the following working config down below. However sometimes the
> routers don't have the command "sh ip ospf nei" and we get the following
> error:
> FAILED! => {"msg": "The task includes an option with an undefined
> variable. The error was: 'dict object' has no attribute 'stdout'\n\nThe
> error appears to be in
> '/etc/ansible/playbooks/ShowCommandsRunAndIpOspfNei.yaml': line 15, column
> 7, but may\nbe elsewhere in the file depending on the exact syntax
> problem.\n\nThe offending line appears to be:\n\n\n - name: Save output to
> file\n ^ here\n"}
> We would like to get the show run from all routers and sh ip ospf nei from
> the routers who have it.
> --- - name: Show run and sh ip ospf nei hosts: Test gather_facts: false
> tasks: - name: Show Commands ignore_errors: true ios_command: commands: -
> sh run - sh ip ospf nei register: output - name: Save output to file copy:
> content: |- {% if output.stdout_lines[1] is defined %} {{ output.stdout[0]
> | replace('\\n', '\n') }}
> {{ output.stdout[1] | replace('\\n', '\n') }} {% else %} {{
> output.stdout[0] | replace('\\n', '\n') }} {% endif %} dest:
> "show-output/{{ inventory_hostname }}.ios"
>
> --
> 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/c7df6afd-61c9-46e2-8b0f-519d9200c192n%40googlegroups.com
>
> <https://groups.google.com/d/msgid/ansible-project/c7df6afd-61c9-46e2-8b0f-519d9200c192n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
>
> --
> Todd
>
>
--
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/d29b85d1-95e5-4ba2-a0ed-b48a74a139ccn%40googlegroups.com.