-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdebug.yaml
83 lines (82 loc) · 2.38 KB
/
debug.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
---
- hosts: localhost
gather_facts: no
tasks:
- pause:
prompt: |
What do you want to see?
1 - single variable
2 - all variables
3 - group variables
4 - single fact
echo: yes
register: debug_option
- pause:
prompt: |
Which variable?
echo: yes
register: selected_var
when: debug_option.user_input == "1"
- pause:
prompt: |
Which fact?
echo: yes
register: selected_fact
when: debug_option.user_input == "4"
- pause:
prompt: |
For which host(s)?
echo: yes
register: target_hosts
when: debug_option.user_input != "3"
- pause:
prompt: |
For which group?
echo: yes
register: target_group
when: debug_option.user_input == "3"
- block:
- add_host:
name: "{{ item }}"
groups: debug
loop: "{{ groups[ target_hosts.user_input ] }}"
changed_when: False
when:
- debug_option.user_input != "3"
- groups[ target_hosts.user_input ] is defined
- block:
- add_host:
name: "{{ target_hosts.user_input }}"
groups: debug
changed_when: False
when:
- debug_option.user_input != "3"
- groups[ target_hosts.user_input ] is not defined
- block:
- debug:
msg:
- "{{ selected_var.user_input }}:"
- "{{ hostvars[item][selected_var.user_input] | default('NOT DEFINED') }}"
loop: "{{ groups['debug'] }}"
when: debug_option.user_input == "1"
- block:
- debug:
var: "{{ hostvars[item] }}"
loop: "{{ groups['debug'] }}"
when: debug_option.user_input == "2"
- debug:
var: "{{ groups[target_group.user_input] }}"
when: debug_option.user_input == "3"
- block:
- setup:
gather_subset:
- "{{ selected_fact.user_input | replace('ansible_', '') }}"
delegate_to: "{{ item }}"
delegate_facts: true
loop: "{{ groups['debug'] }}"
- debug:
msg:
- "{{ selected_fact.user_input }}:"
- "{{ hostvars[item][selected_fact.user_input] | default('NOT DEFINED') }}"
loop: "{{ groups['debug'] }}"
when: debug_option.user_input == "4"