# How to print the CLI command with the command output

**URL:** <https://forum.ansible.com/t/how-to-print-the-cli-command-with-the-command-output/35189>\
**Category:** Ansible Project\
**Created:** [May 18, 2021, 8:13pm UTC](https://forum.ansible.com/t/how-to-print-the-cli-command-with-the-command-output/35189 "2021-05-18T20:13:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Al\_Gabsi](https://avatars.discourse-cdn.com/v4/letter/a/e495f1/32.png) [@Al\_Gabsi](https://forum.ansible.com/u/Al_Gabsi)\
**Post date:** [May 18, 2021, 8:13pm UTC](https://forum.ansible.com/t/how-to-print-the-cli-command-with-the-command-output/35189/1 "2021-05-18T20:13:34Z")

</div>

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:

ADMIN@ROUTER-BBBJ11.R1.AT\> show chassis hardware detail | display xml | no-more  
  
  
  
Chassis

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

. ==\> this is my first line  
  
Chassis  
JN111F17FAFA

---

<div class="post-metadata">

**Author:** ![Al\_Gabsi](https://avatars.discourse-cdn.com/v4/letter/a/e495f1/32.png) [@Al\_Gabsi](https://forum.ansible.com/u/Al_Gabsi)\
**Post date:** [May 19, 2021, 5:47am UTC](https://forum.ansible.com/t/how-to-print-the-cli-command-with-the-command-output/35189/2 "2021-05-19T05:47:22Z")

</div>

Wondering if anyone has an answer to this 🙂

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [May 19, 2021, 7:19am UTC](https://forum.ansible.com/t/how-to-print-the-cli-command-with-the-command-output/35189/3 "2021-05-19T07:19:38Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Al\_Gabsi](https://avatars.discourse-cdn.com/v4/letter/a/e495f1/32.png) [@Al\_Gabsi](https://forum.ansible.com/u/Al_Gabsi)\
**Post date:** [May 19, 2021, 11:46am UTC](https://forum.ansible.com/t/how-to-print-the-cli-command-with-the-command-output/35189/4 "2021-05-19T11:46:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [May 19, 2021, 12:14pm UTC](https://forum.ansible.com/t/how-to-print-the-cli-command-with-the-command-output/35189/5 "2021-05-19T12:14:59Z")

</div>

Can’t you combine the results with another query that returns that hostname?

---

<div class="post-metadata">

**Author:** ![Al\_Gabsi](https://avatars.discourse-cdn.com/v4/letter/a/e495f1/32.png) [@Al\_Gabsi](https://forum.ansible.com/u/Al_Gabsi)\
**Post date:** [May 19, 2021, 12:31pm UTC](https://forum.ansible.com/t/how-to-print-the-cli-command-with-the-command-output/35189/6 "2021-05-19T12:31:46Z")

</div>

The first line has to be in this format " [ADMIN@ROUTER-BBBJ11.R1.AT](mailto:ADMIN@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
