Home > Back-end >  AnsibleUnsafeText and AnsibleUndefined for dict in included task
AnsibleUnsafeText and AnsibleUndefined for dict in included task

Time:12-15

I need to loop on a list of dictionaries. I include a tasks file using with_items on my list.

When I try to execute tasks inside included file I get "AnsibleUnsafeText" and "AnsibleUndefined" on 2 dictionaries of my elemets but NOT inside the main file.

Main file

---
- name: Devel New Role
  hosts: localhost
  become: true
  gather_facts: yes

  vars:
    my_list:
      - ext_myapp_customer: dev02
        ext_myapp_spid_enabled: false
        ext_myapp_shib_auth:
          idpidentityid: https://idp-myapp.myapp.com/idp/shibboleth
          remote_user: uid 
          attribute_map:
            shibb-lastname: urn:oid:2.5.4.4
            shibb-firstname: urn:oid:2.5.4.42
            shibb-email: urn:oid:0.9.2342.19200300.100.1.3
            shibb-username: urn:oid:2.16.840.1.113730.3.1.3
            shibb-fiscalcode: urn:oid:0.9.2342.19200300.100.1.1
          sso_logout_url: https://idp.myapp.com/idp/profile/Logout
          urimdprv: https://idp-md.myapp.com/idp/shibboleth
        ext_myapp_auth: shibboleth
      - ext_myapp_customer: dev03
        ext_myapp_spid_enabled: false
        ext_myapp_shib_auth:
          idpidentityid: https://idp-myapp.myapp.com/idp/shibboleth
          remote_user: uid 
          attribute_map:
            shibb-lastname: urn:oid:2.5.4.4
            shibb-firstname: urn:oid:2.5.4.42
            shibb-fiscalcode: urn:oid:0.9.2342.19200300.100.1.1
            shibb-username: urn:oid:2.16.840.1.113730.3.1.3
            shibb-email: urn:oid:0.9.2342.19200300.100.1.3
          sso_logout_url: https://idp.myapp.com/idp/profile/Logout
          urimdprv: https://idp-md.myapp.com/idp/shibboleth
        ext_myapp_auth: shibboleth

  tasks:
    - name: Debug single elements
      debug:
        msg:
          - "ext_myapp_shib_auth: {{ item.ext_myapp_shib_auth }}"
          - "attribute_map: {{ item.ext_myapp_shib_auth.attribute_map }}"
          - "ext_myapp_shib_auth type: {{ item.ext_myapp_shib_auth | type_debug}}"
          - "attribute_map type: {{ item.ext_myapp_shib_auth.attribute_map | type_debug }}"
      with_items: '{{ my_list }}'


    - name: Configure attribute-map for customer
      include_tasks: "included_task.yml"
      vars:
        ext_myapp_customer: "{{ item.ext_myapp_customer }}"
        ext_myapp_auth: "{{ item.ext_myapp_auth }}"
        ext_myapp_spid_enabled: "{{ item.ext_myapp_spid_enabled }}"
        ext_myapp_shib_auth: " {{ item.ext_myapp_shib_auth }}"
      with_items: '{{ my_list }}'  

included_task.yml

  - name: Inside debug
    debug:
      msg:
        - "ext_myapp_shib_auth: {{ ext_myapp_shib_auth }}"
#        - "attribute_map: {{ ext_myapp_shib_auth.attribute_map }}"
        - "ext_myapp_shib_auth type: {{ ext_myapp_shib_auth | type_debug}}"
        - "attribute_map type: {{ ext_myapp_shib_auth.attribute_map | type_debug }}"

Output

TASK [Debug single elements] 

[...]

=> {
    "msg": [
        "ext_myapp_shib_auth: {u'idpidentityid': u'https://idp-myapp.myapp.com/idp/shibboleth', u'remote_user': u'uid mail cn eppn', u'attribute_map': {u'shibb-lastname': u'urn:oid:2.5.4.4', u'shibb-firstname': u'urn:oid:2.5.4.42', u'shibb-email': u'urn:oid:0.9.2342.19200300.100.1.3', u'shibb-username': u'urn:oid:2.16.840.1.113730.3.1.3', u'shibb-fiscalcode': u'urn:oid:0.9.2342.19200300.100.1.1'}, u'sso_logout_url': u'https://idp.myapp.com/idp/profile/Logout', u'urimdprv': u'https://idp-md.myapp.com/idp/shibboleth'}", 
        "attribute_map: {u'shibb-lastname': u'urn:oid:2.5.4.4', u'shibb-firstname': u'urn:oid:2.5.4.42', u'shibb-email': u'urn:oid:0.9.2342.19200300.100.1.3', u'shibb-username': u'urn:oid:2.16.840.1.113730.3.1.3', u'shibb-fiscalcode': u'urn:oid:0.9.2342.19200300.100.1.1'}", 
        "ext_myapp_shib_auth type: dict", <-------- DICT
        "attribute_map type: dict"        <-------- DICT
    ]
}

[...]

TASK [Configure attribute-map for customer] *********************************************************************************************************************************************
included: /home/cin0633a/progetti/ansible/testenv/included_task.yml for localhost
included: /home/cin0633a/progetti/ansible/testenv/included_task.yml for localhost

TASK [Inside debug] 

[...]

ok: [localhost] => {
    "msg": [
        "ext_myapp_shib_auth:  {u'idpidentityid': u'https://idp-myapp.myapp.com/idp/shibboleth', u'remote_user': u'uid mail cn eppn', u'sso_logout_url': u'https://idp.myapp.com/idp/profile/Logout', u'attribute_map': {u'shibb-lastname': u'urn:oid:2.5.4.4', u'shibb-firstname': u'urn:oid:2.5.4.42', u'shibb-fiscalcode': u'urn:oid:0.9.2342.19200300.100.1.1', u'shibb-username': u'urn:oid:2.16.840.1.113730.3.1.3', u'shibb-email': u'urn:oid:0.9.2342.19200300.100.1.3'}, u'urimdprv': u'https://idp-md.myapp.com/idp/shibboleth'}", 
        "ext_myapp_shib_auth type: AnsibleUnsafeText", <---- WHAT !!!
        "attribute_map type: AnsibleUndefined"         <---- WHAT !!!
    ]
}

I can't use these dictionaries inside my included tasks! Why this happens and how can I solve the problem?

CodePudding user response:

        ext_myapp_shib_auth: " {{ item.ext_myapp_shib_auth }}"

You've added an extraneous space at the beginning of the value, which forces it to be interpreted as a string instead of a data structure.

  • Related