AnsibleError: unexpected templating type error

While running provision script to provision a newly created droplet, I ran into this error. Googling didn’t help me much. Could anyone point out what the cause is and how I can further debug this? Thank you.

TASK [letsencrypt : Create needed Nginx confs for challenges] ******************
System info:
  Ansible 2.2.1.0; Darwin
  Trellis at "Add `bin/xdebug-tunnel.sh` to manage Xdebug and SSH tunnels on remote hosts"
---------------------------------------------------
AnsibleError: Unexpected templating type error occurred on (server {
  listen 80;
  server_name{% for item in item.item.value.site_hosts %} {{ item.canonical
}}{% for redirect in item.redirects | default([]) %} {{ redirect }}{% endfor
%}{% endfor %};
  include acme-challenge-location.conf;
}
): 'NoneType' object is not iterable
failed: [138.197.105.183] (item=oshp.conceptual.site) => {"failed": true, "item": "oshp.conceptual.site"}
	to retry, use: --limit @/Users/conceptualcode/Workspace/onestarhouseparty.com/trellis/server.retry

PLAY RECAP *********************************************************************
138.197.105.183            : ok=83   changed=4    unreachable=0    failed=1
localhost                  : ok=0    changed=0    unreachable=0    failed=0

This probably indicates a yaml problem with your site_hosts. My first guess would be that your redirects is just empty, like this:

wordpress_sites:
  example.com:
    site_hosts:
      - canonical: example.com
        redirects:
    local_path: ../site # path targeting local Bedrock site directory (relative to Ansible root)
    ...

Ansible loads a YAML variable without a value as the python None, whose type is NoneType and indeed 'NoneType' object is not iterable, as it needs to be for the loop: {% for redirect in item.redirects | default([]) %}.

If the problem is with redirects and you simply don’t have any redirects, just remove redirects completely, or comment it out, or specify it as an empty list, e.g., redirects: []

Here is some discussion on the YAML structure of site_hosts.

If the above doesn’t clear it up, feel free to post your wordpress_sites for review.

4 Likes

You are right, I commented out redirects entry. I will try to remove that completely now. Thank you for the support. I appreciate it :smiley:

2 Likes