1818for k , v in default_config .items ():
1919 os .environ [k ] = v
2020
21+
2122# Loading config file must be prior to importing most of the ansible.* packages
2223def find_config_file ():
2324 """Find configuration file"""
@@ -104,22 +105,27 @@ def method(*args, **kwargs):
104105
105106 return method
106107
108+
107109def ram_allocated_gb (facts ):
108110 """Return total memory allocation in GB"""
109111 return facts ["ansible_memtotal_mb" ] / 1024
110112
113+
111114def ram_used_gb (facts ):
112115 """Return used memory in GB"""
113116 return (facts ["ansible_memtotal_mb" ] - facts ["ansible_memfree_mb" ]) / 1024
114117
118+
115119def _size (key , mounts ):
116120 return sum ([item .get (key , 0 ) for item in mounts ])
117121
122+
118123def storage_allocated_gb (facts ):
119124 """Return total storage allocation in GB"""
120125 if "ansible_mounts" not in facts :
121126 return 0
122- return _size ("size_total" , facts ["ansible_mounts" ]) / 1024 ** 3
127+ return _size ("size_total" , facts ["ansible_mounts" ]) / 1024 ** 3
128+
123129
124130def storage_used_gb (facts ):
125131 """Return used storage in GB"""
@@ -128,12 +134,14 @@ def storage_used_gb(facts):
128134 return (
129135 _size ("size_total" , facts ["ansible_mounts" ])
130136 - _size ("size_available" , facts ["ansible_mounts" ])
131- ) / 1024 ** 3
137+ ) / 1024 ** 3
138+
132139
133140def cpu_logical_processors (facts ):
134141 """Return the number of CPU logical processors."""
135142 return int (facts .get ("ansible_processor_vcpus" , 0 ))
136143
144+
137145def cpu_name (proc ):
138146 """Return CPU name"""
139147 items_count = len (proc )
@@ -143,10 +151,16 @@ def cpu_name(proc):
143151 return proc [2 ]
144152 return "Unknown"
145153
154+
146155def ip_addresses (facts ):
147156 """Return IP addresses formatted for the tidal API"""
148- return list (map (lambda ip : {"address" : ip },
149- facts ["ansible_all_ipv4_addresses" ] + facts ["ansible_all_ipv6_addresses" ]))
157+ return list (
158+ map (
159+ lambda ip : {"address" : ip },
160+ facts ["ansible_all_ipv4_addresses" ] + facts ["ansible_all_ipv6_addresses" ],
161+ )
162+ )
163+
150164
151165class ResultCallback (CallbackBase ):
152166 """A sample callback plugin used for performing an action as results come in
@@ -189,14 +203,17 @@ def update_results(self, host, data: dict):
189203 if host not in self ._total_results :
190204 self ._total_results [host ] = data
191205 return
192-
206+
193207 # Ensure we append any custom fields, rather than overwriting them
194- if 'custom_fields' in data and 'custom_fields' in self ._total_results [host ]:
195- combined_custom_fields = {** self ._total_results [host ]['custom_fields' ], ** data ['custom_fields' ]}
196- data ['custom_fields' ].update (combined_custom_fields )
208+ if "custom_fields" in data and "custom_fields" in self ._total_results [host ]:
209+ combined_custom_fields = {
210+ ** self ._total_results [host ]["custom_fields" ],
211+ ** data ["custom_fields" ],
212+ }
213+ data ["custom_fields" ].update (combined_custom_fields )
197214 self ._total_results [host ].update (data )
198215 return
199-
216+
200217 self ._total_results [host ].update (data )
201218
202219 def v2_runner_on_ok (self , result ):
@@ -241,37 +258,37 @@ def v2_playbook_on_stats(self, stats):
241258 t = stats .summarize (h ) # pylint: disable=invalid-name
242259
243260 self ._display .display (
244- u "%s : %s %s %s %s %s %s %s"
261+ "%s : %s %s %s %s %s %s %s"
245262 % (
246263 hostcolor (h , t ),
247- colorize (u "ok" , t ["ok" ], C .COLOR_OK ), # pylint: disable=no-member
264+ colorize ("ok" , t ["ok" ], C .COLOR_OK ), # pylint: disable=no-member
248265 colorize (
249- u "changed" ,
266+ "changed" ,
250267 t ["changed" ],
251268 C .COLOR_CHANGED , # pylint: disable=no-member
252269 ),
253270 colorize (
254- u "unreachable" ,
271+ "unreachable" ,
255272 t ["unreachable" ],
256273 C .COLOR_UNREACHABLE , # pylint: disable=no-member
257274 ),
258275 colorize (
259- u "failed" ,
276+ "failed" ,
260277 t ["failures" ],
261278 C .COLOR_ERROR , # pylint: disable=no-member
262279 ),
263280 colorize (
264- u "skipped" ,
281+ "skipped" ,
265282 t ["skipped" ],
266283 C .COLOR_SKIP , # pylint: disable=no-member
267284 ),
268285 colorize (
269- u "rescued" ,
286+ "rescued" ,
270287 t ["rescued" ],
271288 C .COLOR_OK , # pylint: disable=no-member
272289 ),
273290 colorize (
274- u "ignored" ,
291+ "ignored" ,
275292 t ["ignored" ],
276293 C .COLOR_WARN , # pylint: disable=no-member
277294 ),
@@ -322,7 +339,9 @@ def v2_playbook_on_stats(self, stats):
322339 server_dict ["measurable_type" ] = "server"
323340 server_dict ["field_name" ] = custom_field + "_timeseries"
324341 server_dict ["value" ] = server ["custom_fields" ][custom_field ]
325- server_dict ["external_timestamp" ] = server ["custom_fields" ]["cpu_utilization_timestamp" ]
342+ server_dict ["external_timestamp" ] = server ["custom_fields" ][
343+ "cpu_utilization_timestamp"
344+ ]
326345 server_dict ["measurable" ] = {
327346 "host_name" : server ["host_name" ]
328347 }
0 commit comments