# Sudden templating issue

**URL:** <https://forum.ansible.com/t/sudden-templating-issue/10571>\
**Category:** Get Help\
**Tags:** rhel, aap\
**Created:** [October 29, 2024, 2:50pm UTC](https://forum.ansible.com/t/sudden-templating-issue/10571 "2024-10-29T14:50:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![harry\_devine](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/harry_devine/32/5293_2.png) [@harry\_devine](https://forum.ansible.com/u/harry_devine)\
**Post date:** [October 29, 2024, 2:50pm UTC](https://forum.ansible.com/t/sudden-templating-issue/10571/1 "2024-10-29T14:50:43Z")

</div>

I have a playbook that gathers some information, then sets a fact based on that information. This has worked for over 2 years now. Over the weekend, the playbook started failing with an “unexpected templating type error”. Here’s the portion of the play:

```auto
  - name: Set List of users to get Disabled Warning message
    set_fact:
      warning_users: "{{ user_show.results | json_query('[*].json.result.result.{uid: uid[0], mail: mail[0], nsaccountlock: nsaccountlock, pwdexp: krbpasswordexpiration[0]. __datetime__ }') | selectattr('pwdexp','<',warning_date) | selectattr('nsaccountlock', 'equalto', False) | list }}"

```

Here’s the error:

fatal: [server1]: FAILED! =\> {“msg”: “Unexpected templating type error occurred on ({{ user\_show.results | json\_query(‘[\*].json.result.result.{uid: uid[0], mail: mail[0], nsaccountlock: nsaccountlock, pwdexp: krbpasswordexpiration[0]. **datetime** }’) | selectattr(‘pwdexp’,‘\<’,warning\_date) | selectattr(‘nsaccountlock’, ‘equalto’, False) | list }}): ‘\<’ not supported between instances of ‘NoneType’ and ‘AnsibleUnsafeText’. ‘\<’ not supported between instances of ‘NoneType’ and ‘AnsibleUnsafeText’”}

Any ideas on why this is suddenly no longer working? What I’m thinking that it could be was that on this server, Red Hat had me enable the ansible-automation-platform-2.4-for-rhel-8-x86\_64-rpms repository as we’re trying to install AAP on this server. Could this have caused something to change? Ansible core is version 2.15.12.

Thanks,  
Harry

---

<div class="post-metadata">

**Author:** ![jiholland](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jiholland/32/11273_2.png) [@jiholland](https://forum.ansible.com/u/jiholland)\
**Post date:** [October 29, 2024, 5:22pm UTC](https://forum.ansible.com/t/sudden-templating-issue/10571/2 "2024-10-29T17:22:10Z")

</div>

> [@harry\_devine](#):
>
> `selectattr('pwdexp','<',warning_date)`

> [@harry\_devine](#):
>
> ‘\<’ not supported between instances of ‘NoneType’ and ‘AnsibleUnsafeText’

Comparing a `NoneType` variable with `AnsibleUnsafeText` does not work, and it could be that you have an empty `pwdexp` variable in `user_show.results`.

```yaml
---
- name: Test playbook that will fail.
  hosts: localhost
  vars:
    users_show:
      results:
        - pwdexp: a
        - pwdexp: b
        # This is empty, and will cause the task to fail.
        - pwdexp:
    warning_date: c

  tasks:

    - name: Set List of users to get Disabled Warning message
      ansible.builtin.set_fact:
        warning_users: "{{ users_show['results'] | selectattr('pwdexp', '<', warning_date) | list }}"

```

---

<div class="post-metadata">

**Author:** ![harry\_devine](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/harry_devine/32/5293_2.png) [@harry\_devine](https://forum.ansible.com/u/harry_devine)\
**Post date:** [October 29, 2024, 6:03pm UTC](https://forum.ansible.com/t/sudden-templating-issue/10571/3 "2024-10-29T18:03:24Z")

</div>

How would I go about checking for an empty pwdexp value?

---

<div class="post-metadata">

**Author:** ![jiholland](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jiholland/32/11273_2.png) [@jiholland](https://forum.ansible.com/u/jiholland)\
**Post date:** [October 29, 2024, 7:25pm UTC](https://forum.ansible.com/t/sudden-templating-issue/10571/4 "2024-10-29T19:25:42Z")

</div>

I would start by printing the variable, and then break down the expression step by step from there.

```yaml
- name: Print variable.
  ansible.builtin.debug:
    msg: "{{ user_show.results }}"

- name: Print variable with first filter.
  ansible.builtin.debug:
    msg: "{{ user_show.results | json_query('[*].json.result.result.{uid: uid[0], mail: mail[0], nsaccountlock: nsaccountlock, pwdexp: krbpasswordexpiration[0]. __datetime__ }') }}"

```
