Skip to content

Commit 9beb5f9

Browse files
author
Martin Jackson
committed
Update determine_pattern_dir to allow defaults
1 parent 3f0e3d8 commit 9beb5f9

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Alternatively, set `VALUES_SECRET` to an **existing** file whose name ends with
5050
| `playbooks/load_bootstrap_secrets_only.yml` | **Bootstrap only**: same pattern discovery plays and `pattern_settings`, then only bootstrap inject (with retries). **Fails** if no bootstrap file is found. Does **not** read `secretLoader.disabled` or load the primary file. |
5151
| `playbooks/display_secrets_info.yml` | Loads and displays parsed primary secrets (using the backend from `values-global`). If a bootstrap file exists, also parses and displays it with backing store `none`. Missing bootstrap is not an error. |
5252

53-
Typical usage sets `-e pattern_dir=...` to the pattern checkout (and relies on `values-global.yaml` there via `pattern_settings`).
53+
Typical usage passes the pattern checkout as `pattern_dir` (for example `-e pattern_dir=/path/to/pattern`). If you omit it, the same resolution as `pattern_settings` applies: `PATTERN_DIR`, then `PWD`, then the `pwd` command.
5454

5555
`playbooks/install.yml` imports `load_secrets.yml` after the pattern install playbook, so the combined bootstrap-then-primary flow runs during install when secret loading is enabled.
5656

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
---
2+
# Resolves pattern_dir the same way as the pattern_settings role (extra-vars, PATTERN_DIR, PWD, pwd),
3+
# then fails if still unset. Used by display_secrets_info, load_values_global, load_bootstrap_secrets*, etc.
24
- name: Determine pattern dir
35
hosts: localhost
46
connection: local
57
gather_facts: false
68
become: false
7-
vars:
8-
pattern_dir: ''
99
tasks:
10-
- name: Fail if directory is not set
10+
- name: Resolve pattern_dir from extra-vars, PATTERN_DIR, PWD, or pwd
11+
ansible.builtin.include_role:
12+
name: pattern_settings
13+
tasks_from: resolve_overrides.yml
14+
15+
- name: Fail if pattern directory is not set after resolution
1116
ansible.builtin.fail:
12-
msg: "pattern_dir variable must be set"
13-
when: pattern_dir | length == 0
17+
msg: >-
18+
pattern_dir is not set. Pass -e pattern_dir=/path/to/pattern, export PATTERN_DIR to that path,
19+
or run the playbook from the pattern directory so PWD is correct.
20+
when: pattern_dir | default('') | string | trim | length == 0
1421

1522
- name: Set pattern_dir fact for future plays
1623
ansible.builtin.set_fact:
17-
pattern_dir: '{{ pattern_dir }}'
24+
pattern_dir: "{{ pattern_dir | string | trim }}"

0 commit comments

Comments
 (0)