summaryrefslogtreecommitdiffstats
path: root/ansible_collections/containers/podman/plugins/modules
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-26 04:06:02 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-26 04:06:02 +0000
commite3eb94c23206603103f3c4faec6c227f59a1544c (patch)
treef2639459807ba88f55fc9c54d745bd7075d7f15c /ansible_collections/containers/podman/plugins/modules
parentReleasing progress-linux version 9.4.0+dfsg-1~progress7.99u1. (diff)
downloadansible-e3eb94c23206603103f3c4faec6c227f59a1544c.tar.xz
ansible-e3eb94c23206603103f3c4faec6c227f59a1544c.zip
Merging upstream version 9.5.1+dfsg.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'ansible_collections/containers/podman/plugins/modules')
-rw-r--r--ansible_collections/containers/podman/plugins/modules/podman_container.py36
-rw-r--r--ansible_collections/containers/podman/plugins/modules/podman_container_exec.py14
-rw-r--r--ansible_collections/containers/podman/plugins/modules/podman_generate_systemd.py1
-rw-r--r--ansible_collections/containers/podman/plugins/modules/podman_image.py45
-rw-r--r--ansible_collections/containers/podman/plugins/modules/podman_image_info.py2
-rw-r--r--ansible_collections/containers/podman/plugins/modules/podman_login.py5
-rw-r--r--ansible_collections/containers/podman/plugins/modules/podman_network.py41
-rw-r--r--ansible_collections/containers/podman/plugins/modules/podman_play.py100
-rw-r--r--ansible_collections/containers/podman/plugins/modules/podman_pod.py33
-rw-r--r--ansible_collections/containers/podman/plugins/modules/podman_pod_info.py7
-rw-r--r--ansible_collections/containers/podman/plugins/modules/podman_volume.py45
11 files changed, 297 insertions, 32 deletions
diff --git a/ansible_collections/containers/podman/plugins/modules/podman_container.py b/ansible_collections/containers/podman/plugins/modules/podman_container.py
index 51cb57a53..75349f14e 100644
--- a/ansible_collections/containers/podman/plugins/modules/podman_container.py
+++ b/ansible_collections/containers/podman/plugins/modules/podman_container.py
@@ -55,6 +55,8 @@ options:
If container doesn't exist, the module creates it and leaves it in
'created' state. If configuration doesn't match or 'recreate' option is
set, the container will be recreated
+ - I(quadlet) - Write a quadlet file with the specified configuration.
+ Requires the C(quadlet_dir) option to be set.
type: str
default: started
choices:
@@ -63,6 +65,7 @@ options:
- stopped
- started
- created
+ - quadlet
image:
description:
- Repository path (or image name) and tag used to create the container.
@@ -721,6 +724,22 @@ options:
- Publish all exposed ports to random ports on the host interfaces. The
default is false.
type: bool
+ quadlet_dir:
+ description:
+ - Path to the directory to write quadlet file in.
+ By default, it will be set as C(/etc/containers/systemd/) for root user,
+ C(~/.config/containers/systemd/) for non-root users.
+ type: path
+ quadlet_filename:
+ description:
+ - Name of quadlet file to write. By default it takes C(name) value.
+ type: str
+ quadlet_options:
+ description:
+ - Options for the quadlet file. Provide missing in usual container args
+ options as a list of lines to add.
+ type: list
+ elements: str
read_only:
description:
- Mount the container's root filesystem as read only. Default is false
@@ -994,6 +1013,23 @@ EXAMPLES = r"""
- --deploy-hook
- "echo 1 > /var/lib/letsencrypt/complete"
+- name: Create a Quadlet file
+ containers.podman.podman_container:
+ name: quadlet-container
+ image: nginx
+ state: quadlet
+ quadlet_filename: custome-container
+ device: "/dev/sda:/dev/xvda:rwm"
+ ports:
+ - "8080:80"
+ volumes:
+ - "/var/www:/usr/share/nginx/html"
+ quadlet_options:
+ - "AutoUpdate=registry"
+ - "Pull=true"
+ - |
+ [Install]
+ WantedBy=default.target
"""
RETURN = r"""
diff --git a/ansible_collections/containers/podman/plugins/modules/podman_container_exec.py b/ansible_collections/containers/podman/plugins/modules/podman_container_exec.py
index d30e85cdb..1827b0ce7 100644
--- a/ansible_collections/containers/podman/plugins/modules/podman_container_exec.py
+++ b/ansible_collections/containers/podman/plugins/modules/podman_container_exec.py
@@ -40,6 +40,11 @@ options:
description:
- Set environment variables.
type: dict
+ executable:
+ description:
+ - The path to the podman executable.
+ type: str
+ default: podman
privileged:
description:
- Give extended privileges to the container.
@@ -141,6 +146,7 @@ def run_container_exec(module: AnsibleModule) -> dict:
tty = module.params['tty']
user = module.params['user']
workdir = module.params['workdir']
+ executable = module.params['executable']
if command is not None:
argv = shlex.split(command)
@@ -156,7 +162,7 @@ def run_container_exec(module: AnsibleModule) -> dict:
to_text(value, errors='surrogate_or_strict')
exec_options += ['--env',
- '%s="%s"' % (key, value)]
+ '%s=%s' % (key, value)]
if privileged:
exec_options.append('--privileged')
@@ -178,7 +184,7 @@ def run_container_exec(module: AnsibleModule) -> dict:
exec_with_args.extend(exec_options)
rc, stdout, stderr = run_podman_command(
- module=module, executable='podman', args=exec_with_args)
+ module=module, executable=executable, args=exec_with_args, ignore_errors=True)
result = {
'changed': changed,
@@ -211,6 +217,10 @@ def main():
'type': 'bool',
'default': False,
},
+ 'executable': {
+ 'type': 'str',
+ 'default': 'podman',
+ },
'env': {
'type': 'dict',
},
diff --git a/ansible_collections/containers/podman/plugins/modules/podman_generate_systemd.py b/ansible_collections/containers/podman/plugins/modules/podman_generate_systemd.py
index 486a18a86..b27c16c6e 100644
--- a/ansible_collections/containers/podman/plugins/modules/podman_generate_systemd.py
+++ b/ansible_collections/containers/podman/plugins/modules/podman_generate_systemd.py
@@ -183,6 +183,7 @@ EXAMPLES = '''
- name: Postgres container must be started and enabled on systemd
ansible.builtin.systemd:
name: container-postgres_local
+ scope: user
daemon_reload: true
state: started
enabled: true
diff --git a/ansible_collections/containers/podman/plugins/modules/podman_image.py b/ansible_collections/containers/podman/plugins/modules/podman_image.py
index 6305a5d5b..7fcb0041a 100644
--- a/ansible_collections/containers/podman/plugins/modules/podman_image.py
+++ b/ansible_collections/containers/podman/plugins/modules/podman_image.py
@@ -64,6 +64,7 @@ DOCUMENTATION = r'''
- present
- absent
- build
+ - quadlet
validate_certs:
description:
- Require HTTPS and validate certificates when pulling or pushing. Also used during build if a pull or push is necessary.
@@ -175,6 +176,24 @@ DOCUMENTATION = r'''
- docker-daemon
- oci-archive
- ostree
+ quadlet_dir:
+ description:
+ - Path to the directory to write quadlet file in.
+ By default, it will be set as C(/etc/containers/systemd/) for root user,
+ C(~/.config/containers/systemd/) for non-root users.
+ type: path
+ required: false
+ quadlet_filename:
+ description:
+ - Name of quadlet file to write. By default it takes image name without prefixes and tags.
+ type: str
+ quadlet_options:
+ description:
+ - Options for the quadlet file. Provide missing in usual network args
+ options as a list of lines to add.
+ type: list
+ elements: str
+ required: false
'''
EXAMPLES = r"""
@@ -280,6 +299,18 @@ EXAMPLES = r"""
containers.podman.podman_image:
name: nginx
arch: amd64
+
+- name: Create a quadlet file for an image
+ containers.podman.podman_image:
+ name: docker.io/library/alpine:latest
+ state: quadlet
+ quadlet_dir: /etc/containers/systemd
+ quadlet_filename: alpine-latest
+ quadlet_options:
+ - Variant=arm/v7
+ - |
+ [Install]
+ WantedBy=default.target
"""
RETURN = r"""
@@ -410,6 +441,7 @@ import shlex
from ansible.module_utils._text import to_native
from ansible.module_utils.basic import AnsibleModule
from ansible_collections.containers.podman.plugins.module_utils.podman.common import run_podman_command
+from ansible_collections.containers.podman.plugins.module_utils.podman.quadlet import create_quadlet_state
class PodmanImageManager(object):
@@ -451,6 +483,9 @@ class PodmanImageManager(object):
if self.state in ['absent']:
self.absent()
+ if self.state == 'quadlet':
+ self.make_quadlet()
+
def _run(self, args, expected_rc=0, ignore_errors=False):
cmd = " ".join([self.executable]
+ [to_native(i) for i in args])
@@ -537,6 +572,11 @@ class PodmanImageManager(object):
if not self.module.check_mode:
self.remove_image_id()
+ def make_quadlet(self):
+ results_update = create_quadlet_state(self.module, "image")
+ self.results.update(results_update)
+ self.module.exit_json(**self.results)
+
def find_image(self, image_name=None):
if image_name is None:
image_name = self.image_name
@@ -810,13 +850,16 @@ def main():
push=dict(type='bool', default=False),
path=dict(type='str'),
force=dict(type='bool', default=False),
- state=dict(type='str', default='present', choices=['absent', 'present', 'build']),
+ state=dict(type='str', default='present', choices=['absent', 'present', 'build', 'quadlet']),
validate_certs=dict(type='bool', aliases=['tlsverify', 'tls_verify']),
executable=dict(type='str', default='podman'),
auth_file=dict(type='path', aliases=['authfile']),
username=dict(type='str'),
password=dict(type='str', no_log=True),
ca_cert_dir=dict(type='path'),
+ quadlet_dir=dict(type='path', required=False),
+ quadlet_filename=dict(type='str'),
+ quadlet_options=dict(type='list', elements='str', required=False),
build=dict(
type='dict',
aliases=['build_args', 'buildargs'],
diff --git a/ansible_collections/containers/podman/plugins/modules/podman_image_info.py b/ansible_collections/containers/podman/plugins/modules/podman_image_info.py
index d8af08814..02b0f9ed1 100644
--- a/ansible_collections/containers/podman/plugins/modules/podman_image_info.py
+++ b/ansible_collections/containers/podman/plugins/modules/podman_image_info.py
@@ -48,7 +48,7 @@ RETURN = r"""
images:
description: info from all or specified images
returned: always
- type: dict
+ type: list
sample: [
{
"Annotations": {},
diff --git a/ansible_collections/containers/podman/plugins/modules/podman_login.py b/ansible_collections/containers/podman/plugins/modules/podman_login.py
index 8ae8418a9..25bdb8d99 100644
--- a/ansible_collections/containers/podman/plugins/modules/podman_login.py
+++ b/ansible_collections/containers/podman/plugins/modules/podman_login.py
@@ -154,10 +154,7 @@ def main():
supports_check_mode=True,
required_together=(
['username', 'password'],
- ),
- mutually_exclusive=(
- ['certdir', 'tlsverify'],
- ),
+ )
)
registry = module.params['registry']
diff --git a/ansible_collections/containers/podman/plugins/modules/podman_network.py b/ansible_collections/containers/podman/plugins/modules/podman_network.py
index 3f52af4ce..37bfefede 100644
--- a/ansible_collections/containers/podman/plugins/modules/podman_network.py
+++ b/ansible_collections/containers/podman/plugins/modules/podman_network.py
@@ -127,11 +127,30 @@ options:
choices:
- present
- absent
+ - quadlet
recreate:
description:
- Recreate network even if exists.
type: bool
default: false
+ quadlet_dir:
+ description:
+ - Path to the directory to write quadlet file in.
+ By default, it will be set as C(/etc/containers/systemd/) for root user,
+ C(~/.config/containers/systemd/) for non-root users.
+ type: path
+ required: false
+ quadlet_filename:
+ description:
+ - Name of quadlet file to write. By default it takes I(name) value.
+ type: str
+ quadlet_options:
+ description:
+ - Options for the quadlet file. Provide missing in usual network args
+ options as a list of lines to add.
+ type: list
+ elements: str
+ required: false
"""
EXAMPLES = r"""
@@ -148,6 +167,14 @@ EXAMPLES = r"""
subnet: 192.168.22.0/24
gateway: 192.168.22.1
become: true
+
+- name: Create Quadlet file for podman network
+ containers.podman.podman_network:
+ name: podman_network
+ state: quadlet
+ quadlet_options:
+ - IPv6=true
+ - Label="ipv6 network"
"""
RETURN = r"""
@@ -197,7 +224,7 @@ network:
]
"""
-import json # noqa: F402
+import json
try:
import ipaddress
HAS_IP_ADDRESS_MODULE = True
@@ -208,6 +235,7 @@ from ansible.module_utils.basic import AnsibleModule # noqa: F402
from ansible.module_utils._text import to_bytes, to_native # noqa: F402
from ansible_collections.containers.podman.plugins.module_utils.podman.common import LooseVersion
from ansible_collections.containers.podman.plugins.module_utils.podman.common import lower_keys
+from ansible_collections.containers.podman.plugins.module_utils.podman.quadlet import create_quadlet_state
class PodmanNetworkModuleParams:
@@ -620,6 +648,7 @@ class PodmanNetworkManager:
states_map = {
'present': self.make_present,
'absent': self.make_absent,
+ 'quadlet': self.make_quadlet,
}
process_action = states_map[self.state]
process_action()
@@ -652,12 +681,17 @@ class PodmanNetworkManager:
'podman_actions': self.network.actions})
self.module.exit_json(**self.results)
+ def make_quadlet(self):
+ results_update = create_quadlet_state(self.module, "network")
+ self.results.update(results_update)
+ self.module.exit_json(**self.results)
+
def main():
module = AnsibleModule(
argument_spec=dict(
state=dict(type='str', default="present",
- choices=['present', 'absent']),
+ choices=['present', 'absent', 'quadlet']),
name=dict(type='str', required=True),
disable_dns=dict(type='bool', required=False),
driver=dict(type='str', required=False),
@@ -681,6 +715,9 @@ def main():
executable=dict(type='str', required=False, default='podman'),
debug=dict(type='bool', default=False),
recreate=dict(type='bool', default=False),
+ quadlet_dir=dict(type='path', required=False),
+ quadlet_filename=dict(type='str', required=False),
+ quadlet_options=dict(type='list', elements='str', required=False),
),
required_by=dict( # for IP range and GW to set 'subnet' is required
ip_range=('subnet'),
diff --git a/ansible_collections/containers/podman/plugins/modules/podman_play.py b/ansible_collections/containers/podman/plugins/modules/podman_play.py
index 10a9a06fa..66138efc0 100644
--- a/ansible_collections/containers/podman/plugins/modules/podman_play.py
+++ b/ansible_collections/containers/podman/plugins/modules/podman_play.py
@@ -103,7 +103,8 @@ options:
required: false
tag:
description:
- - specify a custom log tag for the container. This option is currently supported only by the journald log driver in Podman.
+ - Specify a custom log tag for the container.
+ This option is currently supported only by the journald log driver in Podman.
type: str
required: false
log_level:
@@ -131,6 +132,7 @@ options:
- created
- started
- absent
+ - quadlet
required: True
tls_verify:
description:
@@ -158,6 +160,24 @@ options:
An empty value ("") means user namespaces are disabled.
required: false
type: str
+ quadlet_dir:
+ description:
+ - Path to the directory to write quadlet file in.
+ By default, it will be set as C(/etc/containers/systemd/) for root user,
+ C(~/.config/containers/systemd/) for non-root users.
+ type: path
+ required: false
+ quadlet_filename:
+ description:
+ - Name of quadlet file to write. Must be specified if state is quadlet.
+ type: str
+ quadlet_options:
+ description:
+ - Options for the quadlet file. Provide missing in usual network args
+ options as a list of lines to add.
+ type: list
+ elements: str
+ required: false
'''
EXAMPLES = '''
@@ -178,6 +198,19 @@ EXAMPLES = '''
log_opt:
path: /tmp/my-container.log
max_size: 10mb
+
+- name: Create a Quadlet file
+ containers.podman.podman_play:
+ kube_file: ~/kube.yaml
+ state: quadlet
+ annotations:
+ greeting: hello
+ greet_to: world
+ userns: host
+ quadlet_filename: kube-pod
+ quadlet_options:
+ - "SetWorkingDirectory=yaml"
+ - "ExitCodePropagation=any"
'''
import re # noqa: F402
try:
@@ -187,6 +220,8 @@ except ImportError:
HAS_YAML = False
from ansible.module_utils.basic import AnsibleModule # noqa: F402
+from ansible_collections.containers.podman.plugins.module_utils.podman.common import LooseVersion, get_podman_version
+from ansible_collections.containers.podman.plugins.module_utils.podman.quadlet import create_quadlet_state # noqa: F402
class PodmanKubeManagement:
@@ -196,11 +231,12 @@ class PodmanKubeManagement:
self.actions = []
self.executable = executable
self.command = [self.executable, 'play', 'kube']
+ self.version = get_podman_version(module)
creds = []
# pod_name = extract_pod_name(module.params['kube_file'])
if self.module.params['annotation']:
for k, v in self.module.params['annotation'].items():
- self.command.extend(['--annotation', '"{k}={v}"'.format(k=k, v=v)])
+ self.command.extend(['--annotation', '{k}={v}'.format(k=k, v=v)])
if self.module.params['username']:
creds += [self.module.params['username']]
if self.module.params['password']:
@@ -244,17 +280,31 @@ class PodmanKubeManagement:
self.module.log('PODMAN-PLAY-KUBE rc: %s' % rc)
return rc, out, err
+ def tear_down_pods(self):
+ '''
+ Tear down the pod and contaiers by using --down option in kube play
+ which is supported since Podman 3.4.0
+ '''
+ changed = False
+ kube_file = self.module.params['kube_file']
+
+ rc, out, err = self._command_run([self.executable, "kube", "play", "--down", kube_file])
+ if rc != 0:
+ self.module.fail_json(msg="Failed to delete Pod with %s" % (kube_file))
+ else:
+ changed = True
+
+ return changed, out, err
+
def discover_pods(self):
pod_name = ''
if self.module.params['kube_file']:
if HAS_YAML:
with open(self.module.params['kube_file']) as f:
- pod = yaml.safe_load(f)
- if 'metadata' in pod:
- pod_name = pod['metadata'].get('name')
- else:
- self.module.fail_json(
- "No metadata in Kube file!\n%s" % pod)
+ pods = list(yaml.safe_load_all(f))
+ for pod in pods:
+ if 'metadata' in pod and pod['kind'] in ['Deployment', 'Pod']:
+ pod_name = pod['metadata'].get('name')
else:
with open(self.module.params['kube_file']) as text:
# the following formats are matched for a kube name:
@@ -266,7 +316,7 @@ class PodmanKubeManagement:
if re_pod:
pod_name = re_pod.group(1)
if not pod_name:
- self.module.fail_json("Deployment doesn't have a name!")
+ self.module.fail_json("This Kube file doesn't have Pod or Deployment!")
# Find all pods
all_pods = ''
# In case of one pod or replicasets
@@ -294,8 +344,12 @@ class PodmanKubeManagement:
return changed, out_all, err_all
def pod_recreate(self):
- pods = self.discover_pods()
- self.remove_associated_pods(pods)
+ if self.version is not None and LooseVersion(self.version) >= LooseVersion('3.4.0'):
+ self.tear_down_pods()
+ else:
+ pods = self.discover_pods()
+ self.remove_associated_pods(pods)
+
# Create a pod
rc, out, err = self._command_run(self.command)
if rc != 0:
@@ -318,6 +372,12 @@ class PodmanKubeManagement:
changed = True
return changed, out, err
+ def make_quadlet(self):
+ results = {"changed": False}
+ results_update = create_quadlet_state(self.module, "kube")
+ results.update(results_update)
+ self.module.exit_json(**results)
+
def main():
module = AnsibleModule(
@@ -341,7 +401,7 @@ def main():
network=dict(type='list', elements='str'),
state=dict(
type='str',
- choices=['started', 'created', 'absent'],
+ choices=['started', 'created', 'absent', 'quadlet'],
required=True),
tls_verify=dict(type='bool'),
debug=dict(type='bool'),
@@ -351,16 +411,28 @@ def main():
log_level=dict(
type='str',
choices=["debug", "info", "warn", "error", "fatal", "panic"]),
+ quadlet_dir=dict(type='path', required=False),
+ quadlet_filename=dict(type='str', required=False),
+ quadlet_options=dict(type='list', elements='str', required=False),
),
supports_check_mode=True,
+ required_if=[
+ ('state', 'quadlet', ['quadlet_filename']),
+ ],
)
executable = module.get_bin_path(
module.params['executable'], required=True)
manage = PodmanKubeManagement(module, executable)
if module.params['state'] == 'absent':
- pods = manage.discover_pods()
- changed, out, err = manage.remove_associated_pods(pods)
+ if manage.version is not None and LooseVersion(manage.version) > LooseVersion('3.4.0'):
+ manage.module.log(msg="version: %s, kube file %s" % (manage.version, manage.module.params['kube_file']))
+ changed, out, err = manage.tear_down_pods()
+ else:
+ pods = manage.discover_pods()
+ changed, out, err = manage.remove_associated_pods(pods)
+ elif module.params['state'] == 'quadlet':
+ manage.make_quadlet()
else:
changed, out, err = manage.play()
results = {
diff --git a/ansible_collections/containers/podman/plugins/modules/podman_pod.py b/ansible_collections/containers/podman/plugins/modules/podman_pod.py
index 7b57fd302..a975921ea 100644
--- a/ansible_collections/containers/podman/plugins/modules/podman_pod.py
+++ b/ansible_collections/containers/podman/plugins/modules/podman_pod.py
@@ -30,6 +30,7 @@ options:
- stopped
- paused
- unpaused
+ - quadlet
recreate:
description:
- Use with present and started states to force the re-creation of an
@@ -340,6 +341,22 @@ options:
required: false
aliases:
- ports
+ quadlet_dir:
+ description:
+ - Path to the directory to write quadlet file in.
+ By default, it will be set as C(/etc/containers/systemd/) for root user,
+ C(~/.config/containers/systemd/) for non-root users.
+ type: path
+ quadlet_filename:
+ description:
+ - Name of quadlet file to write. By default it takes I(name) value.
+ type: str
+ quadlet_options:
+ description:
+ - Options for the quadlet file. Provide missing in usual container args
+ options as a list of lines to add.
+ type: list
+ elements: str
share:
description:
- A comma delimited list of kernel namespaces to share. If none or "" is specified,
@@ -435,7 +452,7 @@ pod:
EXAMPLES = '''
# What modules does for example
-- podman_pod:
+- containers.podman.podman_pod:
name: pod1
state: started
ports:
@@ -447,6 +464,16 @@ EXAMPLES = '''
name: pod2
state: started
publish: "127.0.0.1::80"
+
+# Create a Quadlet file for a pod
+- containers.podman.podman_pod:
+ name: qpod
+ state: quadlet
+ ports:
+ - "4444:5555"
+ volume:
+ - /var/run/docker.sock:/var/run/docker.sock
+ quadlet_dir: /custom/dir
'''
from ansible.module_utils.basic import AnsibleModule # noqa: F402
from ..module_utils.podman.podman_pod_lib import PodmanPodManager # noqa: F402
@@ -454,9 +481,7 @@ from ..module_utils.podman.podman_pod_lib import ARGUMENTS_SPEC_POD # noqa: F40
def main():
- module = AnsibleModule(
- argument_spec=ARGUMENTS_SPEC_POD
- )
+ module = AnsibleModule(argument_spec=ARGUMENTS_SPEC_POD)
results = PodmanPodManager(module, module.params).execute()
module.exit_json(**results)
diff --git a/ansible_collections/containers/podman/plugins/modules/podman_pod_info.py b/ansible_collections/containers/podman/plugins/modules/podman_pod_info.py
index 8b2a4bf06..8597ae98d 100644
--- a/ansible_collections/containers/podman/plugins/modules/podman_pod_info.py
+++ b/ansible_collections/containers/podman/plugins/modules/podman_pod_info.py
@@ -109,9 +109,12 @@ def get_pod_info(module, executable, name):
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):
+ data = json.loads(out) if out else None
+ if isinstance(data, list) and data:
+ data = data[0]
+ if not out or data is None or not data:
continue
- result.append(json.loads(out))
+ result.append(data)
return result, errs, rcs
diff --git a/ansible_collections/containers/podman/plugins/modules/podman_volume.py b/ansible_collections/containers/podman/plugins/modules/podman_volume.py
index b4d5062fa..0b990354a 100644
--- a/ansible_collections/containers/podman/plugins/modules/podman_volume.py
+++ b/ansible_collections/containers/podman/plugins/modules/podman_volume.py
@@ -24,6 +24,7 @@ options:
choices:
- present
- absent
+ - quadlet
recreate:
description:
- Recreate volume even if exists.
@@ -62,6 +63,24 @@ options:
- Return additional information which can be helpful for investigations.
type: bool
default: False
+ quadlet_dir:
+ description:
+ - Path to the directory to write quadlet file in.
+ By default, it will be set as C(/etc/containers/systemd/) for root user,
+ C(~/.config/containers/systemd/) for non-root users.
+ type: path
+ required: false
+ quadlet_filename:
+ description:
+ - Name of quadlet file to write. By default it takes I(name) value.
+ type: str
+ quadlet_options:
+ description:
+ - Options for the quadlet file. Provide missing in usual network args
+ options as a list of lines to add.
+ type: list
+ elements: str
+ required: false
requirements:
- "podman"
@@ -88,7 +107,8 @@ volume:
EXAMPLES = '''
# What modules does for example
-- podman_volume:
+- name: Create a volume
+ containers.podman.podman_volume:
state: present
name: volume1
label:
@@ -97,6 +117,17 @@ EXAMPLES = '''
options:
- "device=/dev/loop1"
- "type=ext4"
+
+- name: Create a Quadlet file for a volume
+ containers.podman.podman_volume:
+ state: quadlet
+ name: quadlet_volume
+ quadlet_filename: custom-name
+ quadlet_options:
+ - Group=192
+ - Copy=true
+ - Image=quay.io/centos/centos:latest
+
'''
# noqa: F402
import json # noqa: F402
@@ -105,6 +136,7 @@ from ansible.module_utils.basic import AnsibleModule # noqa: F402
from ansible.module_utils._text import to_bytes, to_native # noqa: F402
from ansible_collections.containers.podman.plugins.module_utils.podman.common import LooseVersion
from ansible_collections.containers.podman.plugins.module_utils.podman.common import lower_keys
+from ansible_collections.containers.podman.plugins.module_utils.podman.quadlet import create_quadlet_state
class PodmanVolumeModuleParams:
@@ -436,6 +468,7 @@ class PodmanVolumeManager:
states_map = {
'present': self.make_present,
'absent': self.make_absent,
+ 'quadlet': self.make_quadlet,
}
process_action = states_map[self.state]
process_action()
@@ -468,12 +501,17 @@ class PodmanVolumeManager:
'podman_actions': self.volume.actions})
self.module.exit_json(**self.results)
+ def make_quadlet(self):
+ results_update = create_quadlet_state(self.module, "volume")
+ self.results.update(results_update)
+ self.module.exit_json(**self.results)
+
def main():
module = AnsibleModule(
argument_spec=dict(
state=dict(type='str', default="present",
- choices=['present', 'absent']),
+ choices=['present', 'absent', 'quadlet']),
name=dict(type='str', required=True),
label=dict(type='dict', required=False),
driver=dict(type='str', required=False),
@@ -481,6 +519,9 @@ def main():
recreate=dict(type='bool', default=False),
executable=dict(type='str', required=False, default='podman'),
debug=dict(type='bool', default=False),
+ quadlet_dir=dict(type='path', required=False),
+ quadlet_filename=dict(type='str', required=False),
+ quadlet_options=dict(type='list', elements='str', required=False),
))
PodmanVolumeManager(module).execute()