Skip to content

Commit aa20ede

Browse files
Add podman system info module (#922)
Add podman system info module Signed-off-by: johnsonlien <[email protected]> Signed-off-by: Sagi Shnaidman <[email protected]> Co-authored-by: Sagi Shnaidman <[email protected]>
1 parent f6bd81e commit aa20ede

File tree

4 files changed

+388
-0
lines changed

4 files changed

+388
-0
lines changed
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
name: Podman system info
2+
3+
on:
4+
push:
5+
paths:
6+
- '.github/workflows/podman_system_info.yml'
7+
- 'ci/*.yml'
8+
- 'ci/run_containers_tests.sh'
9+
- 'ci/playbooks/containers/podman_system_info.yml'
10+
- 'plugins/modules/podman_system_info.py'
11+
- 'tests/integration/targets/podman_system_info/**'
12+
branches:
13+
- main
14+
pull_request:
15+
paths:
16+
- '.github/workflows/podman_system_info.yml'
17+
- 'ci/*.yml'
18+
- 'ci/run_containers_tests.sh'
19+
- 'ci/playbooks/containers/podman_system_info.yml'
20+
- 'plugins/modules/podman_system_info.py'
21+
- 'tests/integration/targets/podman_system_info/**'
22+
schedule:
23+
- cron: 4 0 * * * # Run daily at 0:03 UTC
24+
25+
jobs:
26+
27+
test_podman_system_info:
28+
name: Podman system info ${{ matrix.ansible-version }}-${{ matrix.os || 'ubuntu-22.04' }}
29+
runs-on: ${{ matrix.os || 'ubuntu-22.04' }}
30+
defaults:
31+
run:
32+
shell: bash
33+
strategy:
34+
fail-fast: false
35+
matrix:
36+
ansible-version:
37+
- git+https://github.com/ansible/[email protected]
38+
- git+https://github.com/ansible/ansible.git@devel
39+
os:
40+
- ubuntu-22.04
41+
python-version:
42+
- "3.11"
43+
44+
steps:
45+
46+
- name: Check out repository
47+
uses: actions/checkout@v4
48+
49+
- name: Set up Python ${{ matrix.python-version }}
50+
uses: actions/setup-python@v5
51+
with:
52+
python-version: ${{ matrix.python-version }}
53+
54+
- name: Upgrade pip and display Python and PIP versions
55+
run: |
56+
sudo apt-get update
57+
sudo apt-get install -y python*-wheel python*-yaml
58+
python -m pip install --upgrade pip
59+
python -V
60+
pip --version
61+
62+
- name: Set up pip cache
63+
uses: actions/cache@v4
64+
with:
65+
path: ~/.cache/pip
66+
key: ${{ runner.os }}-pip-${{ github.ref }}-units-VMs
67+
restore-keys: |
68+
${{ runner.os }}-pip-
69+
${{ runner.os }}-
70+
71+
- name: Install Ansible ${{ matrix.ansible-version }}
72+
run: python3 -m pip install --user --force-reinstall --upgrade '${{ matrix.ansible-version }}'
73+
74+
- name: Build and install the collection tarball
75+
run: |
76+
export PATH=~/.local/bin:$PATH
77+
78+
echo "Run ansible version"
79+
command -v ansible
80+
ansible --version
81+
rm -rf /tmp/just_new_collection
82+
~/.local/bin/ansible-galaxy collection build --output-path /tmp/just_new_collection --force
83+
~/.local/bin/ansible-galaxy collection install -vvv --force /tmp/just_new_collection/*.tar.gz
84+
85+
- name: Run collection tests for podman system info
86+
run: |
87+
export PATH=~/.local/bin:$PATH
88+
89+
export ANSIBLE_CONFIG=$(pwd)/ci/ansible-dev.cfg
90+
if [[ '${{ matrix.ansible-version }}' == 'ansible<2.10' ]]; then
91+
export ANSIBLE_CONFIG=$(pwd)/ci/ansible-2.9.cfg
92+
fi
93+
94+
echo $ANSIBLE_CONFIG
95+
command -v ansible-playbook
96+
pip --version
97+
python --version
98+
ansible-playbook --version
99+
100+
ansible-playbook -vv ci/playbooks/pre.yml \
101+
-e host=localhost \
102+
-i localhost, \
103+
-e ansible_connection=local \
104+
-e setup_python=false
105+
106+
TEST2RUN=podman_system_info ./ci/run_containers_tests.sh
107+
shell: bash
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
- hosts: all
3+
gather_facts: true
4+
tasks:
5+
- include_role:
6+
name: podman_system_info
7+
vars:
8+
ansible_python_interpreter: "{{ _ansible_python_interpreter }}"
Lines changed: 264 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,264 @@
1+
#!/usr/bin/python
2+
# Copyright (c) 2025 Ansible Project
3+
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
4+
5+
from __future__ import absolute_import, division, print_function
6+
7+
__metaclass__ = type
8+
9+
DOCUMENTATION = r"""
10+
module: podman_system_info
11+
author:
12+
- Johnson Lien (@johnsonlien)
13+
short_description: Get podman system information from host machine
14+
description: Runs "podman system info" on host machine
15+
requirements:
16+
- "Podman installed on host"
17+
options:
18+
executable:
19+
description:
20+
- Path to C(podman) executable if it is not in the C($PATH) on the
21+
machine running C(podman)
22+
default: 'podman'
23+
type: str
24+
"""
25+
26+
EXAMPLES = r"""
27+
- name: Get Podman system information
28+
containers.podman.podman_system_info:
29+
30+
- name: Get Podman system information into a variable
31+
containers.podman.podman_system_info:
32+
register: podman_info
33+
- name: Printing Podman System info
34+
debug:
35+
msg: "{{ podman_info['podman_system_info'] }}"
36+
"""
37+
38+
RETURN = r"""
39+
podman_system_info:
40+
description: System information from podman
41+
returned: always
42+
type: dict
43+
sample:
44+
{
45+
"host": {
46+
"arch": "amd64",
47+
"buildahVersion": "1.40.1",
48+
"cgroupManager": "systemd",
49+
"cgroupVersion": "v2",
50+
"cgroupControllers": [
51+
"cpu",
52+
"io",
53+
"memory",
54+
"pids"
55+
],
56+
"conmon": {
57+
"package": "conmon-2.1.13-1.fc41.x86_64",
58+
"path": "/usr/bin/conmon",
59+
"version": "conmon version 2.1.13, commit "
60+
},
61+
"cpus": 12,
62+
"cpuUtilization": {
63+
"userPercent": 5.73,
64+
"systemPercent": 2.15,
65+
"idlePercent": 92.12
66+
},
67+
"databaseBackend": "boltdb",
68+
"distribution": {
69+
"distribution": "fedora",
70+
"variant": "workstation",
71+
"version": "41"
72+
},
73+
"eventLogger": "journald",
74+
"freeLocks": 897,
75+
"hostname": "user.remote",
76+
"idMappings": {
77+
"gidmap": [
78+
{
79+
"container_id": 0,
80+
"host_id": 1000,
81+
"size": 1
82+
},
83+
{
84+
"container_id": 1,
85+
"host_id": 100000,
86+
"size": 65536
87+
}
88+
],
89+
"uidmap": [
90+
{
91+
"container_id": 0,
92+
"host_id": 1000,
93+
"size": 1
94+
},
95+
{
96+
"container_id": 1,
97+
"host_id": 100000,
98+
"size": 65536
99+
}
100+
]
101+
},
102+
"kernel": "6.14.9-200.fc41.x86_64",
103+
"logDriver": "journald",
104+
"memFree": 3055095808,
105+
"memTotal": 67157032960,
106+
"networkBackend": "netavark",
107+
"networkBackendInfo": {
108+
"backend": "netavark",
109+
"version": "netavark 1.15.2",
110+
"package": "netavark-1.15.2-1.fc41.x86_64",
111+
"path": "/usr/libexec/podman/netavark",
112+
"dns": {
113+
"version": "aardvark-dns 1.15.0",
114+
"package": "aardvark-dns-1.15.0-1.fc41.x86_64",
115+
"path": "/usr/libexec/podman/aardvark-dns"
116+
}
117+
},
118+
"ociRuntime": {
119+
"name": "crun",
120+
"package": "crun-1.21-1.fc41.x86_64",
121+
"path": "/usr/bin/crun",
122+
"version": "crun version 1.21..."
123+
},
124+
"os": "linux",
125+
"remoteSocket": {
126+
"path": "/run/user/1000/podman/podman.sock",
127+
"exists": true
128+
},
129+
"rootlessNetworkCmd": "pasta",
130+
"serviceIsRemote": false,
131+
"security": {
132+
"apparmorEnabled": false,
133+
"capabilities": "CAP_CHOWN,CAP_DAC_OVERRIDE,CAP_FOWNER,CAP_FSETID,CAP_KILL,...",
134+
"rootless": true,
135+
"seccompEnabled": true,
136+
"seccompProfilePath": "/usr/share/containers/seccomp.json",
137+
"selinuxEnabled": true
138+
},
139+
"slirp4netns": {
140+
"executable": "/usr/bin/slirp4netns",
141+
"package": "slirp4netns-1.3.1-1.fc41.x86_64",
142+
"version": "slirp4netns version 1.3.1\ncommit..."
143+
},
144+
"pasta": {
145+
"executable": "/usr/bin/pasta",
146+
"package": "passt-0^20250611.g0293c6f-1.fc41.x86_64",
147+
"version": "pasta 0^20250611.g0293c6f-1.fc41.x86_64\nCopyright Red Hat\n..."
148+
},
149+
"swapFree": 1911504896,
150+
"swapTotal": 8589930496,
151+
"uptime": "115h 11m 51.00s (Approximately 3.88 days)",
152+
"variant": "",
153+
"linkmode": "dynamic"
154+
},
155+
"store": {
156+
"configFile": "/home/user/.config/containers/storage.conf",
157+
"containerStore": {
158+
"number": 6,
159+
"paused": 0,
160+
"running": 1,
161+
"stopped": 5
162+
},
163+
"graphDriverName": "overlay",
164+
"graphOptions": {
165+
"overlay.mountopt": "nodev"
166+
},
167+
"graphRoot": "/home/user/.local/share/containers/storage",
168+
"graphRootAllocated": 502921060352,
169+
"graphRootUsed": 457285541888,
170+
"graphStatus": {
171+
"Backing Filesystem": "extfs",
172+
"Native Overlay Diff": "false",
173+
"Supports d_type": "true",
174+
"Supports shifting": "true",
175+
"Supports volatile": "true",
176+
"Using metacopy": "false"
177+
},
178+
"imageCopyTmpDir": "/var/tmp",
179+
"imageStore": {
180+
"number": 859
181+
},
182+
"runRoot": "/run/user/1000/containers",
183+
"volumePath": "/storage/containers/storage/volumes",
184+
"transientStore": false
185+
},
186+
"registries": {
187+
"search": [
188+
"registry.fedoraproject.org",
189+
"registry.access.redhat.com",
190+
"docker.io"
191+
]
192+
},
193+
"plugins": {
194+
"volume": [
195+
"local"
196+
],
197+
"network": [
198+
"bridge",
199+
"macvlan",
200+
"ipvlan"
201+
],
202+
"log": [
203+
"k8s-file",
204+
"none",
205+
"passthrough",
206+
"journald"
207+
],
208+
"authorization": null
209+
},
210+
"version": {
211+
"APIVersion": "5.5.1",
212+
"Version": "5.5.1",
213+
"GoVersion": "go1.23.9",
214+
"GitCommit": "850db76dd78a0641eddb9ee19ee6f60d2c59bcfa",
215+
"BuiltTime": "Thu Jun 5 03:00:00 2025",
216+
"Built": 1749081600,
217+
"BuildOrigin": "Fedora Project",
218+
"OsArch": "linux/amd64",
219+
"Os": "linux"
220+
}
221+
}
222+
"""
223+
224+
import json
225+
226+
from ansible.module_utils.basic import AnsibleModule
227+
228+
229+
def get_podman_system_info(module, executable):
230+
command = [executable, "system", "info", "--format", "json"]
231+
rc, out, err = module.run_command(command)
232+
out = out.strip()
233+
if out:
234+
try:
235+
return json.loads(out)
236+
except Exception as e:
237+
module.fail_json(
238+
msg="Failed to parse podman system info output: error: %s, output: %s err: %s" % (e, out, err),
239+
exception=str(e),
240+
)
241+
242+
243+
def main():
244+
module = AnsibleModule(
245+
argument_spec=dict(
246+
executable=dict(type="str", default="podman"),
247+
),
248+
supports_check_mode=True,
249+
)
250+
251+
executable = module.get_bin_path(module.params["executable"], required=True)
252+
253+
results = get_podman_system_info(module, executable)
254+
255+
results = dict(
256+
changed=False,
257+
podman_system_info=results,
258+
)
259+
260+
module.exit_json(**results)
261+
262+
263+
if __name__ == "__main__":
264+
main()
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
- name: Get Podman system info
2+
containers.podman.podman_system_info:
3+
executable: "{{ test_executable | default('podman') }}"
4+
register: podman_info
5+
6+
- name: Check results
7+
assert:
8+
that:
9+
- podman_info.podman_system_info | length > 0

0 commit comments

Comments
 (0)