ios_command multiple commands

  • name: Network Getting Started First Playbook
    connection: network_cli
    gather_facts: false
    hosts: lab
    tasks:

  • name: run multiple commands on remote nodes
    ios_command:
    commands:

  • show run
    register: output

  • name: save output
    copy:
    content: “{{ output.stdout[0] }}”
    dest: “/etc/ansible/backup/{{ inventory_hostname }}.txt”

Have you had the chance to save a set of multiple commands on file, just save the first one from the list, does anyone have the same scenario?

Hi,

You can give list of commands and all the outputs will register in mentioned variable name. And instead output.stdout[0] just give output.stdout.

But the problem is variable I.e output.stdout will only contain outputs only. Means issued command will not be there.

Try with blockinfile module to have command1
output of command1
Command2
Output of command2

Thanks,
Veera

Tks Kumar, Your tip worked for me.