If you use
junos_install_config in check mode, it will load the configuration and produce a diff (assuming
diffs_file is set), but it will not commit the config. If you are using Ansible >= 2.2, then you can specify
check_mode: yes on the
junos_install_config task without having to enable check mode for the entire playbook. See this
link for more info.
---
# This playbook requires Ansible >= 2.2.
- name: "Demonstrate diff from junos_install_config without commit"
hosts: junos-all
connection: local
gather_facts: no
roles:
- Juniper.junos
tasks:
- name: "Cleanup the ./output directory"
file:
path: "./output"
state: absent
run_once: True
delegate_to: localhost
- name: "Create the ./output directory"
file:
path: "./output"
state: directory
run_once: True
delegate_to: localhost
- name: "Verify the ./input directory exists"
file:
path: "./input"
state: directory
run_once: True
delegate_to: localhost
- name: "Verify the template exists"
file:
path: "./input/template-host-name.j2"
state: file
run_once: True
delegate_to: localhost
- name: "Build configuration files from template"
template:
src: "./input/template-host-name.j2"
dest: "./input/{{ inventory_hostname }}-host-name.conf"
- name: "Produce config diff"
junos_install_config:
host: "{{ inventory_hostname }}"
user: "{{ jaccess.user }}"
passwd: "{{ jaccess.passwd }}"
file: "./input/{{ inventory_hostname }}-host-name.conf"
diffs_file: "./output/{{ inventory_hostname }}-host-name.diff"
check_mode: yes
register: response
- name: "Cleanup the config file"
file:
path: "./input/{{ inventory_hostname }}-host-name.conf"
state: absent
- name: "Read diff file into diffs variable"
set_fact:
diffs: "{{ lookup('file','./output/{{ inventory_hostname }}-host-name.diff') }}"
- name: "Print diffs"
debug:
var: diffs
- name: "Cleanup the ./output directory"
file:
path: "./output"
state: absent
run_once: True
delegate_to: localhost