Odd permission issue with caddy/ansible

Just to be clear up front, I don’t believe this is a caddy issue, but was curious if maybe someone else has ran in to this same or similar issue before and has any ideas.

I manage my caddy install on several load balancers with Ansible. It’s a fairly simple setup in that I define the Caddy config file and then use Ansible to push that to the required servers and restart/reload if needed. Any changes go through the same process.

I have an odd issue for new configs. In each site, I define an access log for that site. All of that is simply handled in the caddy config, I don’t create/pre-create the files with Ansible. When I push a new config out, it’s obvviously detected as a change and Ansible reloads the caddy service. However, for some reason, when caddy creates that initial log file, it’s creating it as the root user, which prevents caddy from properly reloading. If I do this exact same thing, push the exact same config all manually, the log file is correctly created as the caddy user and caddy is able to correctly reload.

Any thoughts on why, when pushed through Ansible, the logs files are being created as the root user? Again, I don’t believe this is a caddy issue, but it’s the only service that exhibits this kind of behavior when used with Ansible.

I don’t know Ansible at all. My guess, though, is Ansible is requesting the reload while Ansible’s privilege escalation is still in effect, so the log file creation would happen under root instead of user.

Can you follow the template that is given to you when you create a post? Not every item has to be filled out, but we definitely need to see Caddy logs, your Caddyfile, and how Caddy is installed and ran at minimum.