-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdisplay-hostvars.yml
132 lines (121 loc) · 5.57 KB
/
display-hostvars.yml
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
---
- name: Gather facts for all hosts to apply OS specific group vars for them
tags: always
hosts: all
ignore_unreachable: true
tasks:
- name: Set os info
ansible.builtin.set_fact:
os_family: "{{ 'os_linux' if ansible_os_family|d('')|lower in ['debian', 'redhat']
else ansible_os_family|d('Unknown') }}"
os_distribution: "os_{{ ansible_facts['distribution'] |d('Unknown') | lower | replace(' ','_') }}"
os_distribution_version: "os_{{ ansible_facts['distribution'] |d('Unknown') | lower
| replace(' ','_') }}_{{ ansible_facts['distribution_major_version']
| d(ansible_facts['distribution_release'])|d('Unknown') | lower | replace('.','_') | replace(' ','_') }}"
- name: Set os info for windows for vmware esx
when: ansible_os_family|d('')=='VMkernel'
ansible.builtin.set_fact:
os_family: "dc_os_esxi"
os_distribution: "esxi"
os_distribution_version: "dc_os_esxi_{{ ansible_facts['distribution_major_version']
| d(ansible_facts['distribution_release']) |d('Unknown') | lower | replace('.','_') | replace(' ','_') }}"
- name: Set os info for windows for vmware vcenter
when: ansible_os_family|d('')=='VMware Photon'
ansible.builtin.set_fact:
os_family: "os_vsphere"
os_distribution: "vsphere"
os_distribution_version: "os_vsphere_{{ ansible_facts['distribution']|d('Unknown') | lower
| replace(' ','_') }}_v{{ ansible_facts['distribution_major_version'] |d('Unknown') }}"
- name: Set os info for windows
when: ansible_os_family|d('')|lower is search('windows')
ansible.builtin.set_fact:
os_family: "os_windows"
os_distribution: "windows"
os_distribution_version: "os_windows_{{ ansible_facts['distribution']|d('Unknown')
| lower | replace(' ','_') | regex_replace('(microsoft_|windows_)', '') }}"
- name: Display os group classification info
ansible.builtin.debug:
msg:
- os_family={{ os_family }}
- os_distribution={{ os_distribution }}
- os_distribution_version={{ os_distribution_version }}
- name: Group hosts based on os_family
changed_when: false
ansible.builtin.group_by:
key: "{{ os_family }}"
## ref: https://github.com/ansible/ansible/issues/76788
- name: Group hosts based on os_distribution
changed_when: false
ansible.builtin.group_by:
key: "{{ os_distribution }}"
parents: "{{ os_family }}"
- name: Group hosts based on os_distribution_version
changed_when: false
ansible.builtin.group_by:
key: "{{ os_distribution_version }}"
parents: "{{ os_distribution }}"
# - name: Classify hosts depending on their internal domain
# changed_when: no
# ansible.builtin.group_by:
# key: ca_domain_{{ ('_').join( inventory_hostname.split('.')[1::]|reverse ) | d(internal_domain) }}
- name: Display important common variable information
tags: always
hosts: all
ignore_unreachable: true
ignore_errors: true
gather_facts: false
tasks:
- name: Display important common variable information
when: inventory_hostname in ansible_play_hosts
ansible.builtin.debug:
msg:
- inventory_hostname={{ inventory_hostname | d('unknown') }}
- inventory_hostname_short={{ inventory_hostname_short | d('unknown') }}
- internal_subdomain={{ internal_subdomain | d('') }}
- internal_domain={{ internal_domain | d('unknown') }}
- netbase__hostname={{ netbase__hostname }}
- ansible_user={{ ansible_user }}
- ansible_host={{ ansible_host }}
- ansible_hostname={{ ansible_hostname | d('') }}
- ansible_port={{ ansible_port | d('') }}
- ansible_fqdn={{ ansible_fqdn | d('') }}
- ansible_default_ipv4.address={{ ansible_default_ipv4.address | d(ansible_all_ipv4_addresses[0]) | d('') }}
- ansible_os_family={{ ansible_os_family | d('unknown') }}
- ansible_distribution={{ ansible_distribution | d('unknown') }}
- ansible_distribution_release={{ ansible_distribution_release | d('unknown') }}
- ansible_distribution_major_version={{ ansible_distribution_major_version | d('unknown') }}
- os_python_interpreter={{ os_python_interpreter }}
- ansible_python_interpreter={{ ansible_python_interpreter | d('unknown') }}
- ansible_pip_interpreter={{ ansible_pip_interpreter | d('unknown') }}
- group_names={{ group_names | d('') }}
- ntp_servers={{ ntp_servers | d('') }}
- docker_stack_external_domain={{ docker_stack_external_domain | d('') }}
- docker_stack_internal_domain={{ docker_stack_internal_domain | d('') }}
- ca_domain={{ ca_domain | d('unknown') }}
- ca_domains_hosted={{ ca_domains_hosted | d('') }}
## Debugging purposes: print all environment variables
## ref: https://gryzli.info/2017/12/21/ansible-debug-print-variables/
- name: "Debug: Print environment variables"
hosts: all,!node_offline
tags:
- display-envvars
- debug-envvars
- debug-env-vars
tasks:
- name: Print env var debug information
when: inventory_hostname in ansible_play_hosts
ansible.builtin.debug:
var: environment
tags: debug_info
- name: Display hostvars
hosts: all,!node_offline
gather_facts: true
tags:
- debug-hostvars
- display-hostvars
tasks:
- name: Print host variable information
when: inventory_hostname in ansible_play_hosts
ansible.builtin.debug:
var: hostvars
tags: debug_info