|
| 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() |
0 commit comments