33# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
44
55from __future__ import absolute_import , division , print_function
6+
67__metaclass__ = type
78
8- DOCUMENTATION = r'''
9+ DOCUMENTATION = r"""
910module: podman_system_info
1011author:
1112 - Johnson Lien (@johnsonlien)
2021 machine running C(podman)
2122 default: 'podman'
2223 type: str
23- '''
24+ """
2425
25- EXAMPLES = r'''
26+ EXAMPLES = r"""
2627- name: Get Podman system information
2728 containers.podman.podman_system_info:
2829
3233- name: Printing Podman System info
3334 debug:
3435 msg: "{{ podman_info['podman_system_info'] }}"
35- '''
36+ """
3637
37- RETURN = r'''
38+ RETURN = r"""
3839host:
3940 arch: amd64
4041 buildahVersion: 1.23.0
4445 conmon:
4546 package: conmon-2.0.29-2.fc34.x86_64
4647 path: /usr/bin/conmon
47- version: 'conmon version 2.0.29, commit: '
48- cpu_utilization:
49- idle_percent: 96.84
50- system_percent: 0.71
51- user_percent: 2.45
48+ version: 'conmon version 2.0.29, commit:'
49+ cpu_utilization:
50+ idle_percent: 96.84
51+ system_percent: 0.71
52+ user_percent: 2.45
5253 cpus: 8
5354 distribution:
5455 distribution: fedora
178179 GoVersion: go1.16.6
179180 OsArch: linux/amd64
180181 Version: 4.0.0
181- '''
182+ """
182183
183184import json
184185
185186from ansible .module_utils .basic import AnsibleModule
186187
188+
187189def get_podman_system_info (module , executable ):
188- command = [executable , ' system' , ' info' ]
189- rc , out , err = module .run_command (command )
190+ command = [executable , " system" , " info" , "--format" , "json" ]
191+ _ , out , err = module .run_command (command )
190192 out = out .strip ()
191193 if out :
192- return json .loads (out )
194+ try :
195+ return json .loads (out )
196+ except Exception as e :
197+ module .fail_json (
198+ msg = "Failed to parse podman system info output: error: %s, output: %s err: %s" % (e , out , err ),
199+ exception = str (e ),
200+ )
193201
194- module .log (msg = "Unable to get podman system info: %s" % err )
195- return json .dumps ([])
196202
197203def main ():
198204 module = AnsibleModule (
199205 argument_spec = dict (
200- executable = dict (type = ' str' , default = ' podman' ),
206+ executable = dict (type = " str" , default = " podman" ),
201207 ),
202208 supports_check_mode = True ,
203209 )
204210
205- executable = module .get_bin_path (module .params [' executable' ], required = True )
211+ executable = module .get_bin_path (module .params [" executable" ], required = True )
206212
207213 results = get_podman_system_info (module , executable )
208214
@@ -213,5 +219,6 @@ def main():
213219
214220 module .exit_json (** results )
215221
216- if __name__ == '__main__' :
222+
223+ if __name__ == "__main__" :
217224 main ()
0 commit comments