Ansible 2.15 Filter expression is not being evaluated when called from JSON

45 Views Asked by At

Environment (I am using ansible-navigator to run playbooks so the environment is within a podman container):

ansible [core 2.15.5]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/runner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.9/site-packages/ansible
  ansible collection location = /runner/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.9.16 (main, Sep 22 2023, 17:57:55) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] (/usr/bin/python3.9)
  jinja version = 3.1.2
  libyaml = True

So basically I have a json file which contains some Ansible Filter expressions which I want to call and evaluate dynamically here is an example:

{"testios": [{"name": "Check1", "tests": ["string_example | regex_search('THIS TEST ENTRY SHOULD BE FALSE')"]}]}

And then I load the test var with something like this

- name: "Load test var"
  set_fact:
    test_unsafe: "{{ lookup('vars', 'test', allow_unsafe=true)[0] }}"

- name: "Jinjafy"
  set_fact:
    jinjafied_test: "{{ '{{' }}{{ test_unsafe }}{{ '}}' }}"

And instead of Ansible Evaluating my expression it simply gives back a templated string.

ok: [host1] => {
    "jinjafied_test": "{{string_example | regex_search('THIS TEST ENTRY SHOULD BE FALSE')}}"
}

This was working just fine, in Ansible 2.9.13, this is a very simple example the json can get a lot more "complex" with the tests.

Any inputs here? any known changes affecting this? someone else in the same boat?

0

There are 0 best solutions below