junos_command

Hello,

I’m trying to execute show commands on a Juniper using the playbook below. I would like to use a separate file with the list of show commands but can’t find the correct way to do it. Any help would be appreciated.

thanks

showfile: “{{ lookup(‘file’, ‘template/shcmds.txt’) }}”

  • name: Run a set of commands
    junos_command:
    commands: “{{ showfile }}”

src: template/shcmds.j2

output: text
provider: “{{ netconf }}”
register: showcmds

  • set_fact:
    readout: “{{ showcmds.stdout_lines | to_nice_yaml }}”

  • name: copy content
    local_action:
    copy content=“{{ readout }}”
    dest=“{{ report_dir }}/{{ inventory_hostname }}.txt”

######### Input file ##########
template]$ more shcmds.txt

  • “show bgp sum”
  • “show route summary”

You can use ‘include_vars’

tasks:
- name: include commands
  include_vars:
    file: shcmds.yaml

- name: Run a set of commands
  junos_command:
    commands: "{{ show_commands }}"
    output: text
    provider: "{{ netconf }}"
  register: showcmds

$ cat shcmds.yaml