Consul Automation for Rolling Configuration Changes with Ansible

I’m using ansible to deploy consul via zip/unarchive to on prem linux servers. I’ve been trying to work out how to make rolling configuration changes and updates to the deployments. Some configurations are reloadable - others require a restart/rejoin before moving on to the next node - I realize I can do something like get the nodes back via consul members and then check the results against the current node using ansible variables but I am unsure this is the best approach for rolling upgrades and config changes.

I have a very similar setup and the approach I’ve taken is to detect if consul is already running and then send a consul leave on that machine. Afterwards I shut down consul, apply changes, and then bring it back up. So far so good. I do follow the guidelines in the docs about updating the leader last so this isn’t a completely hands-off system but I don’t mind that.

- name: Get consul service Status
    name: "consul"
    state: started
  register: consul_service_status
  ignore_errors: true
  tags: always

- debug:
    var: consul_service_status
  tags: always
  ignore_errors: true

- name: gracefully leave the consul cluster
  shell: consul leave
  tags: update
  ignore_errors: true
  when: "'consul_server' in group_names and consul_service_status.state == 'started'"

Thank you for sharing I will try this