Junos Automation (Scripting)
Highlighted
Junos Automation (Scripting)

junos/ansiboe/pyez/netconf

‎05-26-2019 02:44 AM

I'm trying to experiment with ansible and I'm not sure if I can set a provider globally (ie. for the whole playbook) instead of "per task: eg.:

 

---
- name: Get port information
  juniper_junos_table:        
    provider: "{{ netconf }}"
    file: "ethport.yml"
    table: "EthPortTable"
  register: response

I don't really want to set it for every single task (as it's always the same anyway) so... is there any way of setting the provider "globally" (or authenticate in some other way)?

 

 

3 REPLIES 3
Junos Automation (Scripting)

Re: junos/ansiboe/pyez/netconf

‎06-12-2019 05:01 AM

I don't believe that there is a global provider approach that can be used. 

Junos Automation (Scripting)

Re: junos/ansiboe/pyez/netconf

‎06-12-2019 05:39 AM

Hi damanloox.

 

There is option since Ansible 2.6 to specify default module attribute values per each module once per play using the "module_defaults" directive.

 

Documentation: https://docs.ansible.com/ansible/latest/user_guide/playbooks_module_defaults.html

 

In your case the playbook could look like:

 

--- 
- name:  Get port information
  hosts: JUNIPER
  roles:
     - Juniper.junos
  module_defaults:
     juniper_junos_table:
        provider: "{{ netconf }}"
  connection: local
  gather_facts: no

  tasks:
  - name:  Get port information
    juniper_junos_table:
       file: "ethport.yml"
       table: "EthPortTable"
    register: response

I tested this in Ansible 2.8.1 with success.

 

Hope this helps.

 

 


 

Regards
Luděk Matoušek
JNCIS-ENT, JNCIS-SP, JNCIP-SEC, JNCIA-DevOps
Junos Automation (Scripting)

Re: junos/ansiboe/pyez/netconf

‎06-12-2019 06:21 AM

That's really good to know!  Many thanks for giving me something new to learn today.

 

I've also verified that it works in Ansible 2.7.0

 

Regards,

Andy