How to print the CLI command with the command output

48 views
Skip to first unread message

Al Gabsi

unread,
May 18, 2021, 4:13:34 PM5/18/21
to Ansible Project


Hello Everyone;

Could you please guide me on how to be able to print the CLI command to the log file?
For example, if I am  backing up inventory, and I am using "show chassis hardware", I would like to see something like this:

AD...@ROUTER-BBBJ11.R1.AT> show chassis hardware detail | display xml | no-more 
    <chassis-inventory xmlns="http://xml.juniper.net/junos/17.3R3/junos-chassis">
        <chassis junos:style="inventory">
            <name>Chassis</name>

Currently, I am only seeing the output and not seeing the hostname with the CLI command. 

Here is my script
This my current output. It is not show ing the CLI
<chassis-inventory>. ==> this is my first line
  <chassis style="inventory">
    <name>Chassis</name>
    <serial-number>JN111F17FAFA</serial-number>

------------------------------

---
- name: Get Device Facts
  hosts: lab-nep6
  connection: local
  gather_facts: no
  roles:
    - juniper.junos
  vars_prompt:
    - name: USERNAME
      prompt: Username
      private: no
    - name: PASSWORD
      prompt: password
      private: yes
  tasks:
    - name: Get inventory_hostname
      juniper_junos_command:
        host: "{{ inventory_hostname }}"
        port: 22
        user: "{{ USERNAME }}"
        password: "{{ PASSWORD }}"
        commands: "show chassis hardware detail"
        formats:
          - "xml"
        dest: "tmp/inventory-nep6/{{ inventory_hostname }}__{{ '%m-%d-%Y' | strftime }}.output"
      

Thank you in advance :-)



Al Gabsi

unread,
May 19, 2021, 1:47:22 AM5/19/21
to Ansible Project
Wondering if anyone has an answer to this :-)

Dick Visser

unread,
May 19, 2021, 3:20:06 AM5/19/21
to ansible...@googlegroups.com
This is a best effort mailing list run mostly by volunteers. I
wouldn't expect a response in a few hours.

I may be wrong, but given that the purpose of the network modules
(such as the junos ones) is to abstract away the CLI interaction, what
you're asking sounds like the opposite?
> --
> 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/0c15c623-cc24-4714-af2f-0994f1de77c6n%40googlegroups.com.



--
Dick Visser
Trust & Identity Service Operations Manager
GÉANT

Alaeddin Gabsi

unread,
May 19, 2021, 7:46:59 AM5/19/21
to ansible...@googlegroups.com
Thank you, Dick;

I thought that maybe it should be some kind of option to print the STDIN. In my case, an inventory report without hostnames can not be used. 

I then probably should use a python script for this.  

Thanks 



--
Thank You
Alaeddin Gabsi

Dick Visser

unread,
May 19, 2021, 8:15:25 AM5/19/21
to ansible...@googlegroups.com
Can't you combine the results with another query that returns that hostname?

--
Sent from a mobile device - please excuse the brevity, spelling and punctuation.

Alaeddin Gabsi

unread,
May 19, 2021, 8:32:15 AM5/19/21
to ansible...@googlegroups.com
The first line has to be in this format " AD...@ROUTER-BBBJ11.R1.AT> show chassis hardware detail | display xml | no-more ". By the way, there is no DNS working and I am just using IP addresses. I probably use RPC XML and see if I can change the file name to that format then use tail. Or just PyEZ.

Thanks


Reply all
Reply to author
Forward
0 new messages