Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug when cold starting using caddy_config_mode = "Caddyfile" #218

Open
wjessop opened this issue Nov 30, 2024 · 0 comments
Open

Bug when cold starting using caddy_config_mode = "Caddyfile" #218

wjessop opened this issue Nov 30, 2024 · 0 comments

Comments

@wjessop
Copy link

wjessop commented Nov 30, 2024

Thank you for writing and releasing this code, it's appreciated!

I have a role, it contains something like this:

- name: Run the Caddy role
  include_role:
    name: maxhoesel.caddy.caddy_server
  vars:
    caddy_apply_config: true
    caddy_config_mode: Caddyfile
    caddy_caddyfile: |
            localhost:80
            respond "This is the production config"

This fails at the "Caddy is running" task (roles/caddy_server/tasks/main.yml) when run for the first time, the log on the OS being:

Error: reading config file: open /etc/caddy/Caddyfile: no such file or directory

This makes sense, caddy will not start with no config file present, and we never get to the "Configure Caddy" step which would create the Caddyfile. I can work around this by creating a stub config file to be overwritten by the real config later:

- name: Check if Caddyfile exists
  stat:
    path: /etc/caddy/Caddyfile
  register: result

# The caddy server doesn't start unless there's a Caddyfile present, create one if it's absent
- name: Create a stub Caddyfile
  when: not result.stat.exists
  copy:
    dest: /etc/caddy/Caddyfile
    content: |
            localhost:80
            respond "Hello, world!"

- name: Run the Caddy role
  include_role:
    name: maxhoesel.caddy.caddy_server
  vars:
    caddy_apply_config: true
    caddy_config_mode: Caddyfile
    caddy_caddyfile: |
            localhost:80
            respond "This is the production config"

However, that's kind of a hack and I'm not sure it was intended to work this way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant