Skip to content

Commit 381881a

Browse files
authored
Add molecule tests for enterprise edition (#361)
1 parent aa950f8 commit 381881a

File tree

10 files changed

+225
-147
lines changed

10 files changed

+225
-147
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ to load any new configuration deployed.
7575

7676
## [Role Variables](role_variables.md)
7777

78+
## Misc
79+
80+
### [Vault Release Scheme](vault_releases.md)
81+
7882
## License
7983

8084
BSD-2-Clause

defaults/main.yml

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66
# ---------------------------------------------------------------------------
77

88
# Package variables
9-
vault_version_suffix: "{{ '.hsm' if vault_enterprise_hsm else '' }}"
10-
vault_version: "{{ lookup('env', 'VAULT_VERSION') | default('1.18.2', true) }}{{ vault_version_suffix }}"
11-
vault_version_repo_suffix: "{{ '+ent' if vault_enterprise }}-1"
9+
vault_version: "{{ lookup('env', 'VAULT_VERSION') | default('1.18.2', true) }}"
10+
11+
vault_version_release_site_suffix: "{{ '+ent' if vault_enterprise }}{{ '.hsm' if vault_enterprise_hsm }}"
12+
vault_version_repo_suffix: "{{ '+ent' if vault_enterprise }}"
13+
vault_version_debian_repo_suffix: "-1"
14+
1215
vault_architecture_map:
1316
# this first entry seems... redundant (but it's required for reasons)
1417
amd64: amd64
@@ -17,10 +20,13 @@ vault_architecture_map:
1720
aarch64: arm64
1821
vault_architecture: "{{ vault_architecture_map[ansible_architecture] }}"
1922
vault_os: "{{ ansible_system | lower }}"
20-
vault_pkg: "vault_{{ vault_version }}_{{ vault_os }}_{{ vault_architecture }}.zip"
21-
vault_shasums: "vault_{{ vault_version }}_SHA256SUMS"
22-
vault_zip_url: "https://releases.hashicorp.com/vault/{{ vault_version }}/vault_{{ vault_version }}_{{ vault_os }}_{{ vault_architecture }}.zip"
23-
vault_checksum_file_url: "https://releases.hashicorp.com/vault/{{ vault_version }}/vault_{{ vault_version }}_SHA256SUMS"
23+
24+
vault_pkg_stub: "vault_{{ vault_version }}{{ vault_version_release_site_suffix }}"
25+
vault_pkg: "{{ vault_pkg_stub }}_{{ vault_os }}_{{ vault_architecture }}.zip"
26+
vault_shasums: "{{ vault_pkg_stub }}_SHA256SUMS"
27+
vault_url_stub: "https://releases.hashicorp.com/vault/{{ vault_version }}{{ vault_version_release_site_suffix }}"
28+
vault_zip_url: "{{ vault_url_stub }}/{{ vault_pkg }}"
29+
vault_checksum_file_url: "{{ vault_url_stub }}/{{ vault_shasums }}"
2430
vault_repository_url: "{{ _vault_repository_url | default() }}"
2531
vault_repository_key_url: "{{ _vault_repository_key_url | default() }}"
2632
vault_rhsm_subscription_name:
@@ -385,8 +391,6 @@ vault_entropy_seal: false
385391
# ---------------------------------------------------------------------------
386392

387393
vault_enterprise: "{{ lookup('env', 'VAULT_ENTERPRISE') | default(false, true) }}"
388-
vault_enterprise_pkg: "vault-enterprise_{{ vault_version }}_{{ vault_os }}_{{ vault_architecture }}.zip"
389-
vault_enterprise_shasums: "vault-enterprise_{{ vault_version }}_SHA256SUMS"
390394

391395
# Manage enterprise license file with this role
392396
vault_configure_enterprise_license: false
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
platforms:
3+
- name: centos-stream-9
4+
groups:
5+
- vault_raft_servers
6+
image: dokken/centos-stream-9
7+
pre_build_image: true
8+
command: /lib/systemd/systemd
9+
privileged: true
10+
cgroup_parent: docker.slice
11+
- name: centos-stream-9_repo
12+
groups:
13+
- vault_raft_servers
14+
image: dokken/centos-stream-9
15+
pre_build_image: true
16+
command: /lib/systemd/systemd
17+
privileged: true
18+
cgroup_parent: docker.slice
19+
20+
provisioner:
21+
inventory:
22+
host_vars:
23+
centos-stream-9:
24+
vault_disable_api_health_check: true
25+
vault_enterprise: true
26+
vault_install_hashi_repo: false
27+
centos-stream-9_repo:
28+
vault_disable_api_health_check: true
29+
vault_enterprise: true
30+
vault_install_hashi_repo: true
31+
vault_bin_path: /usr/bin
32+
vault_group: vault
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
platforms:
3+
- name: debian-11
4+
groups:
5+
- vault_raft_servers
6+
image: dokken/debian-11
7+
pre_build_image: true
8+
command: /lib/systemd/systemd
9+
privileged: true
10+
cgroup_parent: docker.slice
11+
- name: debian-11_repo
12+
groups:
13+
- vault_raft_servers
14+
image: dokken/debian-11
15+
pre_build_image: true
16+
command: /lib/systemd/systemd
17+
privileged: true
18+
cgroup_parent: docker.slice
19+
20+
provisioner:
21+
inventory:
22+
host_vars:
23+
debian-11:
24+
vault_disable_api_health_check: true
25+
vault_enterprise: true
26+
vault_install_hashi_repo: false
27+
debian-11_repo:
28+
vault_disable_api_health_check: true
29+
vault_enterprise: true
30+
vault_install_hashi_repo: true
31+
vault_bin_path: /usr/bin
32+
vault_group: vault
33+

molecule/verify.yml

Lines changed: 50 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -10,46 +10,55 @@
1010
goss_url: "https://github.com/aelsabbahy/goss/releases/download/{{ goss_version }}/goss-linux-{{ goss_arch }}"
1111
goss_test_directory: /tmp
1212
goss_format: tap
13+
enterprise: "{{ 'enterprise' in lookup('env', 'MOLECULE_SCENARIO_DIRECTORY') }}"
1314
tasks:
14-
- name: Download and install Goss
15-
get_url:
16-
url: "{{ goss_url }}"
17-
dest: "{{ goss_dst }}"
18-
checksum: "sha256:{{ goss_sha256sum }}"
19-
mode: 0755
20-
register: download_goss
21-
until: download_goss is succeeded
22-
retries: 3
15+
- name: Check if enterprise
16+
ansible.builtin.debug:
17+
msg: "Verification is skipped because vault enterprise does not start without license"
18+
when: enterprise
19+
- name: Verify tasks
20+
when: not enterprise
21+
block:
22+
- name: Download and install Goss
23+
get_url:
24+
url: "{{ goss_url }}"
25+
dest: "{{ goss_dst }}"
26+
checksum: "sha256:{{ goss_sha256sum }}"
27+
mode: 0755
28+
register: download_goss
29+
until: download_goss is succeeded
30+
retries: 3
31+
32+
- name: Copy Goss tests to remote
33+
template:
34+
src: "{{ item }}"
35+
dest: "{{ goss_test_directory }}/{{ item | basename | splitext | first }}"
36+
mode: 0644
37+
with_fileglob:
38+
- "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/molecule/_tests/test_*.j2"
39+
40+
- name: Register test files
41+
shell: "ls {{ goss_test_directory }}/test_*.yml"
42+
changed_when: false
43+
register: test_files
44+
45+
- name: Execute Goss tests
46+
environment:
47+
# yamllint disable-line rule:line-length
48+
PATH: '/opt/rh/rh-git218/root/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
49+
command: "{{ goss_dst }} -g {{ item }} validate -f {{ goss_format }}"
50+
changed_when: false
51+
register: test_results
52+
with_items: "{{ test_files.stdout_lines }}"
53+
54+
- name: Display details about the Goss results
55+
debug:
56+
msg: "{{ item.stdout_lines }}"
57+
with_items: "{{ test_results.results }}"
58+
59+
- name: Fail when tests fail
60+
fail:
61+
msg: "Goss failed to validate"
62+
when: item.rc != 0
63+
with_items: "{{ test_results.results }}"
2364

24-
- name: Copy Goss tests to remote
25-
template:
26-
src: "{{ item }}"
27-
dest: "{{ goss_test_directory }}/{{ item | basename | splitext | first }}"
28-
mode: 0644
29-
with_fileglob:
30-
- "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/molecule/_tests/test_*.j2"
31-
32-
- name: Register test files
33-
shell: "ls {{ goss_test_directory }}/test_*.yml"
34-
changed_when: false
35-
register: test_files
36-
37-
- name: Execute Goss tests
38-
environment:
39-
# yamllint disable-line rule:line-length
40-
PATH: '/opt/rh/rh-git218/root/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
41-
command: "{{ goss_dst }} -g {{ item }} validate -f {{ goss_format }}"
42-
changed_when: false
43-
register: test_results
44-
with_items: "{{ test_files.stdout_lines }}"
45-
46-
- name: Display details about the Goss results
47-
debug:
48-
msg: "{{ item.stdout_lines }}"
49-
with_items: "{{ test_results.results }}"
50-
51-
- name: Fail when tests fail
52-
fail:
53-
msg: "Goss failed to validate"
54-
when: item.rc != 0
55-
with_items: "{{ test_results.results }}"

tasks/install.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
get_url:
3434
url: "{{ vault_zip_url }}"
3535
dest: "{{ role_path }}/files/{{ vault_pkg }}"
36-
checksum: "sha256:{{ (lookup('url', vault_checksum_file_url, wantlist=true) | select('match', '.*' + vault_pkg + '$') | first).split()[0] }}"
36+
checksum:
37+
"sha256:{{ (lookup('url', vault_checksum_file_url, wantlist=true) | select('match', '.*' + (vault_pkg | regex_escape()) + '$') | first).split()[0] }}"
3738
timeout: "42"
3839
mode: "0644"
3940
become: "{{ vault_privileged_install }}"

tasks/install_enterprise.yml

Lines changed: 0 additions & 82 deletions
This file was deleted.

tasks/install_hashi_repo.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,18 @@
7171
state: absent
7272
become: true
7373

74-
- name: Install Vault package
74+
- name: "Install Vault package {{ _vault_repo_pkg }}"
7575
package:
7676
name: "{{ _vault_repo_pkg }}"
7777
state: present
7878
become: true
7979
vars:
8080
_vault_repo_pkg: "{% if (ansible_pkg_mgr in ['yum', 'dnf']) %}\
81-
vault-{{ 'enterprise-' if (vault_enterprise | bool) else '' }}{{ vault_version }}{{ vault_version_repo_suffix }}\
81+
vault{{ '-enterprise' if vault_enterprise }}-{{ vault_version }}{{ vault_version_repo_suffix }}\
8282
{% elif (ansible_pkg_mgr == 'apt') %}\
83-
vault{{ '-enterprise' if (vault_enterprise | bool) else '' }}={{ vault_version }}{{ vault_version_repo_suffix }}\
83+
vault{{ '-enterprise' if vault_enterprise }}={{ vault_version }}{{ vault_version_repo_suffix }}{{ vault_version_debian_repo_suffix }}\
8484
{% else %}\
85-
vault{{ '-enterprise' if (vault_enterprise | bool) else '' }}={{ vault_version }}{{ vault_version_repo_suffix }}\
85+
vault{{ '-enterprise' if vault_enterprise }}={{ vault_version }}{{ vault_version_repo_suffix }}\
8686
{% endif %}"
8787
notify: Restart vault
8888

tasks/main.yml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,11 @@
5151

5252
- name: Compute if installation is required
5353
set_fact:
54-
installation_required: "{{ vault_installation is failed or installed_vault_version.stdout != vault_version }}"
55-
56-
- name: Install OS packages and Vault Enterprise via control host
57-
include_tasks: install_enterprise.yml
58-
when:
59-
- vault_enterprise | bool
60-
- not vault_install_remotely | bool
61-
- not vault_install_hashi_repo | bool
62-
- installation_required | bool
54+
installation_required: "{{ vault_installation is failed or installed_vault_version.stdout != vault_version~('+ent' if vault_enterprise) }}"
6355

6456
- name: Install OS packages and Vault via control host
6557
include_tasks: install.yml
6658
when:
67-
- not vault_enterprise | bool
6859
- not vault_install_remotely | bool
6960
- not vault_install_hashi_repo | bool
7061
- installation_required | bool

0 commit comments

Comments
 (0)