Server IP : 85.214.239.14 / Your IP : 3.149.255.21 Web Server : Apache/2.4.62 (Debian) System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Mon Sep 30 15:36:27 MSK 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.18 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /lib/python3/dist-packages/ansible_collections/containers/podman/plugins/modules/ |
Upload File : |
#!/usr/bin/python # Copyright (c) 2020 Red Hat # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import absolute_import, division, print_function __metaclass__ = type DOCUMENTATION = r""" module: podman_pod_info author: - "Sagi Shnaidman (@sshnaidm)" version_added: '1.0.0' short_description: Gather info about podman pods notes: [] description: - Gather info about podman pods with podman inspect command. requirements: - "Podman installed on host" options: name: description: - Name of the pod type: str executable: description: - Path to C(podman) executable if it is not in the C($PATH) on the machine running C(podman) default: 'podman' type: str """ EXAMPLES = r""" - name: Gather info about all present pods containers.podman.podman_pod_info: - name: Gather info about specific pods containers.podman.podman_pod_info: name: special_pod """ RETURN = r""" pods: description: Facts from all or specified pods returned: always type: list sample: [ { "Config": { "id": "d9cb6dbb0....", "name": "pod1", "hostname": "pod1host", "labels": { }, "cgroupParent": "/libpod_parent", "sharesCgroup": true, "sharesIpc": true, "sharesNet": true, "sharesUts": true, "infraConfig": { "makeInfraContainer": true, "infraPortBindings": [ { "hostPort": 7777, "containerPort": 7111, "protocol": "tcp", "hostIP": "" } ] }, "created": "2020-07-13T20:29:12.572282186+03:00", "lockID": 682 }, "State": { "cgroupPath": "/libpod_parent/d9cb6dbb0....", "infraContainerID": "ad46737bf....", "status": "Created" }, "Containers": [ { "id": "ad46737bf....", "state": "configured" } ] } ] """ import json from ansible.module_utils.basic import AnsibleModule def get_pod_info(module, executable, name): command = [executable, 'pod', 'inspect'] pods = [name] result = [] errs = [] rcs = [] if not name: all_names = [executable, 'pod', 'ls', '-q'] rc, out, err = module.run_command(all_names) if rc != 0: module.fail_json(msg="Unable to get list of pods: %s" % err) name = out.split() if not name: return [], [err], [rc] pods = name for pod in pods: rc, out, err = module.run_command(command + [pod]) errs.append(err.strip()) rcs += [rc] if not out or json.loads(out) is None or not json.loads(out): continue result.append(json.loads(out)) return result, errs, rcs def main(): module = AnsibleModule( argument_spec=dict( executable=dict(type='str', default='podman'), name=dict(type='str') ), supports_check_mode=True, ) name = module.params['name'] executable = module.get_bin_path(module.params['executable'], required=True) inspect_results, errs, rcs = get_pod_info(module, executable, name) if len(rcs) > 1 and 0 not in rcs: module.fail_json(msg="Failed to inspect pods", stderr="\n".join(errs)) results = { "changed": False, "pods": inspect_results, "stderr": "\n".join(errs), } module.exit_json(**results) if __name__ == '__main__': main()