Ansible Cisco输出创建空文件

问题描述 投票:0回答:1

仅将第一个命令的输出写入文件。

我如何使其将所有命令的输出写入文件?

---

- name: run show commands
  hosts: nexus1
  gather_facts: False


  tasks:
  - name: run show commands on nexus
    nxos_command:
      commands:
        - show hostname
        - show ip route
        - show interface
        - show ip interface vrf all 
        - show hsrp
    register: output

  - name: Copy to server
    copy:
      content: "{{ output.stdout[0] }}"
      dest: "/home/CiscoOutPut/{{ inventory_hostname }}.txt"
linux ansible cisco
1个回答
0
投票

您只是询问”来自第一个命令的输出。 output.stdout是一个列表,每个命令输出一个项目。当询问output.stdout[0]时,您仅询问第一个结果。

如果要将所有命令的输出写入文件,则类似于:

  - name: Copy to server
    copy:
      content: "{{ '\n'.join(output.stdout) }}"
      dest: "/home/CiscoOutPut/{{ inventory_hostname }}.txt"
© www.soinside.com 2019 - 2024. All rights reserved.