hcp-ansible/playbooks/tasks/consul/consul_control_plane.yml

72 lines
2.8 KiB
YAML
Raw Normal View History

---
- name: "Consul control plane"
block:
2024-08-17 12:09:24 +00:00
- name: "Include ednz_cloud.hashistack.consul"
ansible.builtin.include_role:
2024-08-17 12:09:24 +00:00
name: ednz_cloud.hashistack.consul
2024-08-17 12:09:24 +00:00
- name: "Consul | Wait for consul cluster to initialize" # noqa: run-once[task]
block:
2024-08-17 12:09:24 +00:00
- name: "Consul | Wait for consul nodes to stabilize"
ansible.builtin.wait_for:
host: "{{ api_interface_address }}"
port: "{{ consul_api_port[consul_api_scheme] }}"
delay: 10
2024-08-17 12:09:24 +00:00
- name: "Consul | Waiting for consul api to respond"
ansible.builtin.uri:
url: "{{ consul_api_addr }}"
validate_certs: no
return_content: yes
status_code:
- 200
until: uri_output.status == 200
retries: 24
delay: 5
register: uri_output
2024-08-17 12:09:24 +00:00
- name: "Consul | Initialize consul cluster" # noqa: run-once[task]
community.general.consul_acl_bootstrap:
bootstrap_secret: "{{ _credentials.consul.root_token.secret_id }}"
host: "{{ api_interface_address }}"
port: "{{ consul_api_port[consul_api_scheme] }}"
scheme: "{{ consul_api_scheme }}"
state: present
register: _consul_init_secret
when:
- consul_init_server
2024-08-17 12:09:24 +00:00
- consul_configuration.acl.enabled
2024-08-17 12:09:24 +00:00
- name: "Consul | Create consul agents token"
when:
- consul_init_server
2024-08-17 12:09:24 +00:00
- consul_configuration.acl.enabled
block:
2024-08-17 12:09:24 +00:00
- name: "Consul | Create consul agents token" # noqa: run-once[task] no-handler
block:
2024-08-17 12:09:24 +00:00
- name: "Consul | Create consul agent policy"
community.general.consul_policy:
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
state: present
name: agents-policy
rules: "{{ consul_default_agent_policy }}"
register: _consul_agent_policy
2024-08-17 12:09:24 +00:00
- name: "Consul | Create consul agents token"
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
register: _consul_agent_token