Junos Automation (Scripting)
Junos Automation (Scripting)

What is the default path of template and vars in juniper_junos_config

‎04-02-2018 09:41 PM

Hi,

I'm using juniper_junos_config and jinja2 template to generate dynamic configuration. According to https://junos-ansible-modules.readthedocs.io/en/2.0.2/juniper_junos_config.html, template and vars are absolute path to j2 tamplate and vars file.

 

I wonder if there is default path for template and vars, so that I don't have to specify the whole absolute path, but reletive path instead.

 

1 REPLY 1
Highlighted
Junos Automation (Scripting)

Re: What is the default path of template and vars in juniper_junos_config

‎05-23-2018 11:28 AM

Hi,

 

When I build and commit configuration, I tend to use the following approach (in my case) with the variable junos_conf.

 

build_dir: /var/tmp/build
tmp_dir: '{{build_dir}}/{{inventory_hostname}}/tmp'
junos_conf: '{{build_dir}}/{{ inventory_hostname }}/junos.conf'

OK, perhaps a little overkill using three variables in this example, but in my setup I'm also capturing and storing XML data results from devices and that gets dumped into another variable too.  But, as you can see in the above, junos_conf will point to some location associated with each host in the inventory and finally to a file junos.conf

 

I'm using roles to generate the various parts of configuration from the templates, that structure follows the usual layout. e.g.

roles/
myRole/ defaults/ meta/ tasks/ templates/ vars/

Afterwhich, the task for the configuration generation would resemble.

- name: Creating some config
  template: src=foo.j2 dest={{ tmp_dir }}/foo.conf
- name: Creating more config template: src=bar.j2 dest={{ tmp_dir }}/bar.conf

This results in multiple .conf files created within the tmp_dir for each inventory host, and I use an assemble task to combine each of these different elements into the file junos.conf e.g.

- name: assembling configurations
  assemble:
    src: "{{ tmp_dir }}"
    dest: "{{ junos_conf }}"
    mode: "{{ conf_file_mode | default('666') }}"
    regexp: .+\.cfg

Then the final part of the equation being a role to commit the configuration to the device(s) which will just reference the source as being the variable {{ junos_conf }}.

 

Hope that this might help you.

 

Regards,

Andy

 

 

Feedback