ansible-community / ansible-nomad

:watch: Ansible role for Nomad
https://galaxy.ansible.com/brianshumate/nomad
BSD 2-Clause "Simplified" License
294 stars 163 forks source link

Nomad 1.7.0 compatibility issue with 'consul' Block #179

Closed madsboddum closed 7 months ago

madsboddum commented 9 months ago

I just tried to upgrade from 1.6.3 to the new 1.7.0 release.

Dec 08 10:59:04 web14.survey-it.dk systemd[1]: Started nomad agent.
Dec 08 10:59:04 web14.survey-it.dk nomad[3886575]: ==> Error loading configuration from /etc/nomad.d: Error loading /etc/nomad.d/base.hcl: error parsing 'consul': 1 error(s) decoding:
Dec 08 10:59:04 web14.survey-it.dk nomad[3886575]: * 'tags[0]' expected type 'string', got unconvertible type 'map[string]interface {}', value: 'map[]'
Dec 08 10:59:04 web14.survey-it.dk systemd[1]: nomad.service: Main process exited, code=exited, status=1/FAILURE
Dec 08 10:59:04 web14.survey-it.dk systemd[1]: nomad.service: Failed with result 'exit-code'.
Dec 08 11:00:19 web14.survey-it.dk systemd[1]: Stopped nomad agent.

The consul Block in /etc/nomad.d/base.hcl looks like this:

consul {
    # The address to the Consul agent.
    address = "192.168.80.48:8500"
    ssl = false
    ca_file = ""
    cert_file = ""
    key_file = ""
    token = ""
    # The service name to register the server and client with Consul.
    server_service_name = "nomad-servers"
    client_service_name = "nomad-clients"
    tags = {}

    # Enables automatically registering the services.
    auto_advertise = true

    # Enabling the server and client to bootstrap using Consul.
    server_auto_join = true
    client_auto_join = true
}

It seems like tags can no longer be {} for whatever reason. Link to docs for convenience: https://developer.hashicorp.com/nomad/docs/configuration/consul#tags

madsboddum commented 9 months ago

We found a workaround for this by simply defining some tags in nomad_consul_tags, like so:

nomad_consul_tags:
  - test1
  - test2

... which makes the consul Block look like this:

consul {
    # The address to the Consul agent.
    address = "192.168.80.48:8500"
    ssl = false
    ca_file = ""
    cert_file = ""
    key_file = ""
    token = ""
    # The service name to register the server and client with Consul.
    server_service_name = "nomad-servers"
    client_service_name = "nomad-clients"
    tags = ["test1", "test2"]

    # Enables automatically registering the services.
    auto_advertise = true

    # Enabling the server and client to bootstrap using Consul.
    server_auto_join = true
    client_auto_join = true
}

It is now formatted as an actual array instead of an object.

madsboddum commented 9 months ago

A possible fix could be changing the default value for nomad_consul_tags, perhaps?

https://github.com/ansible-community/ansible-nomad/blob/master/defaults/main.yml#L163C1-L163C18

### Consul
nomad_use_consul: false
nomad_consul_address: "localhost:8500"
nomad_consul_ssl: false
nomad_consul_ca_file: ""
nomad_consul_cert_file: ""
nomad_consul_key_file: ""
nomad_consul_token: ""
nomad_consul_servers_service_name: "nomad-servers"
nomad_consul_clients_service_name: "nomad-clients"
nomad_consul_tags: {} # <----- THIS

Simply having: nomad_consul_tags: [] Solves the problem for us.

consul {
    # The address to the Consul agent.
    address = "192.168.80.32:8500"
    ssl = false
    ca_file = ""
    cert_file = ""
    key_file = ""
    token = ""
    # The service name to register the server and client with Consul.
    server_service_name = "nomad-servers"
    client_service_name = "nomad-clients"
    tags = []

    # Enables automatically registering the services.
    auto_advertise = true

    # Enabling the server and client to bootstrap using Consul.
    server_auto_join = true
    client_auto_join = true
}
sas1024 commented 7 months ago

Same issue with Nomad 1.7.x

nomad_consul_tags: [] really solves this problem.

@rndmh3ro could you please change this line in defaults/main.yml ?

rndmh3ro commented 7 months ago

@sas1024, would you mind creating a PR for this? :)

sas1024 commented 7 months ago

@rndmh3ro sure, done :)

rndmh3ro commented 7 months ago

fixed by #190

madsboddum commented 7 months ago

I just used the new version of the role on our Nomad 1.7.3 agents without the nomad_consul_tags: [] workaround and I can confirm that it works now.

Thanks!