2022-08-05 21:31:34 +02:00
|
|
|
---
|
2020-09-25 08:01:17 +02:00
|
|
|
####################################################################
|
|
|
|
# WARNING: These are designed specifically for Ansible tests #
|
|
|
|
# and should not be used as examples of how to write Ansible roles #
|
|
|
|
####################################################################
|
|
|
|
|
2022-08-05 21:31:34 +02:00
|
|
|
# Copyright (c) Ansible Project
|
|
|
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2020-03-09 10:11:07 +01:00
|
|
|
- name: Install Consul and test
|
|
|
|
vars:
|
2023-07-07 07:49:10 +02:00
|
|
|
consul_version: 1.13.2
|
|
|
|
consul_uri: https://releases.hashicorp.com/consul/{{ consul_version }}/consul_{{ consul_version }}_{{ ansible_system | lower }}_{{ consul_arch }}.zip
|
2021-09-09 07:31:44 +02:00
|
|
|
consul_cmd: '{{ remote_tmp_dir }}/consul'
|
2020-03-09 10:11:07 +01:00
|
|
|
block:
|
|
|
|
- name: Install requests<2.20 (CentOS/RHEL 6)
|
|
|
|
pip:
|
|
|
|
name: requests<2.20
|
2022-05-19 14:48:03 +02:00
|
|
|
extra_args: "-c {{ remote_constraints }}"
|
2020-03-09 10:11:07 +01:00
|
|
|
register: result
|
|
|
|
until: result is success
|
|
|
|
when: ansible_distribution_file_variety|default() == 'RedHat' and ansible_distribution_major_version is version('6', '<=')
|
|
|
|
- name: Install python-consul
|
|
|
|
pip:
|
|
|
|
name: python-consul
|
2022-05-19 14:48:03 +02:00
|
|
|
extra_args: "-c {{ remote_constraints }}"
|
2020-03-09 10:11:07 +01:00
|
|
|
register: result
|
|
|
|
until: result is success
|
2022-02-21 21:14:45 +01:00
|
|
|
- name: Generate privatekey
|
|
|
|
community.crypto.openssl_privatekey:
|
|
|
|
path: '{{ remote_tmp_dir }}/privatekey.pem'
|
|
|
|
- name: Generate CSR
|
|
|
|
community.crypto.openssl_csr:
|
|
|
|
path: '{{ remote_tmp_dir }}/csr.csr'
|
|
|
|
privatekey_path: '{{ remote_tmp_dir }}/privatekey.pem'
|
|
|
|
subject:
|
|
|
|
commonName: localhost
|
|
|
|
- name: Generate selfsigned certificate
|
|
|
|
register: selfsigned_certificate
|
|
|
|
community.crypto.x509_certificate:
|
|
|
|
path: '{{ remote_tmp_dir }}/cert.pem'
|
|
|
|
csr_path: '{{ remote_tmp_dir }}/csr.csr'
|
|
|
|
privatekey_path: '{{ remote_tmp_dir }}/privatekey.pem'
|
|
|
|
provider: selfsigned
|
|
|
|
selfsigned_digest: sha256
|
2020-03-09 10:11:07 +01:00
|
|
|
- name: Install unzip
|
|
|
|
package:
|
|
|
|
name: unzip
|
|
|
|
register: result
|
|
|
|
until: result is success
|
|
|
|
when: ansible_distribution != "MacOSX"
|
|
|
|
- assert:
|
|
|
|
that: ansible_architecture in ['i386', 'x86_64', 'amd64']
|
|
|
|
- set_fact:
|
|
|
|
consul_arch: '386'
|
|
|
|
when: ansible_architecture == 'i386'
|
|
|
|
- set_fact:
|
|
|
|
consul_arch: amd64
|
|
|
|
when: ansible_architecture in ['x86_64', 'amd64']
|
|
|
|
- name: Download consul binary
|
|
|
|
unarchive:
|
|
|
|
src: '{{ consul_uri }}'
|
2021-09-09 07:31:44 +02:00
|
|
|
dest: '{{ remote_tmp_dir }}'
|
2020-03-09 10:11:07 +01:00
|
|
|
remote_src: true
|
|
|
|
register: result
|
|
|
|
until: result is success
|
|
|
|
- vars:
|
2021-09-09 07:31:44 +02:00
|
|
|
remote_dir: '{{ echo_remote_tmp_dir.stdout }}'
|
2020-03-09 10:11:07 +01:00
|
|
|
block:
|
2021-09-09 07:31:44 +02:00
|
|
|
- command: echo {{ remote_tmp_dir }}
|
|
|
|
register: echo_remote_tmp_dir
|
2020-03-09 10:11:07 +01:00
|
|
|
- name: Create configuration file
|
|
|
|
template:
|
|
|
|
src: consul_config.hcl.j2
|
2021-09-09 07:31:44 +02:00
|
|
|
dest: '{{ remote_tmp_dir }}/consul_config.hcl'
|
2020-03-09 10:11:07 +01:00
|
|
|
- name: Start Consul (dev mode enabled)
|
2021-09-09 07:31:44 +02:00
|
|
|
shell: nohup {{ consul_cmd }} agent -dev -config-file {{ remote_tmp_dir }}/consul_config.hcl </dev/null >/dev/null 2>&1 &
|
2023-07-07 07:49:10 +02:00
|
|
|
- name: Bootstrap ACL
|
2024-01-27 10:22:44 +01:00
|
|
|
consul_acl_bootstrap:
|
|
|
|
register: consul_bootstrap_result
|
2023-07-07 07:49:10 +02:00
|
|
|
- set_fact:
|
2024-01-27 10:22:44 +01:00
|
|
|
consul_management_token: '{{ consul_bootstrap_result.result.SecretID }}'
|
2020-03-09 10:11:07 +01:00
|
|
|
- name: Create some data
|
2023-07-07 07:49:10 +02:00
|
|
|
command: '{{ consul_cmd }} kv put -token={{consul_management_token}} data/value{{ item }} foo{{ item }}'
|
2020-03-09 10:11:07 +01:00
|
|
|
loop:
|
|
|
|
- 1
|
|
|
|
- 2
|
|
|
|
- 3
|
2024-01-21 18:29:29 +01:00
|
|
|
- import_tasks: consul_general.yml
|
|
|
|
- import_tasks: consul_kv.yml
|
2024-01-27 10:58:41 +01:00
|
|
|
|
|
|
|
- block:
|
|
|
|
- import_tasks: consul_session.yml
|
|
|
|
- import_tasks: consul_policy.yml
|
|
|
|
- import_tasks: consul_role.yml
|
|
|
|
- import_tasks: consul_token.yml
|
|
|
|
- import_tasks: consul_auth_method.yml
|
|
|
|
- import_tasks: consul_binding_rule.yml
|
2024-06-16 09:32:55 +02:00
|
|
|
- import_tasks: consul_agent_service.yml
|
|
|
|
- import_tasks: consul_agent_check.yml
|
2024-01-27 10:58:41 +01:00
|
|
|
module_defaults:
|
|
|
|
group/community.general.consul:
|
|
|
|
token: "{{ consul_management_token }}"
|
|
|
|
|
2020-03-09 10:11:07 +01:00
|
|
|
always:
|
|
|
|
- name: Kill consul process
|
2021-09-09 07:31:44 +02:00
|
|
|
shell: kill $(cat {{ remote_tmp_dir }}/consul.pid)
|
2023-07-12 19:27:23 +02:00
|
|
|
ignore_errors: true
|