It is not necessary to go via 'show' commands. The data you are looking for is probably available under 'junos_facts'.
https://www.juniper.net/documentation/us/en/software/junos-ansible/ansible/topics/task/junos-ansible-device-facts-retrieving.html
https://galaxy.ansible.com/ui/repo/published/junipernetworks/junos/content/module/junos_facts/
So, something like
---
- name: Collect Junos versions and models and save to CSV
hosts: all
gather_facts: no
tasks:
- name: Gather Junos facts
junipernetworks.junos.junos_facts:
register: device_facts
- name: Add Junos version and model to a list
set_fact:
device_info_list: "{{ device_info_list | default([]) + [{'hostname': inventory_hostname, 'model': device_facts.facts.model, 'version': device_facts.facts.version}] }}"
- name: Write results to CSV
local_action:
module: copy
content: |
hostname,model,version
{% for device in device_info_list %}
{{ device.hostname }},{{ device.model }},{{ device.version }}
{% endfor %}
dest: junos_device_info.csv
run_once: yes
------------------------------
PER GRANATH
------------------------------
Original Message:
Sent: 02-21-2025 03:37
From: FRANCOIS VAN HEERDEN
Subject: Question on an Ansible playbook creation
try this as well,
- name: get chassis hardware detail junos_command: commands: show chassis hardware detail display: xml
------------------------------
FRANCOIS VAN HEERDEN
Original Message:
Sent: 02-20-2025 10:42
From: JORDAN ATHERTON
Subject: Question on an Ansible playbook creation
I am having issues automating something with ansible,
Every month juniper requests us to give them a full inventory list of all of our devices, by running this command on the box and saving it in a file:
"show chassis hardware detail | display xml | no-more"
At first i tried something like this:
---- name: Grab Junipers Monlthy Request hosts: test gather_facts: no connection: netconf vars_files: - ../../../Credentials/credentials.yml vars: ansible_network_os: junos tasks: - name: Run Command On Juniper Device junipernetworks.junos.junos_config: lines: - show chassis hardware detail | display xml | no-more
That obviously does not work because ansible doesn't like the "|" within the command.
Does anyone have a playbook handy that will grab information like this:
user@devicename> show chassis hardware detail | display xml | no-more <rpc-reply xmlns:junos="http://xml.juniper.net/junos/24.4R1.9/junos"> <chassis-inventory xmlns="http://xml.juniper.net/junos/24.4R0/junos-chassis"> --All chassis information from the output of the command--- </chassis-module> </chassis> </chassis-inventory> <cli> <banner>{master:0}</banner> </cli></rpc-reply>
They need it formated "exactly how it is outputted" for their automation on their end that they use.
------------------------------
JORDAN ATHERTON
------------------------------