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

bootstrap_expect is wrong when using consul #132

Open blmhemu opened 3 years ago

blmhemu commented 3 years ago

In the below line, we are checking if consul is NOT enabled. But when consul is enabled, the bootstrap_expect is wrongly being set to 3 whatever be the actual count. This is causing nomad to fail in some cases.

https://github.com/ansible-community/ansible-nomad/blob/a1853f1cf1051f72ca4b3fc672a56686b42efce6/defaults/main.yml#L129

lsander22 commented 2 years ago

I had the same problem as you. You can fix the problem by initializing the variable nomad_servers differently in defaults/main.yml.

nomad_servers: "\
    {% set _nomad_servers = [] %}\
    {% for host in groups[nomad_group_name] %}\
      {% set _nomad_node_role = hostvars[host]['nomad_node_role'] | default('client', true) %}\
      {% if ( _nomad_node_role == 'server' or _nomad_node_role == 'both') %}\
        {% if _nomad_servers.append(host) %}{% endif %}\
      {% endif %}\
    {% endfor %}\
    {{ _nomad_servers }}\ "