-
Notifications
You must be signed in to change notification settings - Fork 2
/
generate_spec.yml
183 lines (149 loc) · 6.26 KB
/
generate_spec.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
---
- hosts: all
become: no
gather_facts: yes
tasks:
- name : Create host_vars folder
local_action: file
path=./host_vars
state=directory
- name: Destroy exsting spec file
local_action: file
path=./host_vars/{{ inventory_hostname }}.yml
state=absent
- name: Create spec file
local_action: file
path=./host_vars/{{ inventory_hostname }}.yml
state=touch
- name: Create yaml header
local_action: lineinfile
line="---\n"
dest=./host_vars/{{ inventory_hostname }}.yml
- name: Add cpu model
local_action: lineinfile
line="cpu_model{{':'}} '{{ ansible_processor[1] }}'"
dest=./host_vars/{{ inventory_hostname }}.yml
- name: Add cpu count
local_action: lineinfile
line="cpu_count{{':'}} {{ ansible_processor_count }}"
dest=./host_vars/{{ inventory_hostname }}.yml
- name: Add cores per cpu
local_action: lineinfile
line="cores_per_cpu{{':'}} {{ ansible_processor_cores }}"
dest=./host_vars/{{ inventory_hostname }}.yml
- name: Add total memory (mb)
local_action: lineinfile
line="total_memory_mb{{':'}} {{ ansible_memtotal_mb }}"
dest=./host_vars/{{ inventory_hostname }}.yml
- name: Add free memory (mb)
local_action: lineinfile
line="free_memory_mb{{':'}} {{ ansible_memfree_mb }}"
dest=./host_vars/{{ inventory_hostname }}.yml
- name: Add total swap space (mb)
local_action: lineinfile
line="total_swap_mb{{':'}} {{ ansible_swaptotal_mb }}"
dest=./host_vars/{{ inventory_hostname }}.yml
- name: Add virtualization type
local_action: lineinfile
line="virtualization_type{{':'}} '{{ ansible_virtualization_type }}'"
dest=./host_vars/{{ inventory_hostname }}.yml
- name: Add IPv4 addresses declaration
local_action: lineinfile
line="ipv4_addresses{{':'}}"
dest=./host_vars/{{ inventory_hostname }}.yml
- name: Add IPv4 addresses declaration
local_action: lineinfile
line=" - \"{{ item }}\""
dest=./host_vars/{{ inventory_hostname }}.yml
with_items: ansible_all_ipv4_addresses
- name: Add IPv6 addresses declaration
local_action: lineinfile
line="ipv6_addresses{{':'}}"
dest=./host_vars/{{ inventory_hostname }}.yml
- name: Add IPv6 addresses declaration
local_action: lineinfile
line=" - \"{{ item }}\""
dest=./host_vars/{{ inventory_hostname }}.yml
with_items: ansible_all_ipv6_addresses
- name: Add system architecture
local_action: lineinfile
line="system_architecture{{':'}} '{{ ansible_architecture }}'"
dest=./host_vars/{{ inventory_hostname }}.yml
- name: Add linux distribution
local_action: lineinfile
line="linux_distribution{{':'}} '{{ ansible_distribution }}'"
dest=./host_vars/{{ inventory_hostname }}.yml
- name: Add distribution version
local_action: lineinfile
line="distribution_version{{':'}} '{{ ansible_distribution_version }}'"
dest=./host_vars/{{ inventory_hostname }}.yml
- name: Add FQDN
local_action: lineinfile
line="fqdn{{':'}} '{{ ansible_fqdn }}'"
dest=./host_vars/{{ inventory_hostname }}.yml
- name: Add selinux (when installed)
local_action: lineinfile
line="selinux_status{{':'}} '{{ ansible_selinux.status }}'"
dest=./host_vars/{{ inventory_hostname }}.yml
when: ansible_selinux.status is defined
- name: Add selinux (not installed)
local_action: lineinfile
line="selinux_status{{':'}} 'N/A'"
dest=./host_vars/{{ inventory_hostname }}.yml
when: ansible_selinux.status is not defined
- name: Get CPU performance stats
shell: echo '2^2^21' | { /usr/bin/time -f '%e' bc > /dev/null ;} 2>&1
ignore_errors: yes
register: cpu_performance
- name: Add CPU performance stats
local_action: lineinfile
line="cpu_performance{{':'}} '{{ cpu_performance.stdout }}'"
dest=./host_vars/{{ inventory_hostname }}.yml
when: cpu_performance|succeeded
- name: Add CPU performance stats
local_action: lineinfile
line="cpu_performance{{':'}} 'N/A'"
dest=./host_vars/{{ inventory_hostname }}.yml
when: cpu_performance|failed
- name: Get bandwidth stats
shell: speedtest --simple
ignore_errors: yes
register: network_performance
- name: Add bandwidth stats
local_action: lineinfile
line="{{ network_performance.stdout }}"
dest=./host_vars/{{ inventory_hostname }}.yml
when: network_performance|succeeded
- name: Add bandwidth stats
local_action: lineinfile
line="Ping{{':'}} 'N/A'\nDownload{{':'}} 'N/A'\nUpload{{':'}} 'N/A'"
dest=./host_vars/{{ inventory_hostname }}.yml
when: network_performance|failed
- name: Get CPU utilization
shell: top -b -n2 -p 1 | fgrep "Cpu(s)" | tail -1 | awk -F'id,' -v prefix="$prefix" '{ split($1, vs, ","); v=vs[length(vs)]; sub("%", "", v); printf "%s%.1f%%\n", prefix, 100 - v }'
ignore_errors: yes
register: cpu_utilization
- name: Add CPU utilization
local_action: lineinfile
line="cpu_utilization{{':'}} '{{ cpu_utilization.stdout }}'"
dest=./host_vars/{{ inventory_hostname }}.yml
when: cpu_utilization|succeeded
- name: Add CPU utilization
local_action: lineinfile
line="cpu_utilization{{':'}} 'N/A'"
dest=./host_vars/{{ inventory_hostname }}.yml
when: cpu_utilization|failed
- name: Get outstanding security updates
shell: /usr/bin/yum --debuglevel 2 --security check-update 2>/dev/null | head -n 2 | tail -n 1 | awk '{ print $1 }'
ignore_errors: yes
register: security_patches
- name: Add outstanding security patches
local_action: lineinfile
line="security_patches{{':'}} '{{ security_patches.stdout }}'"
dest=./host_vars/{{ inventory_hostname }}.yml
when: security_patches|succeeded
- name: Add outstanding security patches
local_action: lineinfile
line="security_patches{{':'}} 'N/A'"
dest=./host_vars/{{ inventory_hostname }}.yml
when: security_patches|failed