Ansible Query to get Network ID for further playbooks.

NeilB
Getting noticed

Ansible Query to get Network ID for further playbooks.

Hi,

 

So, i'm not sure if this is the right way to complete this task and not really a Meraki specific thing, but through i would ask the question.

 

So I'm using the below code to grab the Network ID for a specific network 

 

 get_network.yaml
---
  - name: Get_Networks
    hosts: localhost
    gather_facts: false
    vars:
        network_name_query: "meraki_response[?name=='{{ Network_Name }}'].id"
    vars_prompt:
    - name: Network_Name
      prompt: Please Enter the Network Name
      private: false
    tasks:

    - name: Get Specific Org Network
      cisco.meraki.networks_info:
        organizationId: <INSERT ORG ID> 
 
        meraki_suppress_logging: true
      register: result

    - name: Set Network ID Fact
      set_fact:
        FACT_Network_ID: "{{ result | json_query(network_name_query) }}"
        cacheable: true
 
 
When running this, It sets the NetworK ID of the name you enter in the Prompt as a fact for use in another playbook.
 
get_l3_fw_rules.yaml
---
  - name: Get_L3_Firewall_Rules
    hosts: localhost
    gather_facts: false
    tasks:

    - name: Get L3 Firewall Rules
      cisco.meraki.networks_appliance_firewall_l3_firewall_rules_info:
        networkId: "{{ ansible_facts['FACT_Network_ID'] }}"
      register: result

    - name: Show All Firewall Rules
      ansible.builtin.debug:
        msg: "{{ result.meraki_response.rules }}"
 
 
 
If I run the two playbooks together... I.E
get_rules_for specific_network.yaml
---
- name: Get Network ID
   import_playbook: Get_Network.yaml 
- name: Get L3 Firewall Rules
   import_playbook: Get_L3_FW_Rules.yaml 
 
 
 
I've verified with some debugs to ensure the ID is being gathered correctly and added to the fact successfully, but it doesn't seem to pass that variable into the L3 Firewall Rules play correctly. 
 
Apologies if this is in the wrong forum, but just wondered if someone had come across something similar at all?
 
Cheers
Neil
1 Reply 1
alemabrahao
Kind of a big deal
Kind of a big deal

You can try using add_host to create a temporary host with variables attached.

I am not a Cisco Meraki employee. My suggestions are based on documentation of Meraki best practices and day-to-day experience.

Please, if this post was useful, leave your kudos and mark it as solved.
Get notified when there are additional replies to this discussion.