Ansible:如何复制4个命令的输出

Ansible:如何复制4个命令的输出,ansible,Ansible,我想将变量showoutput(其中有4个命令)的内容复制到一个文件中。但是,当我执行playbook时,它只复制第一个命令 如何复制这四个命令 在我的剧本下面: - hosts: ios vars: command_list: - show cdp neigh - show ip interface brief - show clock - show arp tasks: - name: Run the SHOW com

我想将变量showoutput(其中有4个命令)的内容复制到一个文件中。但是,当我执行playbook时,它只复制第一个命令

如何复制这四个命令

在我的剧本下面:

- hosts: ios
  vars:
    command_list:
      - show cdp neigh
      - show ip interface brief
      - show clock
      - show arp

  tasks:
    - name: Run the SHOW commands and save output
      ios_command:
        commands: "{{ command_list }}"
      register: showoutput

    - name : Copy the result in a file
      copy:
        content: "{{showoutput.stdout[0]}}"
        dest: "/home/net/output/{{hostvars.localhost.DTG}}/{{inventory_hostname}}-{{hostvars.localhost.DTG}}-test.txt"

Ansible关于

在使用循环的任务中注册变量时,将 变量包含循环中每个项的值。数据 循环期间放置在变量中的结构将包含
results
属性,即来自模块的所有响应的列表

每个命令的输出都应该在
showoutput.results
中可用,它是一个数组。您可以将其循环为

    - name : Copy the result in a file
      copy:
        content: "{{ item.stdout }}"
        dest: "/home/net/output/{{hostvars.localhost.DTG}}/{{inventory_hostname}}-{{hostvars.localhost.DTG}}-test.txt"
      with_items: "{{ showoutput.results }}"

Ansible关于

在使用循环的任务中注册变量时,将 变量包含循环中每个项的值。数据 循环期间放置在变量中的结构将包含
results
属性,即来自模块的所有响应的列表

每个命令的输出都应该在
showoutput.results
中可用,它是一个数组。您可以将其循环为

    - name : Copy the result in a file
      copy:
        content: "{{ item.stdout }}"
        dest: "/home/net/output/{{hostvars.localhost.DTG}}/{{inventory_hostname}}-{{hostvars.localhost.DTG}}-test.txt"
      with_items: "{{ showoutput.results }}"