Skip to content

Commit dab5ce6

Browse files
author
Martin Jackson
committed
Add extravar handling for pattern_dir if needed
1 parent 62c1756 commit dab5ce6

5 files changed

Lines changed: 16 additions & 39 deletions

File tree

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,14 @@ Provide CA distribution using a separate chart or platform mechanism.
4747

4848
For the complete flow and task ordering, see
4949
`secrets-initialization-and-vault-unseal.md`.
50+
51+
## Pattern repository directory (`pattern_dir`)
52+
53+
Playbooks need the path to your pattern Git checkout (where `values-global.yaml`
54+
and related files live). Resolution order: extra var `pattern_dir`, environment
55+
variable `PATTERN_DIR`, then `PWD` and `pwd`.
56+
57+
When running from the imperative container or another fixed working directory,
58+
pass the repo root explicitly, for example `-e pattern_dir=/git/repo` (or add
59+
equivalent extra vars via `clusterGroup.imperative.extraPlaybookArgs` in the
60+
clustergroup chart).

playbooks/vault.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
connection: local
55
gather_facts: false
66
roles:
7-
# Resolves pattern_dir (PATTERN_DIR / PWD) and loads main.clusterGroupName as main_clustergroup.
7+
# Resolves pattern_dir (extra var / PATTERN_DIR / PWD) and loads main.clusterGroupName as main_clustergroup.
88
# vault_ss_csi_workload_auth prefers merged clustergroup YAML from an in-cluster ConfigMap, then file fallback.
99
- pattern_settings
1010
- find_vp_secrets

roles/pattern_settings/tasks/resolve_overrides.yml

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,3 @@
99
| default(lookup("pipe","pwd"), true)
1010
| trim
1111
}}
12-
13-
# When playbooks run from a collection install (e.g. .../cluster_utils/playbooks), PWD points at
14-
# that directory while values-global.yaml lives at the pattern Git repo root. Walk upward from the
15-
# initial guess until values-global.yaml is found; if none, keep the guess (fail later as before).
16-
- name: Canonicalize pattern_dir to directory containing values-global.yaml
17-
ansible.builtin.command:
18-
argv:
19-
- python3
20-
- -c
21-
- |
22-
import os
23-
import sys
24-
25-
start = os.path.abspath(os.environ["RHVP_PATTERN_DIR_GUESS"])
26-
d = start
27-
while True:
28-
if os.path.isfile(os.path.join(d, "values-global.yaml")):
29-
sys.stdout.write(d)
30-
break
31-
parent = os.path.dirname(d)
32-
if parent == d:
33-
sys.stdout.write(start)
34-
break
35-
d = parent
36-
environment:
37-
RHVP_PATTERN_DIR_GUESS: "{{ pattern_dir }}"
38-
register: _rhvp_pattern_dir_canonical
39-
changed_when: false
40-
41-
- name: Apply canonical pattern_dir
42-
ansible.builtin.set_fact:
43-
pattern_dir: "{{ _rhvp_pattern_dir_canonical.stdout | trim }}"

roles/vault_utils/tasks/vault_ss_csi_workload_auth.yaml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@
1313
_ss_csi_all_entries: []
1414
when: vault_ss_csi_from_applications | default(true) | bool
1515

16-
# Many jobs run only vault_utils (no pattern_settings role). Reuse the same pattern_dir
17-
# resolution as pattern_settings (PATTERN_DIR, else PWD, else pwd) so values-global and
18-
# values-<clustergroup>.yaml resolve without exporting PATTERN_DIR when CWD is the repo root.
16+
# Many playbooks run vault_utils without pattern_settings. Align pattern_dir with pattern_settings
17+
# (extra var, PATTERN_DIR, PWD, pwd), then derive main clustergroup name from values-global when unset.
1918
- name: Resolve pattern_dir for SS CSI (align with pattern_settings)
2019
ansible.builtin.include_tasks: ../pattern_settings/tasks/resolve_overrides.yml
2120
when: vault_ss_csi_from_applications | default(true) | bool
@@ -29,7 +28,6 @@
2928
- (pattern_dir | string | trim | length) > 0
3029
- (main_clustergroup is not defined) or ((main_clustergroup | default('', true) | string | trim) | length == 0)
3130

32-
# pattern_settings sets main_clustergroup; other playbooks use main_clustergroupname — align.
3331
- name: Alias main_clustergroupname from main_clustergroup for SS CSI
3432
ansible.builtin.set_fact:
3533
main_clustergroupname: "{{ main_clustergroup | string | trim }}"
@@ -143,7 +141,7 @@
143141
ssCsiWorkloadAuth identities={{ _ss_csi_all_entries | default([]) | length }},
144142
hub roles to configure={{ _ss_csi_hub_entries | default([]) | length }}.
145143
If identities is 0, define ssCsiWorkloadAuth under clusterGroup.applications or under clusterGroup.managedClusterGroups.*.applications in the merged clustergroup values (in-cluster ConfigMap or values-{{ main_clustergroupname | default('hub') }}.yaml).
146-
If nothing loads, check vault_ss_csi_clustergroup_configmap_* settings, run from the pattern repo for file fallback, set vault_ss_csi_cluster_values_file, or set vault_ss_csi_fallback_local_clustergroup_file; ensure main.clusterGroupName in values-global.
144+
If nothing loads, check vault_ss_csi_clustergroup_configmap_* settings, pass pattern_dir (and optionally main_clustergroup / main_clustergroupname) via extra vars, set vault_ss_csi_cluster_values_file, or set vault_ss_csi_fallback_local_clustergroup_file; ensure main.clusterGroupName in values-global when resolving from pattern_dir.
147145
when: vault_ss_csi_from_applications | default(true) | bool
148146

149147
- name: Configure hub Vault Kubernetes auth role per SS CSI workload identity

secrets-initialization-and-vault-unseal.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This document describes how Vault and application secrets are bootstrapped when
77
- **Playbook:** `playbooks/vault.yml`
88
- **Hosts:** `localhost`, `connection: local`, `gather_facts: false`
99
- **Roles (order):**
10-
1. **`pattern_settings`** — Resolves `pattern_dir` and loads `main.clusterGroupName` as `main_clustergroup` (used later, e.g. SS CSI workload auth reading `values-<clustergroup>.yaml`).
10+
1. **`pattern_settings`** — Resolves `pattern_dir` (extra var, `PATTERN_DIR`, then `PWD` / `pwd`) and loads `values-global.yaml` (including `main.clusterGroupName` as `main_clustergroup`). When `pattern_settings` is not in the play, **`vault_ss_csi_workload_auth`** repeats the same `pattern_dir` resolution and, if needed, reads `values-global.yaml` under that directory to set `main_clustergroup` / `main_clustergroupname` before loading merged clustergroup values.
1111
2. **`find_vp_secrets`** — Locates pattern secrets inputs as used elsewhere in the repository.
1212
3. **`cluster_pre_check`** — Verifies Python `kubernetes` import, kubeconfig (`KUBECONFIG` or `~/.kube/config`), or in-cluster operation via `KUBERNETES_SERVICE_HOST`.
1313
4. **`vault_utils`** — Performs Vault init, unseal, backends/policies, spokes, and pushing secrets from `values-secret` files.

0 commit comments

Comments
 (0)