1. The problem I’m having:
Using the POST/PUT /config/path appends the object instead of replacing
2. Error messages and/or full log output:
No error log
Caddy starts out with a nearly blank config
{
"apps": {
"http": {
"servers": {
"homelab": {
"listen": [
":443"
],
"routes": [],
"tls_connection_policies": []
}
}
},
"tls": {
"certificates": {
"load_files": [
{
"certificate": "/certificates/ghastlylab.io.crt",
"key": "/certificates/ghastlylab.io.key",
"tags": [
"cert0"
]
}
]
}
}
}
}
Then I add a tls_connection_policy
curl -X POST "localhost:2019/config/apps/http/servers/homelab/tls_connection_policies/" \
-H "Content-Type: application/json" \
-d '
{
"certificate_selection": {
"any_tag": [
"cert0"
]
},
"match": {
"sni": [
"pdf.ghastlylab.io"
]
}
}'
Config after:
{
"apps": {
"http": {
"servers": {
"homelab": {
"listen": [
":443"
],
"routes": [],
"tls_connection_policies": [
{
"certificate_selection": {
"any_tag": [
"cert0"
]
},
"match": {
"sni": [
"pdf.ghastlylab.io"
]
}
}
]
}
}
},
"tls": {
"certificates": {
"load_files": [
{
"certificate": "/certificates/ghastlylab.io.crt",
"key": "/certificates/ghastlylab.io.key",
"tags": [
"cert0"
]
}
]
}
}
}
}
Running my ansible playbook again results in the same entry being appended.
{
"apps": {
"http": {
"servers": {
"homelab": {
"listen": [
":443"
],
"routes": [],
"tls_connection_policies": [
{
"certificate_selection": {
"any_tag": [
"cert0"
]
},
"match": {
"sni": [
"pdf.ghastlylab.io"
]
}
},
{
"certificate_selection": {
"any_tag": [
"cert0"
]
},
"match": {
"sni": [
"pdf.ghastlylab.io"
]
}
}
]
}
}
},
"tls": {
"certificates": {
"load_files": [
{
"certificate": "/certificates/ghastlylab.io.crt",
"key": "/certificates/ghastlylab.io.key",
"tags": [
"cert0"
]
}
]
}
}
}
}
After reading the PUT and POST config/[path] API docs I’m not sure if there is a way to create objects with an API call and do nothing with the same API call if the object already exists.
Tagging with @id
also didn’t work. What I noticed is that if I insert two policies with the same tag and do a DELETE to the tag only one entry gets removed and I have to make two DELETE calls to completly remove them.
I noticed this behaviour first on the tls_connection_policies, which I could circumvent, but the same problem happens on the route array as well. Running the same API call results in two identical routes which borks the config and the route/host isn’t working anymore
Is it possible to keep the config idempotent with the API?