Issue passing Set_Facts variable from one playbook to another

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:
      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 (as below), I can see that the fact is being passed through to the next playbook, but it doesn’t seem to be presented to the meraki collection properly. I’ve tested with just putting a network ID in manually and it returns data, so it has to be something with my code.

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

Apologies if this is in the wrong forum, but just wondered if someone had come across something similar at all?

Cheers
Neil

set_fact does not create an ansible_fact but a host scoped variable, which has higher precedence than facts and is accessible both directly networkId: “{{ FACT_Network_ID }}” or via hostvars. The action has a confusing name, but we did modify it to add an option, cacheable, that when set to True , will in addition to the previous var, also create an actual fact.

Thanks for the update.

I’ve tried this, but still doesn’t seem to work. Not sure if its something in the dictionary for Meraki when setting the networkId: and it not liking it being a variable as the string.

Is there a way to debug what the module and see what it has built for the URL during the playbook running? Apologies i know this is very Meraki specific, but also part Ansible-y as well. :slight_smile:

Cheers
Neil

If using -vvv you should see extended results for the module, but for debug you could just do:

msg: “{{ result }}”

to see the structure, just be aware that data types get messy with the debug action, use |type_debug to ensure things are what you expect for specific keys.