Debian Codegraph @

ansible_collections/containers/podman/plugins/modules/podman_runlabel.py

raw
1 #!/usr/bin/python
2 # coding: utf-8 -*-
3
4 # Copyright (c) 2023, Pavel Dostal <@pdostal>
5 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6 from __future__ import absolute_import, division, print_function
7
8 __metaclass__ = type
9
10 DOCUMENTATION = r"""
11 module: podman_runlabel
12 short_description: Run given label from given image
13 author: Pavel Dostal (@pdostal)
14 description:
15 - podman container runlabel runs selected label from given image
16 options:
17 image:
18 description:
19 - Image to get the label from.
20 type: str
21 required: true
22 label:
23 description:
24 - Label to run.
25 type: str
26 required: true
27 executable:
28 description:
29 - Path to C(podman) executable if it is not in the C($PATH) on the
30 machine running C(podman)
31 default: 'podman'
32 type: str
33 requirements:
34 - "Podman installed on host"
35 """
36
37 RETURN = """
38 """
39
40 EXAMPLES = """
41 # What modules does for example
42 - containers.podman.podman_runlabel:
43 image: docker.io/continuumio/miniconda3
44 label: INSTALL
45 """
46
47 from ansible.module_utils.basic import AnsibleModule # noqa: E402
48
49
50 def runlabel(module, executable):
51 changed = False
52 command = [executable, "container", "runlabel"]
53 command.append(module.params["label"])
54 command.append(module.params["image"])
55 rc, out, err = module.run_command(command)
56 if rc == 0:
57 changed = True
58 else:
59 module.fail_json(msg="Error running the runlabel from image %s: %s" % (module.params["image"], err))
60 return changed, out, err
61
62
63 def main():
64 module = AnsibleModule(
65 argument_spec=dict(
66 image=dict(type="str", required=True),
67 label=dict(type="str", required=True),
68 executable=dict(type="str", default="podman"),
69 ),
70 supports_check_mode=False,
71 )
72
73 executable = module.get_bin_path(module.params["executable"], required=True)
74 changed, out, err = runlabel(module, executable)
75
76 results = {"changed": changed, "stdout": out, "stderr": err}
77 module.exit_json(**results)
78
79
80 if __name__ == "__main__":
81 main()