Debian Codegraph @

ansible_collections/community/general/tests/integration/targets/consul/tasks/main.yml

raw
1 ---
2 ####################################################################
3 # WARNING: These are designed specifically for Ansible tests #
4 # and should not be used as examples of how to write Ansible roles #
5 ####################################################################
6
7 # Copyright (c) Ansible Project
8 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
9 # SPDX-License-Identifier: GPL-3.0-or-later
10
11 - name: Install Consul and test
12 vars:
13 consul_version: 1.22.6
14 consul_uri: https://releases.hashicorp.com/consul/{{ consul_version }}/consul_{{ consul_version }}_{{ ansible_facts.system | lower }}_{{ consul_arch }}.zip
15 consul_cmd: '{{ remote_tmp_dir }}/consul'
16 block:
17 - name: Install py-consul
18 pip:
19 name: py-consul
20 extra_args: "-c {{ remote_constraints }}"
21 register: result
22 retries: 3
23 delay: 5
24 until: result is success
25 - name: Generate privatekey
26 community.crypto.openssl_privatekey:
27 path: '{{ remote_tmp_dir }}/privatekey.pem'
28 - name: Generate CSR
29 community.crypto.openssl_csr:
30 path: '{{ remote_tmp_dir }}/csr.csr'
31 privatekey_path: '{{ remote_tmp_dir }}/privatekey.pem'
32 subject:
33 commonName: localhost
34 - name: Generate selfsigned certificate
35 register: selfsigned_certificate
36 community.crypto.x509_certificate:
37 path: '{{ remote_tmp_dir }}/cert.pem'
38 csr_path: '{{ remote_tmp_dir }}/csr.csr'
39 privatekey_path: '{{ remote_tmp_dir }}/privatekey.pem'
40 provider: selfsigned
41 selfsigned_digest: sha256
42 - name: Install unzip
43 package:
44 name: unzip
45 register: result
46 until: result is success
47 when: ansible_facts.distribution != "MacOSX"
48 - assert:
49 that: ansible_facts.architecture in ['i386', 'x86_64', 'amd64', 'arm64', 'aarch64']
50 - set_fact:
51 consul_arch: '386'
52 when: ansible_facts.architecture == 'i386'
53 - set_fact:
54 consul_arch: amd64
55 when: ansible_facts.architecture in ['x86_64', 'amd64']
56 - set_fact:
57 consul_arch: arm64
58 when: ansible_facts.architecture in ['arm64', 'aarch64']
59 - name: Download consul binary
60 unarchive:
61 src: '{{ consul_uri }}'
62 dest: '{{ remote_tmp_dir }}'
63 remote_src: true
64 register: result
65 until: result is success
66 - name: Remove macOS quarantine attribute from consul binary
67 command: xattr -d com.apple.quarantine {{ consul_cmd }}
68 when: ansible_facts.system == 'Darwin'
69 ignore_errors: true
70 - vars:
71 remote_dir: '{{ echo_remote_tmp_dir.stdout }}'
72 block:
73 - command: echo {{ remote_tmp_dir }}
74 register: echo_remote_tmp_dir
75 - name: Create configuration file
76 template:
77 src: consul_config.hcl.j2
78 dest: '{{ remote_tmp_dir }}/consul_config.hcl'
79 - name: Start Consul (dev mode enabled)
80 shell: nohup {{ consul_cmd }} agent -dev -config-file {{ remote_tmp_dir }}/consul_config.hcl </dev/null >/dev/null 2>&1 &
81 - name: Wait for Consul HTTP API to be ready
82 wait_for:
83 host: localhost
84 port: 8500
85 delay: 3
86 timeout: 60
87 - name: Bootstrap ACL
88 consul_acl_bootstrap:
89 register: consul_bootstrap_result
90 - set_fact:
91 consul_management_token: '{{ consul_bootstrap_result.result.SecretID }}'
92 - name: Create some data
93 command: '{{ consul_cmd }} kv put -token={{consul_management_token}} data/value{{ item }} foo{{ item }}'
94 loop:
95 - 1
96 - 2
97 - 3
98 - import_tasks: consul_general.yml
99 - import_tasks: consul_kv.yml
100
101 - block:
102 - import_tasks: consul_session.yml
103 - import_tasks: consul_policy.yml
104 - import_tasks: consul_role.yml
105 - import_tasks: consul_token.yml
106 - import_tasks: consul_auth_method.yml
107 - import_tasks: consul_binding_rule.yml
108 - import_tasks: consul_agent_service.yml
109 - import_tasks: consul_agent_check.yml
110 module_defaults:
111 group/community.general.consul:
112 token: "{{ consul_management_token }}"
113
114 always:
115 - name: Kill consul process
116 shell: kill $(cat {{ remote_tmp_dir }}/consul.pid)
117 ignore_errors: true