maxhoesel.caddy.caddy_config module – Push configuration to a given path in the caddy config

Note

This module is part of the maxhoesel.caddy collection (version 1.1.0).

To install it, use: ansible-galaxy collection install maxhoesel.caddy. You need further requirements to be able to use this module, see Requirements for details.

To use it in a playbook, specify: maxhoesel.caddy.caddy_config.

New in maxhoesel.caddy 0.1.0

Synopsis

  • This modules can update the configuration stored at any valid path in the caddy config API. It is idempotent in that it will not change the config if no changes are present. You can select between all update modes supported by Caddy

Requirements

The below requirements are needed on the host that executes this module.

  • requests must be installed on the host executing the query

Parameters

Parameter

Comments

append

boolean

If set and path points to an existing array or array index, the module will tell Caddy to append/insert to the array (using the APIs POST/PUT method), instead of replacing the array/array index (API PATCH method). See the Caddy API Documentation for details.

Choices:

  • false ← (default)

  • true

caddy_host

string

Address of the caddy API endpoint

Default: "http://localhost:2019"

content

aliases: config, value

any

Content to push to the specified path. Must be a dict or list corresponding to the API JSON format. Required if state=present.

create_path

boolean

added in maxhoesel.caddy 0.2.0

Whether to create the path pointing to the configuration if it doesn’t exist yet. For example, if path=apps/http/servers/myservice and apps/http/servers does not exist yet, the required path entries will be created. Note that any digit path segments are treated as array indices.

Choices:

  • false

  • true ← (default)

force

boolean

By default, this module only pushes configurations if changes have been made compared to the currently running config. Set force=True if you always want to push the configuration, even if no changes will be made. Settings this will cause the module to always return changed=True

Choices:

  • false ← (default)

  • true

path

aliases: name

path / required

Configuration path to which the configuration content will be pushed. Note that the path if is automatically prefixed with config/. Example: apps/http/servers/myservice

state

string

If present, the configuration content at path will be created or updated. If absent, any existing configuration at path will be removed.

Choices:

  • "present" ← (default)

  • "absent"

Notes

Note

  • Check mode is supported.

Examples

- name: Ensure HTTP server configuration is present
  maxhoesel.caddy.caddy_config:
    path: apps/http/servers/myserver
    content:
      listen:
        - ":2015"
      routes:
        - handle:
          - handler: static_response
            body: Hello World!

- name: Ensure HTTP server config is absent
  maxhoesel.caddy.caddy_config:
    path: apps/http/servers/myserver
    state: absent

Authors

  • Max Hösel (@maxhoesel)