Ansible 2.19 template change

You got most of the way there and provided a working reproducer, so it wasn’t too onerous to continue to pare it down (and it’s definitely better to provide a little too much than to provide so little context that the problem can’t be reproduced.)

The first thing to focus on is the template itself, since that’s what’s failing. It’s 38 entirely independent lines, and it’s unlikely that all of them are broken. So, remove lines until the template succeeds, then restore the last thing you removed. (Since these lines are independent you can speed this up by doing a binary search: remove half the lines, check for failure, then continue with the half where the failure is.) This can be quite irritating with more complex templates, but less irritating than having no idea where the failure occurs.

At that point if it’s not obvious why it’s failing you can start eliminating variables and tasks; replace set_fact with static variables, get rid of any variables that are no longer referenced, simplify and eliminate conditions and indirection and other structure. As long as running it still fails in the same way, you know that you haven’t gone too far and gotten rid of the wrong thing.

With a little effort you can pare this down to a short playbook:

- hosts: localhost
  vars:
    database:
      myRole2:
        type: ""
    myRole2InternalDbTypes:
      mssql: MsSQL
  tasks:
    - name: Template the configuration file
      ansible.builtin.template:
        src: silent_installation.conf.in
        dest: /tmp/silent_installation_auto.conf
        mode: "u=xrw,g=r,o=r"

And a one-line template:

service2_dbType="{{ (database.myRole2.type == '') | ansible.builtin.ternary('', myRole2InternalDbTypes[database.myRole2.type | lower]) }}"

that when run produce the error we’re interested in:

TASK [Template the configuration file] *****************************************
[ERROR]: Task failed: 'ansible._internal._templating._lazy_containers._AnsibleLazyTemplateDict object' has no attribute ''

Task failed.
Origin: /testing/ansible2.19-templateIssue/ansible/src/test.yml:9:7

7       mssql: MsSQL
8   tasks:
9     - name: Template the configuration file
        ^ column 7

<<< caused by >>>

'ansible._internal._templating._lazy_containers._AnsibleLazyTemplateDict object' has no attribute ''
Origin: /testing/ansible2.19-templateIssue/ansible/src/silent_installation.conf.in

fatal: [localhost]: FAILED! => {"changed": false, "msg": "Task failed: 'ansible._internal._templating._lazy_containers._AnsibleLazyTemplateDict object' has no attribute ''"}
1 Like