2024-04-01 21:59:48 +00:00
|
|
|
---
|
2024-03-13 22:27:12 +00:00
|
|
|
- name: "Consul"
|
|
|
|
block:
|
2024-05-16 15:29:41 +00:00
|
|
|
- name: "Include ednz_cloud.hashicorp_consul"
|
2024-03-13 22:27:12 +00:00
|
|
|
ansible.builtin.include_role:
|
2024-05-16 15:29:41 +00:00
|
|
|
name: ednz_cloud.hashicorp_consul
|
2024-03-13 22:27:12 +00:00
|
|
|
|
|
|
|
- name: "Wait for consul cluster to initialize" # noqa: run-once[task]
|
2024-04-01 21:59:48 +00:00
|
|
|
ansible.builtin.uri:
|
2024-05-05 00:37:29 +00:00
|
|
|
url: "{{ consul_api_addr }}"
|
2024-04-01 21:59:48 +00:00
|
|
|
validate_certs: no
|
|
|
|
return_content: yes
|
|
|
|
status_code:
|
|
|
|
- 200
|
|
|
|
until: uri_output.status == 200
|
|
|
|
retries: 24
|
|
|
|
delay: 5
|
|
|
|
register: uri_output
|
2024-03-13 22:27:12 +00:00
|
|
|
|
|
|
|
- name: "Initialize consul cluster" # noqa: run-once[task]
|
|
|
|
community.general.consul_acl_bootstrap:
|
2024-05-03 20:26:30 +00:00
|
|
|
bootstrap_secret: "{{ _credentials.consul.root_token.secret_id }}"
|
2024-05-05 00:37:29 +00:00
|
|
|
host: "{{ api_interface_address }}"
|
|
|
|
port: "{{ consul_api_port[consul_api_scheme] }}"
|
|
|
|
scheme: "{{ consul_api_scheme }}"
|
2024-03-13 22:27:12 +00:00
|
|
|
state: present
|
|
|
|
run_once: true
|
|
|
|
delegate_to: "{{ groups['consul_servers'] | first }}"
|
|
|
|
register: _consul_init_secret
|
2024-06-19 22:32:33 +00:00
|
|
|
when: hashicorp_consul_configuration.acl.enabled
|
2024-03-13 22:27:12 +00:00
|
|
|
|
|
|
|
- name: "Create consul agents token"
|
|
|
|
when:
|
|
|
|
- _consul_init_secret.changed
|
|
|
|
- consul_acl_configuration.enabled
|
|
|
|
block:
|
|
|
|
- name: "Create consul agents token" # noqa: run-once[task] no-handler
|
|
|
|
run_once: true
|
|
|
|
block:
|
|
|
|
- name: "Create consul agent policy"
|
|
|
|
community.general.consul_policy:
|
2024-05-03 20:26:30 +00:00
|
|
|
token: "{{ _credentials.consul.root_token.secret_id }}"
|
|
|
|
host: "{{ api_interface_address }}"
|
2024-05-05 00:37:29 +00:00
|
|
|
port: "{{ consul_api_port[consul_api_scheme] }}"
|
|
|
|
scheme: "{{ consul_api_scheme }}"
|
2024-05-03 20:26:30 +00:00
|
|
|
validate_certs: false
|
2024-03-13 22:27:12 +00:00
|
|
|
state: present
|
|
|
|
name: agents-policy
|
|
|
|
rules: "{{ consul_default_agent_policy }}"
|
|
|
|
register: _consul_agent_policy
|
|
|
|
|
|
|
|
- name: "Create consul agents token"
|
2024-05-07 17:23:48 +00:00
|
|
|
community.general.consul_token:
|
|
|
|
token: "{{ _credentials.consul.root_token.secret_id }}"
|
|
|
|
host: "{{ api_interface_address }}"
|
|
|
|
port: "{{ consul_api_port[consul_api_scheme] }}"
|
|
|
|
scheme: "{{ consul_api_scheme }}"
|
|
|
|
validate_certs: false
|
|
|
|
accessor_id: "{{ _credentials.consul.tokens.agent.accessor_id }}"
|
|
|
|
secret_id: "{{ _credentials.consul.tokens.agent.secret_id }}"
|
|
|
|
policies:
|
|
|
|
- id: "{{ _consul_agent_policy.policy.ID }}"
|
|
|
|
state: present
|
2024-03-13 22:27:12 +00:00
|
|
|
register: _consul_agent_token
|
|
|
|
|
2024-06-19 22:32:33 +00:00
|
|
|
- name: "Restart consul service" # noqa: no-handler
|
2024-05-03 20:26:30 +00:00
|
|
|
ansible.builtin.service:
|
2024-06-19 22:32:33 +00:00
|
|
|
name: "{{ hashicorp_consul_service_name }}"
|
2024-05-03 20:26:30 +00:00
|
|
|
state: restarted
|
|
|
|
throttle: 1
|
|
|
|
when: _consul_agent_token.changed
|