Developer

last person joined: 2 days ago 

Expand all | Collapse all

Output options with aoscx_command

This thread has been viewed 14 times
  • 1.  Output options with aoscx_command

    Posted Feb 22, 2021 06:22 AM
    Hi,

    I'm trying to collect output while using aoscx_command, this is my playbook:
    - hosts: all
    gather_facts: false
    roles:
    - role: aoscx-ansible-role
    tasks:
    - name: Execute 'show system', and output results to file in plaintext
    aoscx_command:
    commands: [
    'show system',
    ]
    output_file: /home/talm/output.txt
    output_file_format: plain-text

    but when I'm run it, the output I receive is only for one device:

    [talm@centos01 ansible]$ cat /home/talm/output.txt
    command: show system
    response: Hostname : AOSCX02
    System Description : Virtual.10.05.0020
    System Contact :
    System Location :

    Vendor : Aruba
    Product Name : ABC123 ArubaOS-CX_OVA
    Chassis Serial Nbr : OVA50BF13
    Base MAC Address : 080009-50bf13
    ArubaOS-CX Version : Virtual.10.05.0020

    Time Zone : UTC

    Up Time : 2 hours, 52 minutes
    CPU Util (%) : 6
    Memory Usage (%) : 33
    ------------------------------------------
    [talm@centos01 ansible]$

    How can I append the output for each device in the same file?
    Is there anyway to create a file for each device based on their hostname?

    Thanks.

    ------------------------------
    Tal Madari
    ------------------------------


  • 2.  RE: Output options with aoscx_command

    Posted Feb 22, 2021 12:07 PM
    Hi Tal!

    What is happening is you're overwriting the contents of the file with each execution, what you'll want to do is use one of Ansible's special variables to dynamically create the file for each hostname:
    - name: Execute 'show system', and output results to file in plaintext
    aoscx_command:
    commands: [
    'show system',
    ]
    output_file: /home/talm/{{inventory_hostname}}.txt
    output_file_format: plain-text​

    I'm using the special variable inventory_hostname as the name of the file, that variable will hold the inventory name of each device that it executes on.

    Let me know if this answers your question!

    ------------------------------
    Tiffany Chiapuzio-Wong
    ------------------------------



  • 3.  RE: Output options with aoscx_command

    Posted Feb 22, 2021 03:46 PM
    Hi Tiffany,

    Thanks! got it.

    here is my playbook:
    - hosts: all     
      gather_facts: false
      roles:
        - role: aoscx-ansible-role
      tasks:
        - name: Execute show system
          aoscx_command:
            commands: [
                'show system',
                'show running-config',
                'show vlan',
                ]
            output_file: /home/talm/{{inventory_hostname}}.txt
            output_file_format: plain-text
    ​


    works as expected!

    Thank you.



    ------------------------------
    Tal Madari
    ------------------------------