Error iterating over a dictionary in wordpress-setup role


I’ve just run the latest version of wordpress-setup role.

This is the line from wordpress-site.conf.j2:

server_name {% for host in site_hosts_canonical %}{{ host }} {% if item.value.multisite.subdomains | default(false) %}*.{{ host }} {% endif %}{% endfor %};

The iteration is over {{ wordpress_sites }}

Ansible complains that

“msg”: “AnsibleUndefinedVariable: ‘site_hosts_canonical’ is undefined”

When I look into the template for group_vars/wordpress_sites.yml, I see this:

      - canonical:

I’m not too experienced with Ansible, but I’m not sure how site_hosts_canonical is supposed to work here. There is no such variable or computed reference to an item from the dictionary. Correct me if I’m wrong, thanks!

Could you confirm that you updated all files as in roots/trellis#622? I suspect your files are missing the site_hosts_canonical definition in group_vars/all/helpers.yml, potentially among other things.

Hi @fullyint,

Indeed, I’ve only updated this one role and did not sync other files. I assumed that the role would be self-contained enough to work without external files being updated as well. Perhaps it’s worth considering moving theses essential vars to the defaults of the role itself so that it’s possible to updated trellis on a role-by-role basis? Just an idea. Thanks!

I support the goal of keeping roles self-contained, as much as possible.

The site_hosts_canonical var is used in the definition of the site_hosts var, which currently appears in more than one role (letsencrypt and wordpress-setup). Thus it seemed appropriate for these vars to not be in a single role’s defaults, but in group_vars/all.

I assumed people generally applied all updates, so I’m grateful to learn of the inclination to select only updates for single roles. I generally wouldn’t expect the functioning of one role to depend on updates to some other role. However, I would not be surprised for the functioning of any role to depend on updates to any group_vars, especially if the role and the group_vars were both updated within the same pull request.

1 Like

This is perfectly reasonable.

As far as updating the plays on role-by-role basis, it’s something I personally do all the time. I’ve already customized some of Trellis’ roles, others I do not apply at all - it all depends on a use case, and I bet there are lots of people who use Trellis same way - selectively, with customization. Thanks for help!

1 Like