QBits
QBits

Reputation: 141

How do I reference dictionary? items in Ansible

I had to change the playbooks because the acl_profile_namecan be more than 1. Now I want to reference gama-ansible and loop through - "*/rw/export/mobile/>" and - "*/rw/export/supplyChain/>" :

acl_allow_subscribe:
  acl_profile_name: gama-ansible
    - "*/de/export/mobile/>"
    - "*/de/export/supplyChain/>" 

  acl_profile_name: beta-ansible
    - "*/uk/import/mobile/>"
    - "*/uk/import/supplyChain/>" 

reference them here:

- name: Add ACL Publish Exception
  solace_acl_subscribe_topic_exception:
    name: "{{item}}"
    acl_profile_name: "{{ item.value.acl_profile_name }}"
    msg_vpn: "{{ msg_vpn }}"
    topic_syntax: mqtt
    semp_version: "{{ ansible_facts.solace.about.api.sempVersion }}"
  loop: "{{acl_allow_subscribe}}"

I get the error "The error was: 'acl_profile_name' is undefined\n\n"

Before I changed the yaml files it was working fine and looked like this:

 acl_profile_name: "gama-ansible"

 acl_allow_subscribe:
 - "*/de/export/mobile/>"
 - "*/de/export/supplyChain/>"

referenced this way:

- name: Add ACL Subscribe Exception
  solace_acl_subscribe_topic_exception:
    name: "{{item}}"
    acl_profile_name: "{{ acl_profile_name }}"
    msg_vpn: "{{ msg_vpn }}"
    topic_syntax: mqtt
    semp_version: "{{ ansible_facts.solace.about.api.sempVersion }}"
  loop: "{{acl_allow_subscribe}}"

I tried to implement it this way (based on the first comment from @gary lopez below) but I get an error:

what I want to reference: (notice : the - acl_profile_name: idocument under acl_allow_subscribe has no values)

    acl_allow_subscribe:
      - acl_profile_name: gama-ansible
        values:
          - "*/de/export/mobile/>"
          - "*/de/export/supplyChain/>"
    
      - acl_profile_name: idocument
        values:

 

    acl_allow_publish:
      - acl_profile_name: gama-ansible
        values:
            - "*/uk /export/mobile/>"
            - "*/uk/export/mobile/>"
    
      - acl_profile_name: idocument
        values:
          - "*/de/idoc/>"
          - "*/de/idoc/>"

This is how I referenced it:

- name: Remove ACL Profile
  solace_acl_profile:
    name: "{{ item.0.acl_profile_name }}"
    msg_vpn: "{{ msg_vpn }}"
    state: absent

- name: Add ACL Profile
  solace_acl_profile:
    name: "{{ item.0.acl_profile_name }}"
    msg_vpn: "{{ msg_vpn }}"
    settings:
      clientConnectDefaultAction: allow
      
- name: Update ACL Profile
  solace_acl_profile:
    name: "{{item.0.acl_profile_name}}"
    msg_vpn: "{{ msg_vpn }}"
    settings:
      publishTopicDefaultAction: disallow

# PUBLISH
- name: Remove ACL Publish Exception
  solace_acl_publish_topic_exception:
    name: "{{item.1}}"
    acl_profile_name: "{{ item.0.acl_profile_name }}"
    msg_vpn: "{{ msg_vpn }}"
    state: absent
    semp_version: "{{ ansible_facts.solace.about.api.sempVersion }}"
  loop: "{{acl_allow_publish}}" 

- name: Add ACL Publish Exception
  solace_acl_publish_topic_exception:
    name: "{{item.1}}"
    acl_profile_name: "{{ item.0.acl_profile_name }}"
    msg_vpn: "{{ msg_vpn }}"
    topic_syntax: mqtt
    semp_version: "{{ ansible_facts.solace.about.api.sempVersion }}"
  with_subelements:
    - "{{ acl_allow_publish }}"
    - values

# SUBSCRIBE
- name: Remove ACL Subscribe Exception
  solace_acl_subscribe_topic_exception:
    name: "{{item.1}}"
    acl_profile_name: "{{ item.0.acl_profile_name }}"
    msg_vpn: "{{ msg_vpn }}"
    state: absent  
    semp_version: "{{ ansible_facts.solace.about.api.sempVersion }}" 
  with_subelements:
    - "{{ acl_allow_subscribe }}"
    - values
- name: Add ACL Subscribe Exception
  solace_acl_subscribe_topic_exception:
    name: "{{item.1}}"
    acl_profile_name: "{{ item.0.acl_profile_name }}"
    msg_vpn: "{{ msg_vpn }}"
    topic_syntax: mqtt
    semp_version: "{{ ansible_facts.solace.about.api.sempVersion }}"
  with_subelements:
    - "{{ acl_allow_subscribe }}"
    - values

While referencing it has to loop over the acl_profile_names and the values

Upvotes: 0

Views: 256

Answers (1)

gary lopez
gary lopez

Reputation: 1954

In your case acl_allow_subscribe is not a list. Your could try it in this way

acl_allow_subscribe:
  - acl_profile_name: gama-insible
    values:
      - "*/de/export/mobile/>"
      - "*/de/export/supplyChain/>"

  - acl_profile_name: beta-ansible
    values:
      - "*/uk/import/mobile/>"
      - "*/uk/import/supplyChain/>"

and referenced in this way

- name: Add ACL Publish Exception
  solace_acl_subscribe_topic_exception:
    name: "{{item.1}}"
    acl_profile_name: "{{ item.0.acl_profile_name }}"
    msg_vpn: "{{ msg_vpn }}"
    topic_syntax: mqtt
    semp_version: "{{ ansible_facts.solace.about.api.sempVersion }}"
  with_subelements:
    - "{{ acl_allow_subscribe }}"
    - values

Upvotes: 1

Related Questions