Search code examples
jsonjinja2watchconsulhashicorp

Consul config with multiply watches


I am a newbie with Hasicorp Consul. I want to add to the Hashicorp Consul (v.1.7.1) watches config file the second service to be watched. How should it be done correctly?

I've tried several variants, but none of them is working. In this case it warks for service-2, but ignores service-1.

{
  "watches": [{
      "type": "service",
      "service": "service-1",
            "tag": [ "tag1","tag2","tag3"],
            "args": ["./script.sh"],
      "type": "service",
      "service": "service-2",
            "tag": [ "tag1","tag2","tag3"],
            "args": ["./script.sh"]
  }]
}

Solution

  • Watches is a list of watch specifications, so each individual watch needs to be a separate dict/hash item in the array.

    The following config snippet should successfully fire a watch for each specified service.

    {
      "watches": [
        {
          "type": "service",
          "service": "service-1",
          "tag": [
            "tag1",
            "tag2",
            "tag3"
          ],
          "args": [
            "./script.sh"
          ]
        },
        {
          "type": "service",
          "service": "service-2",
          "tag": [
            "tag1",
            "tag2",
            "tag3"
          ],
          "args": [
            "./script.sh"
          ]
        }
      ]
    }