Re: [ansible-project] 'dict object' has no attribute 'stdout'

509 views
Skip to first unread message
Message has been deleted

Todd Lewis

unread,
Mar 13, 2023, 11:36:25 AM3/13/23
to ansible...@googlegroups.com, uto...@gmail.com
- 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 ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/c7df6afd-61c9-46e2-8b0f-519d9200c192n%40googlegroups.com.

-- 
Todd

Todd Lewis

unread,
Mar 13, 2023, 11:39:46 AM3/13/23
to Ansible Project
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

Reply all
Reply to author
Forward
0 new messages