-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ansible): add role for variable debugging
- Loading branch information
Showing
3 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Role - debug_forge_vars | ||
|
||
This role is used for debugging purposes only. | ||
|
||
## Variables | ||
|
||
The role has the following variables defined. | ||
|
||
### default/main.yml | ||
|
||
In the [main.yml](./defaults/main.yml/) all variables are defined which are | ||
used in the context of debugging. Usually end-users should not worry about them to much. | ||
|
||
<!-- markdownlint-disable MD013 --> | ||
|
||
| name | type | default value | description | | ||
| ------------------------------- | ---- | ------------- | ------------------------------------------------------------------------------------------- | | ||
| `forge_debug_vars_regex_search` | str | ^forge\_.+ | Python regex search term. Useful if you want to print out all variables starting with `xyz` | | ||
|
||
<!-- markdownlint-enable MD013 --> | ||
|
||
## Example Playbook Usage | ||
|
||
This role is best included in a playbook as pre-task: | ||
|
||
```yaml | ||
pre_tasks: | ||
- name: DEBUG - forge variables | ||
ansible.builtin.include_role: | ||
name: debug_forge_vars | ||
``` | ||
With the role included you can launch the playbook in verbose mode `ansible-playbook -v`. | ||
This will print all variables found with the regex search term defined in the `forge_debug_vars_regex_search` | ||
variable. | ||
|
||
You can modify the `forge_debug_vars_regex_search` term by changing it via the vars statement | ||
|
||
```yaml | ||
pre_tasks: | ||
- name: DEBUG - forge git variables | ||
ansible.builtin.include_role: | ||
name: debug_forge_vars | ||
vars: | ||
forge_debug_vars_regex_search: ^forge_git.+ | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Default vars for this role | ||
forge_debug_vars_regex_search: "{{ lookup('ansible.builtin.env', 'FORGE_DEBUG_VARS_REGEX_SEARCH', default='^forge_.+') }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
# main task file for this role | ||
|
||
- name: DEBUG | forge variables | ||
ansible.builtin.debug: | ||
msg: "{{ item }}: {{ lookup('ansible.builtin.vars', item) }}" | ||
verbosity: 1 | ||
loop: "{{ __forge_vars_used }}" | ||
loop_control: | ||
extended: true | ||
label: "{{ ansible_loop.index }}/{{ ansible_loop.length }}" | ||
vars: | ||
__forge_vars_used: "{{ lookup('ansible.builtin.varnames', forge_debug_vars_regex_search, wantlist=true) }}" |