|
1 | 1 | --- |
2 | | -# pattern_dir may be overridden with -e pattern_dir=/path/to/pattern (extra vars win over this default). |
3 | | -# Default '.' is the usual case when ansible-playbook is run from the pattern repository root. |
| 2 | +# Root of the Validated Pattern checkout (directory that contains values-global.yaml, values-secret.yaml, etc.). |
| 3 | +# |
| 4 | +# Set explicitly; this is NOT inferred from the playbook file path when you run collection playbooks from |
| 5 | +# ~/.ansible/collections/... — and a literal '.' would mean the shell's current working directory, not the pattern repo. |
| 6 | +# |
| 7 | +# Configure either: |
| 8 | +# ansible-playbook .../display_secrets_info.yml -e pattern_dir=/absolute/path/to/pattern |
| 9 | +# or: |
| 10 | +# export PATTERN_DIR=/absolute/path/to/pattern |
| 11 | +# |
| 12 | +# Extra vars (-e pattern_dir) take precedence over PATTERN_DIR when both are set. |
4 | 13 | - name: Determine pattern dir |
5 | 14 | hosts: localhost |
6 | 15 | connection: local |
7 | 16 | gather_facts: false |
8 | 17 | become: false |
9 | 18 | vars: |
10 | | - pattern_dir: '.' |
| 19 | + pattern_dir: "{{ lookup('env', 'PATTERN_DIR', default='') }}" |
11 | 20 | tasks: |
| 21 | + - name: Fail if pattern directory is not configured |
| 22 | + ansible.builtin.fail: |
| 23 | + msg: >- |
| 24 | + pattern_dir is not set. Pass your pattern repository root (absolute path), e.g. |
| 25 | + ansible-playbook .../display_secrets_info.yml -e pattern_dir=/path/to/pattern |
| 26 | + or set environment variable PATTERN_DIR to that path before running. |
| 27 | + A default of '.' would follow the shell's current working directory, not the playbook |
| 28 | + directory, and is not used here to avoid loading the wrong values-global.yaml. |
| 29 | + when: pattern_dir | length == 0 |
| 30 | + |
12 | 31 | - name: Set pattern_dir fact for future plays |
13 | 32 | ansible.builtin.set_fact: |
14 | 33 | pattern_dir: '{{ pattern_dir }}' |
0 commit comments