# junos\_command

**URL:** <https://forum.ansible.com/t/junos-command/27154>\
**Category:** Ansible Project\
**Created:** [March 29, 2018, 7:49pm UTC](https://forum.ansible.com/t/junos-command/27154 "2018-03-29T19:49:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gary\_Rubel](https://avatars.discourse-cdn.com/v4/letter/g/bbce88/32.png) [@Gary\_Rubel](https://forum.ansible.com/u/Gary_Rubel)\
**Post date:** [March 29, 2018, 7:49pm UTC](https://forum.ansible.com/t/junos-command/27154/1 "2018-03-29T19:49:35Z")

</div>

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”

---

<div class="post-metadata">

**Author:** ![ganeshrn](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/ganeshrn/32/1021_2.png) [@ganeshrn](https://forum.ansible.com/u/ganeshrn)\
**Post date:** [March 30, 2018, 6:46am UTC](https://forum.ansible.com/t/junos-command/27154/2 "2018-03-30T06:46:14Z")

</div>

You can use ‘include\_vars’

```auto
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
