How to call {{ project_public_path }} in roles

Hi. We have defined php_fpm_slowlog in trellis/roles/wordpress-setup/defaults/main.yml

It works as long as we hardcode the path /srv/www/$pool.slow.log for example.

The problem arises when we want to have multiple staging environments, and the hardcoded paths don’t match up. I’ve tried defining php_fpm_slowlog: "{{ project_public_path }}/logs/$pool.slow.log" but that results in AnsibleUndefinedVariable: {{ project_public_path }}/logs/$pool.slow.log: ‘project_public_path’ is undefined

I don’t understand how to call this variable (which I saw being used in trellis/roles/deploy/defaults/main.yml) to help create create the file that we need to enable the slowlog

I’d follow the example of other tasks in that role which need the path: trellis/main.yml at c87f5026686df8bb28f8d55e38b998f5b78a9d62 · roots/trellis · GitHub

Though it depends on how you’re enabling the slowlog since you didn’t show how that’s done.

Hi @swalkinshaw . Good point. To enable slowlog, I placed the following in /roles/wordpress-setup/templates/php-fpm.conf.j2:

slowlog = {{ php_fpm_slowlog }}
request_slowlog_timeout = {{ php_fpm_request_slowlog_timeout }}

And now I tried putting the following in /roles/wordpress-setup/defaults/main.yml

php_fpm_slowlog: "{{ www_root }}/{{ item.key }}/logs/$pool.slow.log"

It still complains, saying: AnsibleUndefinedVariable: {{ www_root }}/{{ item.key }}/logs/$pool.slow.log: 'item' is undefined

Hardcoding the path works, but I still have a hard time understanding the way Ansible defines these variables/dicts.

Yeah it’s a bit confusing. That template file is used in this task: trellis/main.yml at eb202fa3058caabf94bd8cb31236ceaa08d60674 · roots/trellis · GitHub

Since it’s not site specific (there’s only one global template) it can’t be made site specific. If that task was run in a loop (loop: "{{ wordpress_sites | dict2items }}") like many other site related tasks… then using item.key would work.

So unfortunately Trellis won’t really allow this right now because it uses a single php-fpm pool for all sites; instead of one per site. I think you have two choices right now:

  1. just hardcode it; if you only have a single site then this is easy and probably fine. If you have multiple sites you could pick a non-site specific file location.
  2. refactor that template + task + Nginx conf to support one pool per site. Obviously that’s more complicated

Gotcha, I understand now. I appreciate it :pray: Ok, so I’ll hardcode the path at the site root then, I think