Skip to content

Commit 2dd7cfe

Browse files
johnsonliensshnaidm
authored andcommitted
Add systeminfo module
Signed-off-by: Sagi Shnaidman <[email protected]>
2 parents 179f219 + ec2f66d commit 2dd7cfe

File tree

2 files changed

+28
-20
lines changed

2 files changed

+28
-20
lines changed

plugins/modules/podman_system_info.py

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
44

55
from __future__ import absolute_import, division, print_function
6+
67
__metaclass__ = type
78

8-
DOCUMENTATION = r'''
9+
DOCUMENTATION = r"""
910
module: podman_system_info
1011
author:
1112
- Johnson Lien (@johnsonlien)
@@ -20,9 +21,9 @@
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
@@ -32,9 +33,9 @@
3233
- name: Printing Podman System info
3334
debug:
3435
msg: "{{ podman_info['podman_system_info'] }}"
35-
'''
36+
"""
3637

37-
RETURN = r'''
38+
RETURN = r"""
3839
host:
3940
arch: amd64
4041
buildahVersion: 1.23.0
@@ -44,11 +45,11 @@
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
@@ -178,31 +179,36 @@
178179
GoVersion: go1.16.6
179180
OsArch: linux/amd64
180181
Version: 4.0.0
181-
'''
182+
"""
182183

183184
import json
184185

185186
from ansible.module_utils.basic import AnsibleModule
186187

188+
187189
def 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

197203
def 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()
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
- name: Get Podman system info
22
containers.podman.podman_system_info:
3+
executable: "{{ test_executable | default('podman') }}"
34
register: podman_info
45

56
- name: Check results
6-
assert:
7+
assert:
78
that:
89
- podman_info.podman_system_info | length > 0

0 commit comments

Comments
 (0)