-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_servers.yml
109 lines (92 loc) · 3 KB
/
check_servers.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
---
# set groups based on power status (Power_True and Power_False)
- name: wait for Linux server to be up
hosts: all
gather_facts: no
connection: local
strategy: linear
vars:
max_retry: 5
delay: 1
_ansible_connection: ssh
_ansible_user: root
_ansible_password: XXXX
_ansible_port: 22
tasks:
- name: wait for linux connection
wait_for_connection:
connect_timeout: 3
timeout: 120
sleep: 10
register: linux_is_reachable
- meta: clear_host_errors
- name: Linux PING
ping:
delegate_to: "{{ inventory_hostname }}"
register: linux_is_pinggable
ignore_errors: yes
when: linux_is_reachable|succeeded
#- debug: msg="linux_is_pinggable=(succedded={{linux_is_pinggable|succeeded}} skipped={{linux_is_pinggable|skipped}} failled={{linux_is_pinggable|failed}}){{ linux_is_pinggable }}"
- name: set linux POWER group
#group_by:
#key: "Linux_Power_{{ linux_is_pinggable|succeeded }}"
add_host:
name: "{{ inventory_hostname }}"
group: "Linux_Power_{{ linux_is_pinggable|succeeded }}"
ansible_connection: "{{ _ansible_connection }}"
ansible_user: "{{ _ansible_user }}"
ansible_password: "{{ _ansible_password }}"
ansible_port: "{{ _ansible_port }}"
when: (not linux_is_pinggable|failed) and linux_is_pinggable|succeeded and not linux_is_pinggable|skipped
- meta: clear_host_errors
- name: groupe
debug: "msg={{ groups }}"
- meta: clear_host_errors
- name: wait for Windows server to be up
hosts: all,!Linux_Power_True
gather_facts: no
connection: local
strategy: linear
vars:
max_retry: 1
delay: 1
_ansible_connection: winrm
_ansible_user: winUser
_ansible_password: winPasswd
_ansible_port: 5986
_ansible_winrm_server_cert_validation: ignore
tasks:
- name: set host vars
add_host:
name: "{{ inventory_hostname }}"
ansible_winrm_server_cert_validation: "{{ ansible_winrm_server_cert_validation }}"
- name: wait for windows connection
wait_for_connection:
connect_timeout: 5
timeout: 120
sleep: 10
register: windows_is_reachable
- meta: clear_host_errors
#- debug: msg="windows_is_reachable={{ windows_is_reachable }}"
- name: set windows POWER group
#group_by:
#key: "Windows_Power_{{ windows_is_reachable|succeeded }}"
add_host:
name: "{{ inventory_hostname }}"
group: "Windows_Power_{{ windows_is_reachable|succeeded }}"
ansible_connection: "{{ _ansible_connection }}"
ansible_user: "{{ _ansible_user }}"
ansible_password: "{{ _ansible_password }}"
ansible_port: "{{ _ansible_port }}"
ansible_winrm_server_cert_validation: "{{ _ansible_winrm_server_cert_validation }}"
when: windows_is_reachable|succeeded and not windows_is_reachable|skipped
- meta: clear_host_errors
- name: show groups
hosts: all
gather_facts: no
connection: local
strategy: linear
tasks:
- name: groups
debug: "msg={{ groups }}"
- include: "{{ playbooks }}"