| --- |
| # This role will install Consul Servers/Agents in all machines. After that it installs the Registrators. |
| # There is a group of machines in the corresponding environment inventory called 'consul_servers' where the Consul Servers are installed |
| # In this way they build up a Consul Cluster |
| # Other machines that are not in the 'consul_servers' group, have the Consul Agents |
| # The template 'config.json.j2' will look at the environment inventory to decide to generate a config file for booting a server or an agent |
| |
| - name: ensure consul config directory exists |
| file: |
| path: "{{ consul_conf_dir }}" |
| state: directory |
| when: "'consul_servers' in group_names" |
| |
| - name: copy template from local to remote (which is really local) and fill in templates |
| template: |
| src: config.json.j2 |
| dest: "{{ consul_conf_dir }}/config.json" |
| when: "'consul_servers' in group_names" |
| |
| - name: create configmap |
| shell: "kubectl create configmap consul --from-file={{ consul_conf_dir }}/config.json" |
| |
| - name: create consul deployment |
| shell: "kubectl apply -f {{kube_pod_dir}}/consul.yml" |
| |
| - name: wait until the Consul Server/Agent in this host is up and running |
| uri: |
| method: PUT |
| url: "http://{{ consul_host }}:{{ consul.port.http }}/v1/kv/consulIsAlive" |
| body: 'true' |
| register: result |
| until: result.status == 200 |
| retries: 12 |
| delay: 5 |
| when: "'consul_servers' in group_names" |
| |
| - name: delete is alive token from Consul Server/Agent |
| uri: |
| method: DELETE |
| url: "http://{{ consul_host }}:{{ consul.port.http }}/v1/kv/consulIsAlive" |
| register: result |
| until: result.status == 200 |
| retries: 10 |
| delay: 1 |
| when: "'consul_servers' in group_names" |
| |
| - name: notify handler to fill in Consul KV store with parameters in whisk.properties |
| command: "true" |
| notify: fill consul kv |
| when: "'consul_servers' in group_names" |