# Do I have too many Jinja magic going on in my inventory?

**URL:** <https://forum.ansible.com/t/do-i-have-too-many-jinja-magic-going-on-in-my-inventory/38931>\
**Category:** Get Help\
**Tags:** jinja2\
**Created:** [December 5, 2024, 9:33pm UTC](https://forum.ansible.com/t/do-i-have-too-many-jinja-magic-going-on-in-my-inventory/38931 "2024-12-05T21:33:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thulium-Drake](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/thulium-drake/32/833_2.png) [@Thulium-Drake](https://forum.ansible.com/u/Thulium-Drake)\
**Post date:** [December 5, 2024, 9:33pm UTC](https://forum.ansible.com/t/do-i-have-too-many-jinja-magic-going-on-in-my-inventory/38931/1 "2024-12-05T21:33:33Z")

</div>

Hi folks,

So here I was, coding away and minding my own business, when I noticed that one of my tasks (rendering apache config files from a list, but that’s not important) wasn’t running as expected…

And it’s completely breaking my brain, I don’t understand what is going on. I wrote the following playbook:

```auto
---
- name: 'Ehh, wha?'
  hosts: 'target'
  tasks:
    - name: 'Show as is'
      ansible.builtin.debug:
        var: apache_apps

    - name: 'Force rendering'
      ansible.builtin.set_fact:
        apache_apps:
          - name: "{{ ansible_facts['fqdn'] }}"
            upstream: "http://localhost:8080"
            type: "simple-krb"
            cert: "/etc/ssl/ipa/{{ ansible_facts['fqdn'] }}/{{ ansible_facts['fqdn'] }}.crt"
            key: "/etc/ssl/ipa/{{ ansible_facts['fqdn'] }}/{{ ansible_facts['fqdn'] }}.key"
            extra_config_after_auth: |
              # Allow specific endpoints to bypass authentication
              <LocationMatch "^/(assets|cli|instance-identity|jnlpJars|static-files|whoAmI|wsagents)(/.*)?$">
                Require all granted
              </LocationMatch>
              RequestHeader set X-Forwarded-Host "{{ ansible_facts['fqdn'] }}"
              RequestHeader set X-Forwarded-Port "443"
            hsts: false
            encoded_slashes: "NoDecode"
            krb_passwd: true
            krb_strip_realm: true
            hbac_service: "jenkins"
            state: "present"

    - name: 'Show after rendering'
      ansible.builtin.debug:
        var: apache_apps

```

This is the variable in question (it’s a lab system, so I didn’t bother censoring anything):

```auto
apache_apps:
  - name: "{{ ansible_facts['fqdn'] }}"
    upstream: 'http://localhost:8080'
    type: 'simple-krb'
    cert: "/etc/ssl/ipa/{{ ansible_facts['fqdn'] }}/{{ ansible_facts['fqdn'] }}.crt"
    key: "/etc/ssl/ipa/{{ ansible_facts['fqdn'] }}/{{ ansible_facts['fqdn'] }}.key"
    extra_config_after_auth: |
      # Allow specific endpoints to bypass authentication
      <LocationMatch "^/(assets|cli|instance-identity|jnlpJars|static-files|whoAmI|wsagents)(/.*)?$">
        Require all granted
      </LocationMatch>
      RequestHeader set X-Forwarded-Host "{{ app['name'] }}"
      RequestHeader set X-Forwarded-Port "443"
    hsts: false
    encoded_slashes: 'NoDecode'
    krb_passwd: true
    krb_strip_realm: true
    hbac_service: 'jenkins'
    state: 'present'

```

And here’s the full output:

```auto
PLAY [Ehh, wha?] ****************************************************************************************

TASK [Show as is] ***************************************************************************************
task path: /opt/ansible/projects/rhlab/playbooks/.2163630.bla.yml:60
ok: [m-a18-01.rh.lab] => 
  apache_apps: 'VARIABLE IS NOT DEFINED!: [{''name'': "{{ ansible_facts[''fqdn''] }}", ''upstream'': ''http://localhost:8080'', ''type'': ''simple-krb'', ''cert'': "/etc/ssl/ipa/{{ ansible_facts[''fqdn''] }}/{{ ansible_facts[''fqdn''] }}.crt", ''key'': "/etc/ssl/ipa/{{ ansible_facts[''fqdn''] }}/{{ ansible_facts[''fqdn''] }}.key", ''extra_config_after_auth'': ''# Allow specific endpoints to bypass authentication\n<LocationMatch "^/(assets|cli|instance-identity|jnlpJars|static-files|whoAmI|wsagents)(/.*)?$">\n Require all granted\n</LocationMatch>\nRequestHeader set X-Forwarded-Host "{{ app[\''name\''] }}"\nRequestHeader set X-Forwarded-Port "443"\n'', ''hsts'': False, ''encoded_slashes'': ''NoDecode'', ''krb_passwd'': True, ''krb_strip_realm'': True, ''hbac_service'': ''jenkins'', ''state'': ''present''}]: ''app'' is undefined. ''app'' is undefined. [{''name'': "{{ ansible_facts[''fqdn''] }}", ''upstream'': ''http://localhost:8080'', ''type'': ''simple-krb'', ''cert'': "/etc/ssl/ipa/{{ ansible_facts[''fqdn'']
    }}/{{ ansible_facts[''fqdn''] }}.crt", ''key'': "/etc/ssl/ipa/{{ ansible_facts[''fqdn''] }}/{{ ansible_facts[''fqdn''] }}.key", ''extra_config_after_auth'': ''# Allow specific endpoints to bypass authentication\n<LocationMatch "^/(assets|cli|instance-identity|jnlpJars|static-files|whoAmI|wsagents)(/.*)?$">\n Require all granted\n</LocationMatch>\nRequestHeader set X-Forwarded-Host "{{ app[\''name\''] }}"\nRequestHeader set X-Forwarded-Port "443"\n'', ''hsts'': False, ''encoded_slashes'': ''NoDecode'', ''krb_passwd'': True, ''krb_strip_realm'': True, ''hbac_service'': ''jenkins'', ''state'': ''present''}]: ''app'' is undefined. ''app'' is undefined'

TASK [Force rendering] **********************************************************************************
task path: /opt/ansible/projects/rhlab/playbooks/.2163630.bla.yml:64
ok: [m-a18-01.rh.lab] => changed=false 
  ansible_facts:
    apache_apps:
    - cert: /etc/ssl/ipa/m-a18-01.rh.lab/m-a18-01.rh.lab.crt
      encoded_slashes: NoDecode
      extra_config_after_auth: |-
        # Allow specific endpoints to bypass authentication
        <LocationMatch "^/(assets|cli|instance-identity|jnlpJars|static-files|whoAmI|wsagents)(/.*)?$">
          Require all granted
        </LocationMatch>
        RequestHeader set X-Forwarded-Host "m-a18-01.rh.lab"
        RequestHeader set X-Forwarded-Port "443"
      hbac_service: jenkins
      hsts: false
      key: /etc/ssl/ipa/m-a18-01.rh.lab/m-a18-01.rh.lab.key
      krb_passwd: true
      krb_strip_realm: true
      name: m-a18-01.rh.lab
      state: present
      type: simple-krb
      upstream: http://localhost:8080

TASK [Show after rendering] *****************************************************************************
task path: /opt/ansible/projects/rhlab/playbooks/.2163630.bla.yml:86
ok: [m-a18-01.rh.lab] => 
  apache_apps:
  - cert: /etc/ssl/ipa/m-a18-01.rh.lab/m-a18-01.rh.lab.crt
    encoded_slashes: NoDecode
    extra_config_after_auth: |-
      # Allow specific endpoints to bypass authentication
      <LocationMatch "^/(assets|cli|instance-identity|jnlpJars|static-files|whoAmI|wsagents)(/.*)?$">
        Require all granted
      </LocationMatch>
      RequestHeader set X-Forwarded-Host "m-a18-01.rh.lab"
      RequestHeader set X-Forwarded-Port "443"
    hbac_service: jenkins
    hsts: false
    key: /etc/ssl/ipa/m-a18-01.rh.lab/m-a18-01.rh.lab.key
    krb_passwd: true
    krb_strip_realm: true
    name: m-a18-01.rh.lab
    state: present
    type: simple-krb
    upstream: http://localhost:8080

PLAY RECAP **********************************************************************************************
m-a07-01.rh.lab : ok=6 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0   
m-a18-01.rh.lab : ok=3 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0   

```

But what in the hell is going here?

```auto
ok: [m-a18-01.rh.lab] => 
  apache_apps: 'VARIABLE IS NOT DEFINED!: [{''name'': "{{ ans.......

```

Is this the result of too many Jinja magics in my inventory? I did a quick and dirty grep, there’s 247 lines that contain at least one `{{`, which doesn’t seem like a lot…

---

<div class="post-metadata">

**Author:** ![Denney-tech](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/denney-tech/32/1556_2.png) [@Denney-tech](https://forum.ansible.com/u/Denney-tech)\
**Post date:** [December 5, 2024, 10:03pm UTC](https://forum.ansible.com/t/do-i-have-too-many-jinja-magic-going-on-in-my-inventory/38931/2 "2024-12-05T22:03:10Z")

</div>

> [@Thulium-Drake](#):
>
> ‘‘app’’ is undefined. ‘‘app’’ is undefined’

In the extra\_config\_after\_auth key, your initial variable has an undefined `"{{ app['name'] }}"` variable, while your set\_fact step uses `"{{ ansible_facts['fqdn'] }}"` instead.

---

<div class="post-metadata">

**Author:** ![Thulium-Drake](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/thulium-drake/32/833_2.png) [@Thulium-Drake](https://forum.ansible.com/u/Thulium-Drake)\
**Post date:** [December 5, 2024, 10:14pm UTC](https://forum.ansible.com/t/do-i-have-too-many-jinja-magic-going-on-in-my-inventory/38931/3 "2024-12-05T22:14:29Z")

</div>

Oh wow… That’s dumb 😂

Fixed! Thanks for lending me your eyes! 😄

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [January 4, 2025, 10:14pm UTC](https://forum.ansible.com/t/do-i-have-too-many-jinja-magic-going-on-in-my-inventory/38931/4 "2025-01-04T22:14:55Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
