1
0
Fork 0
mirror of https://github.com/containers/ansible-podman-collections.git synced 2026-02-04 07:11:49 +00:00
This commit is contained in:
Sergey 2025-08-24 14:56:59 +00:00 committed by GitHub
commit e996e38130
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
26 changed files with 1369 additions and 103 deletions

View file

@ -0,0 +1,121 @@
name: Podman API container
on:
push:
paths:
- '.github/workflows/podman_container_api.yml'
- 'ci/*.yml'
- 'ci/run_containers_tests.sh'
- 'ci/playbooks/containers/podman_container_api.yml'
#- 'plugins/modules/podman_container.py'
- 'plugins/module_utils/podman/podman_container_lib.py'
- 'plugins/module_utils/podman/podman_api.py'
- 'plugins/module_utils/podman/common.py'
- 'tests/integration/targets/podman_container_api/**'
branches:
- master
pull_request:
paths:
- '.github/workflows/podman_container_api.yml'
- 'ci/*.yml'
- 'ci/run_containers_tests.sh'
- 'ci/playbooks/containers/podman_container_api.yml'
#- 'plugins/modules/podman_container.py'
- 'plugins/module_utils/podman/podman_container_lib.py'
- 'plugins/module_utils/podman/podman_api.py'
- 'plugins/module_utils/podman/common.py'
- 'tests/integration/targets/podman_container_api/**'
schedule:
- cron: 4 0 * * * # Run daily at 0:03 UTC
jobs:
test_podman_container_api:
name: Podman API container ${{ matrix.ansible-version }}-${{ matrix.os || 'ubuntu-22.04' }}-${{ matrix.podman-version || 'unstable' }}
runs-on: ${{ matrix.os || 'ubuntu-22.04' }}
defaults:
run:
shell: bash
strategy:
fail-fast: false
matrix:
ansible-version:
# - git+https://github.com/ansible/ansible.git@stable-2.18
- git+https://github.com/ansible/ansible.git@devel
os:
- ubuntu-22.04
python-version:
- "3.12"
podman-version:
- unstable
steps:
- name: Check out repository
uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Upgrade pip and display Python and PIP versions
run: |
sudo apt-get update
sudo apt-get install -y python*-wheel python*-yaml
python -m pip install --upgrade pip
python -V
pip --version
- name: Set up pip cache
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ github.ref }}-units-VMs
restore-keys: |
${{ runner.os }}-pip-
${{ runner.os }}-
- name: Install Ansible ${{ matrix.ansible-version }}
run: python3 -m pip install --user --force-reinstall --upgrade '${{ matrix.ansible-version }}'
- name: Build and install the collection tarball
run: |
export PATH=~/.local/bin:$PATH
echo "Run ansible version"
command -v ansible
ansible --version
rm -rf /tmp/just_new_collection
~/.local/bin/ansible-galaxy collection build --output-path /tmp/just_new_collection --force
~/.local/bin/ansible-galaxy collection install -vvv --force /tmp/just_new_collection/*.tar.gz
- name: Run collection tests for podman container API
run: |
export PATH=~/.local/bin:$PATH
if [[ '${{ matrix.ansible-version }}' == 'git+https://github.com/ansible/ansible.git@devel' ]]; then
export ANSIBLE_CONFIG=$(pwd)/ci/ansible-dev.cfg
elif [[ '${{ matrix.ansible-version }}' == 'ansible<2.10' ]]; then
export ANSIBLE_CONFIG=$(pwd)/ci/ansible-2.9.cfg
fi
python3 -m pip install --user -r requirements.txt
podman system service --time=0 unix:///tmp/podman.sock &
sudo podman system service --time=0 unix:///tmp/root-podman.sock &
podman system service --time=0 tcp:localhost:25771 &
echo $ANSIBLE_CONFIG
command -v ansible-playbook
pip --version
python --version
ansible-playbook --version
ansible-playbook -vv ci/playbooks/pre.yml \
-e host=localhost \
-i localhost, \
-e ansible_connection=local \
-e setup_python=false \
-e podman_version_ubuntu=${{ matrix.podman-version }}
TEST2RUN=podman_container_api ./ci/run_containers_tests.sh
shell: bash

View file

@ -0,0 +1,12 @@
---
- hosts: all
gather_facts: true
module_defaults:
containers.podman.podman_container:
podman_socket: unix:///tmp/podman.sock
tasks:
- include_role:
name: podman_container_api
vars:
idem_image: idempotency_test
ansible_python_interpreter: "{{ _ansible_python_interpreter }}"

View file

@ -25,6 +25,14 @@ except ImportError:
),
exc,
)
try:
import requests # pylint: disable=unused-import
from .podman_api import PodmanAPIClient
HAS_REQUESTS = True
except ImportError:
PodmanAPIClient = object
HAS_REQUESTS = False
ARGUMENTS_OPTS_DICT = {
"--attach": ["--attach", "-a"],
@ -378,8 +386,8 @@ def createcommand(argument, info_config, boolean_type=False):
all_values = []
# Remove command args from the list
container_cmd = info_config.get("cmd")
if container_cmd and container_cmd == cr_com[-len(container_cmd):]:
cr_com = cr_com[:-len(container_cmd)]
if container_cmd and container_cmd == cr_com[-len(container_cmd) :]:
cr_com = cr_com[: -len(container_cmd)]
for arg in argument_values:
for ind, cr_opt in enumerate(cr_com):
if arg == cr_opt:
@ -450,3 +458,14 @@ def diff_generic(params, info_config, module_arg, cmd_arg, boolean_type=False):
else:
before = ",".join(sorted(before)) if len(before) > 1 else before[0]
return before, after
class PodmanAPI:
def __init__(self, module, module_params):
if module_params.get("podman_socket") and not HAS_REQUESTS:
module.fail_json(msg="Requests module is not installed while socket was provided!")
self.client = PodmanAPIClient(module_params.get("podman_socket"))
try:
self.client.version()
except Exception as api_error:
module.fail_json(msg="Podman API error: %s" % str(api_error))

View file

@ -0,0 +1,303 @@
# The follwing code is taken from
# https://github.com/msabramo/requests-unixsocket/blob/master/
# requests_unixsocket/adapters.py
from __future__ import absolute_import, division, print_function
import socket
try:
import requests
from requests.adapters import HTTPAdapter
from requests.compat import urlparse, unquote, quote
HAS_REQUESTS = True
except ImportError:
HAS_REQUESTS = False
# Try to use requests-unixsocket if available, as it handles compatibility issues
try:
import requests_unixsocket
HAS_REQUESTS_UNIXSOCKET = True
except ImportError:
HAS_REQUESTS_UNIXSOCKET = False
try:
from requests.packages import urllib3
HAS_URLLIB3 = True
except ImportError:
try:
import urllib3
HAS_URLLIB3 = True
except ImportError:
HAS_URLLIB3 = False
try:
import http.client as httplib
except ImportError:
import httplib
import json
__metaclass__ = type
DEFAULT_SCHEME = "http+unix://"
class PodmanAPIError(Exception):
pass
# The following was adapted from some code from docker-py
# https://github.com/docker/docker-py/blob/master/docker/transport/unixconn.py
class UnixHTTPConnection(httplib.HTTPConnection, object):
def __init__(self, unix_socket_url, timeout=60):
"""Create an HTTP connection to a unix domain socket
:param unix_socket_url: A URL with a scheme of 'http+unix' and the
netloc is a percent-encoded path to a unix domain socket. E.g.:
'http+unix://%2Ftmp%2Fprofilesvc.sock/status/pid'
"""
super(UnixHTTPConnection, self).__init__("localhost", timeout=timeout)
self.unix_socket_url = unix_socket_url
self.timeout = timeout
self.sock = None
def __del__(self): # base class does not have d'tor
if self.sock:
self.sock.close()
def connect(self):
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
sock.settimeout(self.timeout)
socket_path = unquote(urlparse(self.unix_socket_url).netloc)
sock.connect(socket_path)
self.sock = sock
if HAS_URLLIB3:
class UnixHTTPConnectionPool(urllib3.connectionpool.HTTPConnectionPool):
def __init__(self, socket_path, timeout=60):
super(UnixHTTPConnectionPool, self).__init__("localhost", timeout=timeout)
self.socket_path = socket_path
self.timeout = timeout
def _new_conn(self):
return UnixHTTPConnection(self.socket_path, self.timeout)
if HAS_REQUESTS:
class UnixAdapter(HTTPAdapter):
def __init__(self, *args, timeout=60, pool_connections=25, **kwargs):
super(UnixAdapter, self).__init__(*args, **kwargs)
self.timeout = timeout
self.pools = urllib3._collections.RecentlyUsedContainer(pool_connections, dispose_func=lambda p: p.close())
def get_connection_with_tls_context(self, request, verify, proxies=None, cert=None):
# Fix for requests 2.32.2+:
# https://github.com/psf/requests/commit/c98e4d133ef29c46a9b68cd783087218a8075e05
return self.get_connection(request.url, proxies)
def get_connection(self, url, proxies=None):
proxies = proxies or {}
proxy = proxies.get(urlparse(url.lower()).scheme)
if proxy:
raise ValueError("%s does not support specifying proxies" % self.__class__.__name__)
with self.pools.lock:
pool = self.pools.get(url)
if pool:
return pool
pool = UnixHTTPConnectionPool(url, self.timeout)
self.pools[url] = pool
return pool
def request_url(self, request, proxies):
return request.path_url
def close(self):
self.pools.clear()
if HAS_REQUESTS:
class APISession(requests.Session):
def __init__(self, *args, url_scheme=DEFAULT_SCHEME, **kwargs):
super(APISession, self).__init__(*args, **kwargs)
if HAS_REQUESTS_UNIXSOCKET and url_scheme == DEFAULT_SCHEME:
# Use requests-unixsocket which handles newer requests versions
self.mount("http+unix://", requests_unixsocket.adapters.UnixAdapter())
else:
# Fallback to custom implementation
self.mount(url_scheme, UnixAdapter())
# Also mount the scheme without the '+' for new requests versions
if url_scheme == DEFAULT_SCHEME:
self.mount("http+unix://", UnixAdapter())
class PodmanAPIHTTP:
def __init__(self, base_url, scheme=DEFAULT_SCHEME):
self.api_url = "".join((scheme, quote(base_url, safe=""), "/v5.0.0/libpod"))
if scheme == "http://":
self.api_url = "".join((scheme, base_url, "/v5.0.0/libpod"))
self.session = APISession()
def request(self, method, url, **kwargs):
return self.session.request(method=method, url=self.api_url + url, **kwargs)
def get(self, url, **kwargs):
kwargs.setdefault("allow_redirects", True)
return self.request("get", url, **kwargs)
def head(self, url, **kwargs):
kwargs.setdefault("allow_redirects", False)
return self.request("head", url, **kwargs)
def post(self, url, data=None, json=None, **kwargs):
return self.request("post", url, data=data, json=json, **kwargs)
def patch(self, url, data=None, **kwargs):
return self.request("patch", url, data=data, **kwargs)
def put(self, url, data=None, **kwargs):
return self.request("put", url, data=data, **kwargs)
def delete(self, url, **kwargs):
return self.request("delete", url, **kwargs)
def options(self, url, **kwargs):
kwargs.setdefault("allow_redirects", True)
return self.request("options", url, **kwargs)
class PodmanAPIClient:
def __init__(self, base_url):
if not HAS_REQUESTS:
raise PodmanAPIError("requests package is required for podman API")
socket_opt = urlparse(base_url)
if socket_opt.scheme not in ("unix", "http"):
raise PodmanAPIError("Scheme %s is not supported! Use %s" % (socket_opt.scheme, DEFAULT_SCHEME))
if socket_opt.scheme == "http":
self.api = PodmanAPIHTTP(socket_opt.netloc, "http://")
else:
self.api = PodmanAPIHTTP(socket_opt.path)
self.containers = PodmanAPIContainers(self.api)
self.images = PodmanAPIImages(api=self.api)
def version(self):
response = self.api.get("/version")
return response.json()
class PodmanAPIContainers:
def __init__(self, api):
self.api = api
self.quote = quote
def list(self, all_=None, filters=None, limit=None, size=None, sync=None):
"""List all images for a Podman service."""
query = {}
if all_ is not None:
query["all"] = True
if filters is not None:
query["filters"] = filters
if limit is not None:
query["limit"] = limit
if size is not None:
query["size"] = size
if sync is not None:
query["sync"] = sync
response = self.api.get("/containers/json", params=query)
# observed to return None when no containers
return response.json() or []
def create(self, **container_data):
response = self.api.post(
"/containers/create",
json=container_data,
)
if response.ok:
return response.json()
raise PodmanAPIError("Container %s failed to create! Error: %s" % (container_data.get("name"), response.text))
def get(self, name):
response = self.api.get("/containers/{0}/json".format(self.quote(name)))
data = response.json()
if data.get("response") == 404:
data = {}
# raise Exception("Container %s not found!" % name)
return data
def run(self, **container_data):
_ = self.create(**container_data) # pylint: disable=blacklisted-name
name = container_data.get("name")
_ = self.api.post( # pylint: disable=blacklisted-name
"/containers/{0}/start".format(self.quote(name)),
)
return self.get(name)
def start(self, name):
_ = self.api.post( # pylint: disable=blacklisted-name
"/containers/{0}/start".format(self.quote(name)),
)
return self.get(name)
def stop(self, name):
_ = self.api.post( # pylint: disable=blacklisted-name
"/containers/{0}/stop".format(self.quote(name)),
)
return self.get(name)
def restart(self, name):
_ = self.api.post( # pylint: disable=blacklisted-name
"/containers/{0}/restart".format(self.quote(name)),
)
return self.get(name)
def remove(self, name, force=False):
_ = self.api.delete( # pylint: disable=blacklisted-name
"/containers/{0}".format(self.quote(name)), params={"force": force}
)
return
class PodmanAPIImages:
def __init__(self, api):
self.api = api
self.quote = quote
self.inspect = self.get
def exists(self, name):
response = self.api.get("/images/{0}/exists".format(self.quote(name)))
return response.status_code == 204
def pull(self, reference):
response = self.api.post("/images/pull", params={"reference": reference})
if response.ok:
correct_response = {"stream": "", "text": response.text}
for i in response.text.splitlines():
if '"images"' in i:
correct_response["images"] = json.loads(i)["images"]
if '"id"' in i:
correct_response["id"] = json.loads(i)["id"]
elif '"stream"' in i:
correct_response["stream"] += json.loads(i)["stream"]
elif '"error"' in i:
correct_response["error"] = json.loads(i)["error"]
correct_response["code"] = response.status_code
return correct_response
return {"error": "HTTP %s Error: %s" % (response.json()["message"])}
def get(self, name):
response = self.api.get("/images/{0}/json".format(self.quote(name)))
return response.json()

View file

@ -2,43 +2,28 @@ from __future__ import absolute_import, division, print_function
import json # noqa: F402
import os # noqa: F402
import shlex # noqa: F402
import time
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.common import (
generate_systemd,
)
from ansible_collections.containers.podman.plugins.module_utils.podman.common import (
delete_systemd,
)
from ansible_collections.containers.podman.plugins.module_utils.podman.common import (
diff_generic,
)
from ansible_collections.containers.podman.plugins.module_utils.podman.common import (
createcommand,
)
from ansible_collections.containers.podman.plugins.module_utils.podman.quadlet import (
create_quadlet_state,
)
from ansible_collections.containers.podman.plugins.module_utils.podman.quadlet import (
ContainerQuadlet,
)
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.common import generate_systemd
from ansible_collections.containers.podman.plugins.module_utils.podman.common import delete_systemd
from ansible_collections.containers.podman.plugins.module_utils.podman.common import diff_generic
from ansible_collections.containers.podman.plugins.module_utils.podman.common import createcommand
from ansible_collections.containers.podman.plugins.module_utils.podman.quadlet import create_quadlet_state
from ansible_collections.containers.podman.plugins.module_utils.podman.quadlet import ContainerQuadlet
from .common import PodmanAPI
__metaclass__ = type
USE_API = False
ARGUMENTS_SPEC_CONTAINER = dict(
name=dict(required=True, type="str"),
executable=dict(default="podman", type="str"),
podman_socket=dict(type="str"),
state=dict(
type="str",
default="started",
choices=["absent", "present", "stopped", "started", "created", "quadlet"],
type="str", default="started", choices=["absent", "present", "stopped", "started", "created", "quadlet"]
),
image=dict(type="str"),
annotation=dict(type="dict"),
@ -107,9 +92,7 @@ ARGUMENTS_SPEC_CONTAINER = dict(
health_startup_timeout=dict(type="str"),
healthcheck_timeout=dict(type="str", aliases=["health_timeout"]),
healthcheck_failure_action=dict(
type="str",
choices=["none", "kill", "restart", "stop"],
aliases=["health_on_failure"],
type="str", choices=["none", "kill", "restart", "stop"], aliases=["health_on_failure"]
),
hooks_dir=dict(type="list", elements="str"),
hostname=dict(type="str"),
@ -210,6 +193,48 @@ ARGUMENTS_SPEC_CONTAINER = dict(
volumes_from=dict(type="list", elements="str"),
workdir=dict(type="str", aliases=["working_dir"]),
)
NON_PODMAN_ARGS = ["state", "podman_socket", "executable", "debug", "force_restart", "image_strict", "recreate"]
API_TRANSLATION = {
"annotation": "annotations",
"conmon_pidfile": "conmon_pid_file",
"etc_hosts": "hostadd",
"add_hosts": "hostadd",
"http_proxy": "httpproxy",
"label": "labels",
"publish_all": "publish_image_ports",
"rm": "remove",
"auto_remove": "remove",
"volume": "volumes",
"mount": "mounts",
"workdir": "work_dir",
"working_dir": "work_dir",
"dns_search_domains": "dns_search",
"dns": "dns_server",
"dns_opts": "dns_option",
"publish": "portmappings",
"published": "portmappings",
"published_ports": "portmappings",
"ports": "portmappings",
"pids_mode": "pidns",
"pid": "pidns",
"ipc_mode": "ipcns",
"ipc": "ipcns",
"uts": "utsns",
"userns_mode": "userns",
"tty": "terminal",
"device": "devices",
"exposed": "expose",
"exposed_ports": "expose",
"group_add": "groups",
"ulimit": "r_limits",
"ulimits": "r_limits",
"read_only": "read_only_filesystem",
"ip": "static_ip",
"mac_address": "static_mac",
"no_hosts": "use_image_hosts",
"log_opt": "log_configuration",
"log_driver": "log_configuration",
}
def init_options():
@ -256,6 +281,222 @@ def set_container_opts(input_vars):
return options_dict
class PodmanModuleParamsAPI:
"""Creates Podman API call.
Arguments:
action {str} -- action type from 'run', 'stop', 'create', 'delete',
'start'
params {dict} -- dictionary of module parameters
"""
def __init__(self, params, podman_version, module):
self.params = params
self.podman_version = podman_version
self.module = module
self.new_params = {}
def translate(self):
self.new_params = {k: v for k, v in self.params.items() if v is not None and k not in NON_PODMAN_ARGS}
if self.new_params.get("command") and not isinstance(self.new_params.get("command"), list):
self.new_params["command"] = shlex.split(self.new_params["command"])
transformed = {}
mounts = []
for k in self.new_params:
key = API_TRANSLATION.get(k, k)
transformed[key] = self.new_params[k]
if transformed.get("env"):
for k, v in transformed["env"].items():
transformed["env"][k] = str(v)
if transformed.get("labels"):
for k, v in transformed["labels"].items():
transformed["labels"][k] = str(v)
if transformed.get("entrypoint") is not None:
transformed["entrypoint"] = shlex.split(transformed["entrypoint"])
if transformed.get("hostadd") is not None:
hosts = []
for k, v in transformed["hostadd"].items():
hosts.append(":".join((k, v)))
transformed["hostadd"] = hosts
if transformed.get("volumes"):
volumes = []
for v in transformed["volumes"]:
vols = v.split(":")
if len(vols) < 2 or "/" not in vols[0]:
name = vols[0] if len(vols) > 1 else ""
volumes.append(
{
"Name": name,
"Dest": vols[1] if len(vols) > 1 else v,
}
)
continue
source = vols[0]
dest = vols[1].split(",")[0] # remove options
options = []
if len(vols) > 2:
opts = vols[2].split(",")
# work on options
for opt in opts:
if opt.lower() == "ro":
options.append("ro")
elif opt.lower().lstrip("r") in ("shared", "slave", "private", "unbindable"):
options.append(opt)
mounts.append(
{
"destination": dest,
"source": source,
"type": "bind",
"options": options,
}
)
transformed["volumes"] = volumes
if transformed.get("mounts"):
n_mounts = []
for m in transformed["mounts"]:
if not isinstance(m, str):
continue
mlist = m.split(",")
mdict = {}
for m1 in mlist:
if "=" in m1:
mkey, mval = m1.split("=")
else:
continue
if mkey.lower() == "type":
mdict["Type"] = mval
if mval.lower() == "devpts":
mdict["Source"] = "devpts"
elif mkey.lower() in ("source", "src"):
mdict["Source"] = mval
elif mkey.lower() in ("destination", "dst", "target"):
mdict["Destination"] = mval
elif mkey.lower() == "bind-propagation":
if "BindOptions" not in mdict:
mdict["BindOptions"] = {}
mdict["BindOptions"]["Propagation"] = mval
elif mkey.lower() == "bind-nonrecursive":
if "BindOptions" not in mdict:
mdict["BindOptions"] = {}
mdict["BindOptions"]["NonRecursive"] = mval
elif mkey.lower() == "ro":
mdict["ReadOnly"] = mval
elif mkey.lower() == "tmpfs-mode":
if "TmpfsOptions" not in mdict:
mdict["TmpfsOptions"] = {}
mdict["TmpfsOptions"]["Mode"] = mval
elif mkey.lower() == "tmpfs-size":
if "TmpfsOptions" not in mdict:
mdict["TmpfsOptions"] = {}
mdict["TmpfsOptions"]["SizeBytes"] = mval
n_mounts.append(mdict)
transformed["mounts"] = n_mounts + mounts
else:
transformed["mounts"] = mounts
if transformed.get("portmappings") is not None:
total_ports = []
for p in transformed.get("portmappings"):
parts = p.split(":")
if len(parts) == 1:
c_port, protocol = (parts[0].split("/") + ["tcp"])[:2]
total_ports.append(
{
"container_port": int(p),
"protocol": protocol if "udp" not in p else "udp",
# "host_port": int(parts[0].split("/")[0])
}
)
elif len(parts) == 2:
c_port, protocol = (parts[1].split("/") + ["tcp"])[:2]
total_ports.append(
{
"container_port": int(c_port),
"host_port": int(parts[0].split("/")[0]),
"protocol": protocol if "udp" not in p else "udp",
}
)
elif len(parts) == 3:
c_port, protocol = (parts[1].split("/") + ["tcp"])[:2]
total_ports.append(
{
"host_port": int(c_port),
"container_port": int(parts[2].split("/")[0]),
"protocol": protocol if "udp" not in p else "udp",
"host_ip": parts[0],
}
)
transformed["portmappings"] = total_ports
if transformed.get("pod"):
# API doesn't support creating Pod
transformed["pod"] = transformed["pod"].replace("new:", "")
if transformed.get("pidns"):
transformed["pidns"] = {"nsmode": transformed["pidns"]}
if transformed.get("ipcns"):
transformed["ipcns"] = {"nsmode": transformed["ipcns"]}
if transformed.get("utsns"):
transformed["utsns"] = {"nsmode": transformed["utsns"]}
if transformed.get("userns"):
transformed["userns"] = {"nsmode": transformed["userns"]}
if transformed.get("cgroupns"):
transformed["cgroupns"] = {"nsmode": transformed["cgroupns"]}
if transformed.get("network"):
if (
len(transformed["network"]) > 1
or len(transformed["network"][0].split(",")) > 1
and transformed["network"][0] not in ("none", "host", "bridge", "private")
and "container:" not in transformed["network"][0]
and "ns:" not in transformed["network"][0]
and "slirp4netns:" not in transformed["network"][0]
):
if "," in transformed["network"][0]:
transformed["Networks"] = {k: {} for k in transformed["network"][0].split(",")}
else:
transformed["Networks"] = {k: {} for k in transformed["network"]}
transformed["netns"] = {"nsmode": "bridge"}
elif (
len(transformed["network"]) == 1
and transformed["network"][0] not in ("none", "host", "bridge", "private")
and "container:" not in transformed["network"][0]
and "ns:" not in transformed["network"][0]
and "slirp4netns:" not in transformed["network"][0]
):
transformed["Networks"] = {k: {} for k in transformed["network"]}
elif "slirp4netns:" in transformed["network"][0] or "bridge:" in transformed["network"][0]:
transformed["netns"] = {"nsmode": transformed["network"][0].split(":")[0]}
netopts = {
k: [v] for k, v in [i.split("=") for i in transformed["network"][0].split(":")[1].split(",")]
}
transformed["network_options"] = netopts
else:
transformed["netns"] = {"nsmode": transformed["network"][0]}
if transformed.get("r_limits"):
rlimits = []
for rlim in transformed["r_limits"]:
tmp_rlim = rlim.split("=")
typ = tmp_rlim[0]
soft = tmp_rlim[1].split(":")[0]
if len(tmp_rlim[1].split(":")) > 1:
hard = tmp_rlim[1].split(":")[1]
else:
hard = soft
rlimits.append({"type": typ, "soft": int(soft), "hard": int(hard)})
transformed["r_limits"] = rlimits
if transformed.get("rootfs"):
transformed["rootfs"] = transformed["image"]
transformed.pop("image")
if transformed.get("log_configuration"):
transformed["log_configuration"] = {}
if self.params["log_opt"] is not None:
transformed["log_configuration"]["options"] = self.params["log_opt"]
if self.params["log_driver"] is not None:
transformed["log_configuration"]["driver"] = self.params["log_driver"]
if transformed.get("devices"):
transformed["devices"] = [{"path": d.split(":")[0]} for d in transformed["devices"]]
self.module.log("PODMAN-DEBUG-API: %s" % transformed)
return transformed
class PodmanModuleParams:
"""Creates list of arguments for podman CLI command.
@ -953,6 +1194,23 @@ class PodmanContainerDiff:
return True
return False
def clean_aliases(self, params):
aliases = {}
for k, v in ARGUMENTS_SPEC_CONTAINER.items():
if "aliases" in v:
for alias in v["aliases"]:
aliases[alias] = k
return {aliases.get(k, k): v for k, v in params.items()}
def _get_create_command_annotation(self):
if (
"annotations" in self.info.get("config", {})
and self.info["config"]["annotations"] is not None
and "ansible.podman.collection.cmd" in self.info["config"]["annotations"]
):
return self.clean_aliases(json.loads(self.info["config"]["annotations"]["ansible.podman.collection.cmd"]))
return {}
def _diff_generic(self, module_arg, cmd_arg, boolean_type=False):
"""
Generic diff function for module arguments from CreateCommand
@ -968,6 +1226,33 @@ class PodmanContainerDiff:
"""
info_config = self.info["config"]
if USE_API:
cmd = self._get_create_command_annotation()
if cmd:
params = self.clean_aliases(self.params)
return self._diff_update_and_compare(module_arg, cmd.get(module_arg), params.get(module_arg))
elif 'createcommand' in self.info["config"] and self.info["config"]['createcommand']:
self.module.log(
"PODMAN-DEBUG: No annotation found, falling back to create_command parsing."
)
cmd = self.info["config"]['createcommand']
cmd = [i.lower() for i in cmd]
cmd_arg = "--" + module_arg.replace("_", "-") if cmd_arg is None else cmd_arg
before = None
after = self.params.get(module_arg)
if boolean_type:
before = cmd_arg in cmd or (cmd_arg + "=true") in cmd
if not before:
before = None
self.module.log(f"PODMAN-DEBUG: 11 before = {before} and after = {after} and cmd = {cmd} and cmd_arg = {cmd_arg}")
elif cmd_arg in cmd:
self.module.log(f"PODMAN-DEBUG: 22 before = {before} and after = {after} and cmd = {cmd} and cmd_arg = {cmd_arg}")
arg_index = cmd.index(cmd_arg)
if arg_index + 1 < len(cmd):
before = cmd[arg_index + 1]
return self._diff_update_and_compare(module_arg, before, after)
return self._diff_update_and_compare(module_arg, None, None)
before, after = diff_generic(self.params, info_config, module_arg, cmd_arg, boolean_type)
return self._diff_update_and_compare(module_arg, before, after)
@ -1174,7 +1459,7 @@ class PodmanContainerDiff:
if "healthcheck" in self.info["config"]:
# the "test" key is a list of 2 items where the first one is
# "CMD-SHELL" and the second one is the actual healthcheck command.
if len(self.info["config"]["healthcheck"]["test"]) > 1:
if len(self.info["config"]["healthcheck"].get('test', '')) > 1:
before = self.info["config"]["healthcheck"]["test"][1]
after = self.params["healthcheck"] or before
return self._diff_update_and_compare("healthcheck", before, after)
@ -1549,7 +1834,7 @@ class PodmanContainerDiff:
return different
def ensure_image_exists(module, image, module_params):
def ensure_image_exists(module, image, module_params, client):
"""If image is passed, ensure it exists, if not - pull it or fail.
Arguments:
@ -1569,32 +1854,43 @@ def ensure_image_exists(module, image, module_params):
return image_actions
if not image:
return image_actions
image_exists_cmd = [module_exec, "image", "exists", image]
rc, out, err = module.run_command(image_exists_cmd)
if rc == 0:
if USE_API:
if client.images.exists(image):
return image_actions
else:
image_exists_cmd = [module_exec, "image", "exists", image]
rc, out, err = module.run_command(image_exists_cmd)
if rc == 0:
return image_actions
if USE_API:
img = client.images.pull(image)
if not img.get("id"):
module.fail_json(msg="Can't find and pull image %s: %s" % (image, img["text"]))
image_actions.append("pulled image %s" % image)
return image_actions
else:
image_pull_cmd = [module_exec, "image", "pull", image]
if module_params["tls_verify"] is False:
image_pull_cmd.append("--tls-verify=false")
if module_params["authfile"]:
image_pull_cmd.extend(["--authfile", module_params["authfile"]])
if module_params["arch"]:
image_pull_cmd.append("--arch=%s" % module_params["arch"])
if module_params["decryption_key"]:
image_pull_cmd.append("--decryption-key=%s" % module_params["decryption_key"])
if module_params["platform"]:
image_pull_cmd.append("--platform=%s" % module_params["platform"])
if module_params["os"]:
image_pull_cmd.append("--os=%s" % module_params["os"])
if module_params["variant"]:
image_pull_cmd.append("--variant=%s" % module_params["variant"])
if module_params.get("debug"):
module.log("PODMAN-CONTAINER-DEBUG: %s" % " ".join(image_pull_cmd))
rc, out, err = module.run_command(image_pull_cmd)
if rc != 0:
module.fail_json(msg="Can't pull image %s" % image, stdout=out, stderr=err)
image_actions.append("pulled image %s" % image)
return image_actions
image_pull_cmd = [module_exec, "image", "pull", image]
if module_params["tls_verify"] is False:
image_pull_cmd.append("--tls-verify=false")
if module_params["authfile"]:
image_pull_cmd.extend(["--authfile", module_params["authfile"]])
if module_params["arch"]:
image_pull_cmd.append("--arch=%s" % module_params["arch"])
if module_params["decryption_key"]:
image_pull_cmd.append("--decryption-key=%s" % module_params["decryption_key"])
if module_params["platform"]:
image_pull_cmd.append("--platform=%s" % module_params["platform"])
if module_params["os"]:
image_pull_cmd.append("--os=%s" % module_params["os"])
if module_params["variant"]:
image_pull_cmd.append("--variant=%s" % module_params["variant"])
if module_params.get("debug"):
module.log("PODMAN-CONTAINER-DEBUG: %s" % " ".join(image_pull_cmd))
rc, out, err = module.run_command(image_pull_cmd)
if rc != 0:
module.fail_json(msg="Can't pull image %s" % image, stdout=out, stderr=err)
image_actions.append("pulled image %s" % image)
return image_actions
class PodmanContainer:
@ -1603,7 +1899,7 @@ class PodmanContainer:
Manages podman container, inspects it and checks its current state
"""
def __init__(self, module, name, module_params):
def __init__(self, module, name, module_params, client):
"""Initialize PodmanContainer class.
Arguments:
@ -1612,6 +1908,7 @@ class PodmanContainer:
"""
self.module = module
self.client = client
self.module_params = module_params
self.name = name
self.stdout, self.stderr = "", ""
@ -1655,6 +1952,12 @@ class PodmanContainer:
def get_info(self):
"""Inspect container and gather info about it."""
# pylint: disable=unused-variable
if USE_API:
try:
container = self.client.containers.get(self.name)
return container
except Exception:
return {}
rc, out, err = self.module.run_command([self.module_params["executable"], b"container", b"inspect", self.name])
return json.loads(out)[0] if rc == 0 else {}
@ -1664,6 +1967,13 @@ class PodmanContainer:
is_rootfs = self.module_params["rootfs"]
if is_rootfs:
return {"Id": self.module_params["image"]}
if USE_API:
try:
image = self.client.images.get(self.module_params["image"].replace("docker://", ""))
return image
except Exception:
self.module.log("PODMAN-CONTAINER-DEBUG: API Can't inspect image %s" % self.module_params["image"])
return {}
rc, out, err = self.module.run_command(
[
self.module_params["executable"],
@ -1689,34 +1999,68 @@ class PodmanContainer:
action {str} -- action to perform - start, create, stop, run,
delete, restart
"""
b_command = PodmanModuleParams(
action,
self.module_params,
self.version,
self.module,
).construct_command_from_params()
full_cmd = " ".join([self.module_params["executable"]] + [to_native(i) for i in b_command])
self.actions.append(full_cmd)
if self.module.check_mode:
self.module.log("PODMAN-CONTAINER-DEBUG (check_mode): %s" % full_cmd)
if USE_API:
new_params = PodmanModuleParamsAPI(
self.module_params,
self.version,
self.module,
).translate()
if action in ("start", "stop", "delete", "restart"):
container = self.client.containers.get(self.name)
if not container:
self.module.fail_json(msg="Container %s doesn't exist")
if action == "start":
self.client.containers.start(self.name)
elif action == "stop":
self.client.containers.stop(self.name)
elif action == "restart":
self.client.containers.restart(self.name)
elif action == "delete":
self.client.containers.remove(self.name, force=True)
elif action == "create":
new_params.pop("detach")
if not new_params.get("annotations"):
new_params["annotations"] = {}
new_params["annotations"].update({"ansible.podman.collection.cmd": json.dumps(self.module_params)})
try:
container = self.client.containers.create(**new_params)
except Exception as e:
self.module.fail_json(msg=str(e))
elif action == "run":
new_params.pop("detach")
if not new_params.get("annotations"):
new_params["annotations"] = {}
new_params["annotations"].update({"ansible.podman.collection.cmd": json.dumps(self.module_params)})
try:
container = self.client.containers.run(**new_params)
except Exception as e:
self.module.fail_json(msg=str(e))
self.actions.append({action: new_params})
else:
rc, out, err = self.module.run_command(
[self.module_params["executable"], b"container"] + b_command,
expand_user_and_vars=False,
)
self.module.log("PODMAN-CONTAINER-DEBUG: %s" % full_cmd)
if self.module_params["debug"]:
self.module.log("PODMAN-CONTAINER-DEBUG STDOUT: %s" % out)
self.module.log("PODMAN-CONTAINER-DEBUG STDERR: %s" % err)
self.module.log("PODMAN-CONTAINER-DEBUG RC: %s" % rc)
self.stdout = out
self.stderr = err
if rc != 0:
self.module.fail_json(
msg="Container %s exited with code %s when %sed" % (self.name, rc, action),
stdout=out,
stderr=err,
b_command = PodmanModuleParams(
action,
self.module_params,
self.version,
self.module,
).construct_command_from_params()
full_cmd = " ".join([self.module_params["executable"]] + [to_native(i) for i in b_command])
self.actions.append(full_cmd)
if self.module.check_mode:
self.module.log("PODMAN-CONTAINER-DEBUG (check_mode): %s" % full_cmd)
else:
rc, out, err = self.module.run_command(
[self.module_params["executable"], b"container"] + b_command, expand_user_and_vars=False
)
self.module.log("PODMAN-CONTAINER-DEBUG: %s" % full_cmd)
if self.module_params["debug"]:
self.module.log("PODMAN-CONTAINER-DEBUG STDOUT: %s" % out)
self.module.log("PODMAN-CONTAINER-DEBUG STDERR: %s" % err)
self.module.log("PODMAN-CONTAINER-DEBUG RC: %s" % rc)
self.stdout = out
self.stderr = err
if rc != 0:
self.module.fail_json(msg="Can't %s container %s" % (action, self.name), stdout=out, stderr=err)
def run(self):
"""Run the container."""
@ -1780,12 +2124,21 @@ class PodmanManager:
}
self.module_params = params
self.name = self.module_params["name"]
self.executable = self.module.get_bin_path(self.module_params["executable"], required=True)
self.client = None
if self.module_params["podman_socket"]:
global USE_API
USE_API = True
api = PodmanAPI(self.module, self.module_params)
self.client = api.client
else:
self.executable = self.module.get_bin_path(self.module_params["executable"], required=True)
self.image = self.module_params["image"]
self.state = self.module_params["state"]
disable_image_pull = self.state in ("quadlet", "absent") or self.module_params["pull"] == "never"
image_actions = (
ensure_image_exists(self.module, self.image, self.module_params) if not disable_image_pull else []
ensure_image_exists(self.module, self.image, self.module_params, self.client)
if not disable_image_pull
else []
)
self.results["actions"] += image_actions
@ -1795,7 +2148,22 @@ class PodmanManager:
if self.module_params["generate_systemd"].get("new"):
self.module_params["rm"] = True
self.container = PodmanContainer(self.module, self.name, self.module_params)
self.container = PodmanContainer(self.module, self.name, self.module_params, self.client)
def api_wait(self):
"""In case of detach=False and API call, wait until container
is finished.
"""
if self.container.module_params.get("detach") is None or self.container.module_params.get("detach"):
return
status = True
time.sleep(2) # Give time to container to start
while status:
info = self.container.get_info()
if not info:
return
status = info["State"]["Running"]
time.sleep(2)
def update_container_result(self, changed=True):
"""Inspect the current container, update results with last info, exit.
@ -1804,6 +2172,8 @@ class PodmanManager:
changed {bool} -- whether any action was performed
(default: {True})
"""
if USE_API:
self.api_wait()
facts = self.container.get_info() if changed else self.container.info
out, err = self.container.stdout, self.container.stderr
self.results.update(

View file

@ -638,7 +638,6 @@ class PodmanPodDiff:
after = [":".join([clean_volume(i) for i in v.split(":")[:2]]) for v in self.params["volume"]]
if before is not None:
before = [":".join([clean_volume(i) for i in v.split(":")[:2]]) for v in before]
self.module.log("PODMAN Before: %s and After: %s" % (before, after))
if before is None and after is None:
return self._diff_update_and_compare("volume", before, after)
if after is not None:

View file

@ -32,6 +32,11 @@ options:
machine running C(podman)
default: 'podman'
type: str
podman_socket:
description:
- Unix socket address for API connection. If API is not available, the
module will fail.
type: str
state:
description:
- I(absent) - A container matching the specified name will be stopped and
@ -1244,6 +1249,13 @@ EXAMPLES = r"""
- |
[Install]
WantedBy=default.target
- name: Run container with Podman API
containers.podman.podman_container:
name: my_api_container
image: docker.io/library/busybox:latest
state: started
podman_socket: /var/run/podman/podman.sock
"""
RETURN = r"""

View file

@ -32,6 +32,11 @@ options:
machine running C(podman)
default: 'podman'
type: str
podman_socket:
description:
- Unix socket address for API connection. If API is not available, the
module will fail.
type: str
"""
EXAMPLES = r"""
@ -322,8 +327,12 @@ containers:
import json
import time
from ..module_utils.podman.common import PodmanAPI
from ansible.module_utils.basic import AnsibleModule
USE_API = False
def get_containers_facts(module, executable, name):
"""Collect containers facts for all containers or for specified in 'name'.
@ -338,6 +347,24 @@ def get_containers_facts(module, executable, name):
"""
retry = 0
retry_limit = 4
if module.params["podman_socket"]:
global USE_API
USE_API = True
api = PodmanAPI(module, module.params)
client = api.client
all_names = client.containers.list(all_=True)
all_data = []
cycle = name or [j["Id"] for j in all_names]
for c in cycle:
try:
container_attrs = client.containers.get(c)
if container_attrs:
all_data.append(container_attrs)
except Exception:
if name:
module.fail_json(msg="Container %s can't be found!" % c)
continue
return all_data, "", ""
if not name:
all_names = [executable, "container", "ls", "-q", "-a"]
rc, out, err = module.run_command(all_names)
@ -399,12 +426,15 @@ def main():
argument_spec={
"executable": {"type": "str", "default": "podman"},
"name": {"type": "list", "elements": "str"},
"podman_socket": {"type": "str"},
},
supports_check_mode=True,
)
name = module.params["name"]
executable = module.get_bin_path(module.params["executable"], required=True)
executable = None
if not module.params["podman_socket"]:
executable = module.get_bin_path(module.params["executable"], required=True)
# pylint: disable=unused-variable
inspect_results, out, err = get_containers_facts(module, executable, name)

2
requirements.txt Normal file
View file

@ -0,0 +1,2 @@
requests<=2.32.5
requests-unixsocket<=0.4.1

View file

@ -25,6 +25,7 @@
executable: "{{ test_executable | default('podman') }}"
name: "{{ item }}"
state: absent
podman_socket: "{{ podman_socket | default(omit) }}"
loop:
- "alpine:3.7"
- "container"
@ -37,6 +38,7 @@
containers.podman.podman_container:
executable: "{{ test_executable | default('podman') }}"
name: container
podman_socket: "{{ podman_socket | default(omit) }}"
ignore_errors: true
register: no_image
@ -45,6 +47,7 @@
executable: "{{ test_executable | default('podman') }}"
name: container
state: created
podman_socket: "{{ podman_socket | default(omit) }}"
ignore_errors: true
register: no_image1
@ -53,6 +56,7 @@
executable: "{{ test_executable | default('podman') }}"
name: container
state: present
podman_socket: "{{ podman_socket | default(omit) }}"
ignore_errors: true
register: no_image2
@ -81,6 +85,7 @@
image: alpine:3.7
state: started
command: sleep 1d
podman_socket: "{{ podman_socket | default(omit) }}"
register: image
- name: Check using already pulled image
@ -90,6 +95,7 @@
image: alpine:3.7
state: started
command: sleep 1d
podman_socket: "{{ podman_socket | default(omit) }}"
register: image2
- name: Check output is correct
@ -127,7 +133,9 @@
- name: Check output is correct - TLS verify OFF
assert:
that:
- image_tls.podman_actions | select('search', '--tls-verify=False') | list | length > 0
- >-
(image_tls.podman_actions | select('search', '--tls-verify=False') | list | length > 0) or
(image_tls.podman_actions | select('search', 'tls_verify": false') | list | length > 0)
- name: Check using already pulled image - TLS verify OFF
containers.podman.podman_container:
@ -162,6 +170,7 @@
image: ineverneverneverexist
state: started
command: sleep 1d
podman_socket: "{{ podman_socket | default(omit) }}"
register: imagefail
ignore_errors: true
@ -169,7 +178,9 @@
assert:
that:
- imagefail is failed
- imagefail.msg == "Can't pull image ineverneverneverexist"
- >-
imagefail.msg == "Can't pull image ineverneverneverexist"
or "Can't find and pull image ineverneverneverexist" in imagefail.msg
- name: Force container recreate
containers.podman.podman_container:
@ -179,6 +190,7 @@
state: started
command: sleep 1d
recreate: true
podman_socket: "{{ podman_socket | default(omit) }}"
register: recreated
- name: Check output is correct
@ -196,6 +208,7 @@
executable: "{{ test_executable | default('podman') }}"
name: container
state: started
podman_socket: "{{ podman_socket | default(omit) }}"
- name: Present container
containers.podman.podman_container:
@ -204,6 +217,7 @@
image: alpine
state: present
command: sleep 1d
podman_socket: "{{ podman_socket | default(omit) }}"
register: start_present
- name: Check output is correct
@ -216,6 +230,7 @@
executable: "{{ test_executable | default('podman') }}"
name: container
state: stopped
podman_socket: "{{ podman_socket | default(omit) }}"
register: stopped
- name: Stop the same container again (idempotency)
@ -223,6 +238,7 @@
executable: "{{ test_executable | default('podman') }}"
name: container
state: stopped
podman_socket: "{{ podman_socket | default(omit) }}"
register: stopped_again
- name: Check output is correct
@ -244,6 +260,7 @@
executable: "{{ test_executable | default('podman') }}"
name: container
state: absent
podman_socket: "{{ podman_socket | default(omit) }}"
register: deleted
- name: Delete again container (idempotency)
@ -251,6 +268,7 @@
executable: "{{ test_executable | default('podman') }}"
name: container
state: absent
podman_socket: "{{ podman_socket | default(omit) }}"
register: deleted_again
- name: Check output is correct
@ -274,6 +292,7 @@
image: alpine:3.7
state: stopped
command: sleep 1d
podman_socket: "{{ podman_socket | default(omit) }}"
register: created
- name: Check output is correct
@ -312,6 +331,7 @@
executable: "{{ test_executable | default('podman') }}"
name: container
state: absent
podman_socket: "{{ podman_socket | default(omit) }}"
- name: Create container in 'created' state
containers.podman.podman_container:
@ -320,6 +340,7 @@
image: alpine:3.7
state: created
command: sleep 1d
podman_socket: "{{ podman_socket | default(omit) }}"
register: created
- name: Check output is correct
@ -341,6 +362,7 @@
state: created
command: sleep 1d
recreate: true
podman_socket: "{{ podman_socket | default(omit) }}"
register: recreated
- name: Check output is correct
@ -357,6 +379,7 @@
executable: "{{ test_executable | default('podman') }}"
name: container
restart: true
podman_socket: "{{ podman_socket | default(omit) }}"
register: restarted
- name: Check output is correct
@ -373,6 +396,7 @@
executable: "{{ test_executable | default('podman') }}"
name: container
restart: true
podman_socket: "{{ podman_socket | default(omit) }}"
register: restarted
- name: Check output is correct
@ -389,6 +413,7 @@
executable: "{{ test_executable | default('podman') }}"
name: container
state: absent
podman_socket: "{{ podman_socket | default(omit) }}"
- name: Start container that was deleted
containers.podman.podman_container:
@ -397,6 +422,7 @@
image: alpine:3.7
state: started
command: sleep 1d
podman_socket: "{{ podman_socket | default(omit) }}"
register: started
- name: Check output is correct
@ -412,6 +438,7 @@
executable: "{{ test_executable | default('podman') }}"
name: container
state: absent
podman_socket: "{{ podman_socket | default(omit) }}"
register: deleted
- name: Delete again container (idempotency)
@ -419,6 +446,7 @@
executable: "{{ test_executable | default('podman') }}"
name: container
state: absent
podman_socket: "{{ podman_socket | default(omit) }}"
register: deleted_again
- name: Check output is correct
@ -447,6 +475,7 @@
- label=type:spc_t
- label=filetype:container_share_t
- seccomp=unconfined
podman_socket: "{{ podman_socket | default(omit) }}"
- name: Recreate container with same security_opt flags
containers.podman.podman_container:
@ -460,6 +489,7 @@
- label=type:spc_t
- label=filetype:container_share_t
- seccomp=unconfined
podman_socket: "{{ podman_socket | default(omit) }}"
register: recreate_security_opt
- name: Check if output is correct
@ -476,6 +506,7 @@
executable: "{{ test_executable | default('podman') }}"
name: container
state: absent
podman_socket: "{{ podman_socket | default(omit) }}"
- name: Recreate container with parameters
containers.podman.podman_container:
@ -513,6 +544,7 @@
- /tmp:/data
mounts:
- type=devpts,destination=/dev/pts
podman_socket: "{{ podman_socket | default(omit) }}"
register: test
- name: Check output is correct
@ -579,6 +611,7 @@
image: docker.io/alpine
state: started
command: sleep 20m
podman_socket: "{{ podman_socket | default(omit) }}"
- name: Check basic idempotency of running container - run it again
containers.podman.podman_container:
@ -587,6 +620,7 @@
image: alpine:latest
state: started
command: sleep 20m
podman_socket: "{{ podman_socket | default(omit) }}"
register: idem
- name: Check that nothing was changed
@ -602,6 +636,7 @@
state: started
command: sleep 20m
force_restart: true
podman_socket: "{{ podman_socket | default(omit) }}"
register: idem_r
- name: Check that task was changed
@ -616,6 +651,7 @@
image: alpine:latest
state: started
command: sleep 20m
podman_socket: "{{ podman_socket | default(omit) }}"
register: idem_r1
- name: Check that task was not changed
@ -631,6 +667,7 @@
state: started
command: sleep 20m
tty: true
podman_socket: "{{ podman_socket | default(omit) }}"
register: idem1
- name: Check that container is recreated when changed
@ -645,6 +682,7 @@
image: alpine
state: started
command: sleep 20m
podman_socket: "{{ podman_socket | default(omit) }}"
register: idem2
- name: Check that container is recreated when changed to default value
@ -657,15 +695,21 @@
executable: "{{ test_executable | default('podman') }}"
name: testidem
state: absent
podman_socket: "{{ podman_socket | default(omit) }}"
register: remove
- name: Check podman_actions
assert:
that:
- "'podman rm --force testidem' in remove.podman_actions"
when: podman_socket is not defined
# - name: Create a pod
# shell: podman pod create --name testidempod
- name: Check basic idempotency of pod container
containers.podman.podman_pod:
executable: "{{ test_executable | default('podman') }}"
name: testidempod
state: started
when: podman_socket is defined
- name: Check basic idempotency of pod container
containers.podman.podman_container:
@ -675,6 +719,7 @@
state: started
command: sleep 20m
pod: "new:testidempod"
podman_socket: "{{ podman_socket | default(omit) }}"
- name: Check basic idempotency of pod container - run it again
containers.podman.podman_container:
@ -684,6 +729,7 @@
state: started
command: sleep 20m
pod: testidempod
podman_socket: "{{ podman_socket | default(omit) }}"
register: idem3
- name: Check that nothing was changed in pod containers
@ -700,6 +746,7 @@
command: sleep 20m
tty: true
pod: testidempod
podman_socket: "{{ podman_socket | default(omit) }}"
register: idem4
- name: Check that container is recreated when changed
@ -716,6 +763,7 @@
image: alpine
state: started
command: sleep 20m
podman_socket: "{{ podman_socket | default(omit) }}"
generate_systemd:
path: /tmp/
restart_policy: always
@ -737,6 +785,7 @@
image: alpine
state: started
command: sleep 20m
podman_socket: "{{ podman_socket | default(omit) }}"
generate_systemd:
path: /tmp/
time: 120
@ -808,6 +857,7 @@
image: alpine
state: absent
command: sleep 20m
podman_socket: "{{ podman_socket | default(omit) }}"
generate_systemd:
path: /tmp/
restart_policy: always
@ -861,12 +911,14 @@
- stdout
- stderr
env_file: /tmp/envfile
podman_socket: "{{ podman_socket | default(omit) }}"
register: envfile
- name: Check output is correct for env file
assert:
that:
- envfile.stdout == "foo\n"
when: podman_socket is not defined
- name: Create container with multiple environment variables files
containers.podman.podman_container:
@ -884,22 +936,27 @@
env_file:
- /tmp/envfile
- /tmp/envfile2
podman_socket: "{{ podman_socket | default(omit) }}"
register: envfile2
- name: Check output is correct for multiple env files
assert:
that:
- envfile2.stdout == "qwerty\n"
when: podman_socket is not defined
- name: Delete container with environment variables file
containers.podman.podman_container:
executable: "{{ test_executable | default('podman') }}"
name: container1
state: absent
podman_socket: "{{ podman_socket | default(omit) }}"
- name: Rootfs container tests
when: podman_socket is not defined
tags:
- no_build_version
- rootfs
block:
- name: Create temporary rootfs directory
@ -1041,23 +1098,27 @@
image: alpine:3.7
state: started
command: ls /nonexists
podman_socket: "{{ podman_socket | default(omit) }}"
attach:
- stdout
- stderr
register: attach
ignore_errors: true
when: podman_socket is not defined
- name: Check output is correct for started container with attaching
assert:
that:
- attach is failed
- "'No such file or directory' in attach.stderr"
when: podman_socket is not defined
- name: Delete container with attaching
containers.podman.podman_container:
executable: "{{ test_executable | default('podman') }}"
name: container1
state: absent
podman_socket: "{{ podman_socket | default(omit) }}"
- name: Create container with attaching in created state
containers.podman.podman_container:
@ -1069,6 +1130,8 @@
attach:
- stdout
- stderr
podman_socket: "{{ podman_socket | default(omit) }}"
when: podman_socket is not defined
- name: Start container with attaching from created state
containers.podman.podman_container:
@ -1078,20 +1141,24 @@
attach:
- stdout
- stderr
podman_socket: "{{ podman_socket | default(omit) }}"
register: attach2
ignore_errors: true
when: podman_socket is not defined
- name: Check output is correct for started container with attaching from created state
assert:
that:
- attach2 is failed
- "'No such file or directory' in attach2.stderr"
when: podman_socket is not defined
- name: Delete container with attaching from created state
containers.podman.podman_container:
executable: "{{ test_executable | default('podman') }}"
name: container1
state: absent
podman_socket: "{{ podman_socket | default(omit) }}"
- name: Create container without attaching in created state
containers.podman.podman_container:
@ -1100,24 +1167,30 @@
image: alpine:3.7
state: created
command: ls /nonexists
podman_socket: "{{ podman_socket | default(omit) }}"
when: podman_socket is not defined
- name: Start container without attaching from created state
containers.podman.podman_container:
executable: "{{ test_executable | default('podman') }}"
name: container1
state: started
podman_socket: "{{ podman_socket | default(omit) }}"
register: attach21
when: podman_socket is not defined
- name: Check output is correct for container without attaching from created state
assert:
that:
- attach21 is success
when: podman_socket is not defined
- name: Delete container without attaching from created state
containers.podman.podman_container:
executable: "{{ test_executable | default('podman') }}"
name: container1
state: absent
podman_socket: "{{ podman_socket | default(omit) }}"
- name: Create container with detach False
containers.podman.podman_container:
@ -1127,6 +1200,8 @@
state: created
command: ls /nonexists
detach: false
podman_socket: "{{ podman_socket | default(omit) }}"
when: podman_socket is not defined
- name: Start container with detach False
containers.podman.podman_container:
@ -1134,14 +1209,17 @@
name: container1
state: started
detach: false
podman_socket: "{{ podman_socket | default(omit) }}"
register: attach3
ignore_errors: true
when: podman_socket is not defined
- name: Check output is correct for started container with detach False
assert:
that:
- attach3 is failed
- "'No such file or directory' in attach3.stderr"
when: podman_socket is not defined
- name: Create a Quadlet for container with filename
containers.podman.podman_container:
@ -1530,12 +1608,14 @@
executable: "{{ test_executable | default('podman') }}"
name: testidem-pod
state: absent
podman_socket: "{{ podman_socket | default(omit) }}"
- name: Delete all container leftovers from tests
containers.podman.podman_container:
executable: "{{ test_executable | default('podman') }}"
name: "{{ item }}"
state: absent
podman_socket: "{{ podman_socket | default(omit) }}"
loop:
- "alpine:3.7"
- "container"

View file

@ -0,0 +1 @@
../podman_container_idempotency/files

View file

@ -0,0 +1,63 @@
---
- name: Set podman socket var for rootless
set_fact:
podman_socket: unix:///tmp/podman.sock
podman_root_socket: unix:///tmp/root-podman.sock
- name: Run tasks from podman container
include_tasks: ../../podman_container/tasks/main.yml
- name: Run tasks from podman container info
include_tasks: ../../podman_container_info/tasks/main.yml
- name: Prepare a container
include_tasks: ../../podman_container_idempotency/tasks/build_test_container.yml
- name: Test idempotency of users
include_tasks: ../../podman_container_idempotency/tasks/idem_users.yml
- name: Test idempotency of workdir
include_tasks: ../../podman_container_idempotency/tasks/idem_workdir.yml
- name: Test idempotency of labels
include_tasks: ../../podman_container_idempotency/tasks/idem_labels.yml
- name: Test idempotency of stop signal
include_tasks: ../../podman_container_idempotency/tasks/idem_stopsignal.yml
- name: Test idempotency of ports
include_tasks: ../../podman_container_idempotency/tasks/idem_ports.yml
- name: Test idempotency of volumes
include_tasks: ../../podman_container_idempotency/tasks/idem_volumes.yml
- name: Test idempotency of containers in pods
include_tasks: ../../podman_container_idempotency/tasks/idem_pods.yml
- name: Test idempotency of bool options in containers and idempotency
include_tasks: ../../podman_container_idempotency/tasks/idem_bool_list_dict.yml
- name: Test idempotency of other settings
include_tasks: ../../podman_container_idempotency/tasks/idem_all.yml
- name: Set podman socket var for rootless
set_fact:
podman_socket: http://localhost:25771
- name: Run tasks from podman container
include_tasks: ../../podman_container/tasks/main.yml
- name: Run tasks from podman container info
include_tasks: ../../podman_container_info/tasks/main.yml
- name: Prepare a container
include_tasks: ../../podman_container_idempotency/tasks/build_test_container.yml
- name: Test idempotency of other settings
include_tasks: ../../podman_container_idempotency/tasks/idem_volumes.yml
- name: Test idempotency of ports
include_tasks: ../../podman_container_idempotency/tasks/idem_ports.yml
- name: Test idempotency of other settings
include_tasks: ../../podman_container_idempotency/tasks/idem_all.yml

View file

@ -4,6 +4,7 @@
executable: "{{ test_executable | default('podman') }}"
name: idempotency
state: absent
podman_socket: "{{ podman_socket | default(omit) }}"
- name: Run container
containers.podman.podman_container:
@ -12,6 +13,7 @@
name: idempotency
state: started
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
- name: Run container again
containers.podman.podman_container:
@ -20,6 +22,7 @@
name: idempotency
state: present
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test1
- name: Check info when running container again
@ -35,6 +38,7 @@
env: {}
publish: []
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test_to_empty
- name: Run container with empty vars for list and dict - again
@ -46,6 +50,7 @@
env: {}
publish: []
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test_empty
- name: Run container again w/o empty vars
@ -55,14 +60,15 @@
name: idempotency
state: present
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test_from_empty
- name: Check info when running container again
assert:
that:
- test_to_empty is not changed
- test_empty is not changed
- test_from_empty is not changed
- test_to_empty is not changed or podman_socket is defined
- test_empty is not changed or podman_socket is defined
- test_from_empty is not changed or podman_socket is defined
- name: Run container with environment vars
containers.podman.podman_container:
@ -74,6 +80,7 @@
mykey: "amazing value"
ENV1: "one=two=three"
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test2
- name: Check info with environment vars
@ -90,6 +97,7 @@
mykey: "amazing value"
ENV1: "one=two=three"
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test3
- name: Check info with environment vars again
@ -106,6 +114,7 @@
mykey: "amazing value1"
ENV1: "one=two=three"
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test4
- name: Check info with changed environment vars
@ -122,6 +131,7 @@
tag: nonotag
log_driver: journald
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test9
- name: Check info with log opt tag
@ -138,6 +148,7 @@
tag: nonotag
log_driver: journald
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test10
- name: Check info with log opt tag - again
@ -152,6 +163,7 @@
state: present
command: 1h
log_driver: journald
podman_socket: "{{ podman_socket | default(omit) }}"
register: test11
- name: Check info with default log opt tag
@ -168,6 +180,7 @@
path: /tmp/container.log
log_driver: journald
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test12
- name: Check info with log opt path
@ -184,6 +197,7 @@
path: /tmp/container2.log
log_driver: journald
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test13
- name: Check info with changed log opt path
@ -198,6 +212,7 @@
state: present
log_driver: journald
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test14
- name: Check info with default log opt path
@ -216,6 +231,7 @@
max_size: 100mb
tag: sometag
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
- name: Run container with mounted /dev/fuse
containers.podman.podman_container:
@ -226,6 +242,7 @@
command: 1h
device:
- /dev/fuse
podman_socket: "{{ podman_socket | default(omit) }}"
register: test15
- name: Run container with mounted /dev/fuse again
@ -237,6 +254,7 @@
command: 1h
device:
- /dev/fuse
podman_socket: "{{ podman_socket | default(omit) }}"
register: test16
- name: Run container with mounted /dev/fuse:/dev/fuse
@ -248,6 +266,7 @@
command: 1h
device:
- /dev/fuse:/dev/fuse
podman_socket: "{{ podman_socket | default(omit) }}"
register: test17
- name: Run container with mounted /dev/fuse third time
@ -259,6 +278,7 @@
command: 1h
device:
- /dev/fuse
podman_socket: "{{ podman_socket | default(omit) }}"
register: test18
- name: Run container without mounted device
@ -268,6 +288,7 @@
name: idempotency
state: started
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test19
- name: Check info with mounted devices
@ -289,6 +310,7 @@
host1: 127.0.0.1
host2: fd00::1
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test20
- name: Check info with etc_hosts
@ -305,6 +327,7 @@
host1: 127.0.0.1
host2: fd00::1
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test21
- name: Check info with etc_hosts again
@ -317,6 +340,7 @@
image: "{{ idem_image }}"
name: idempotency
state: present
podman_socket: "{{ podman_socket | default(omit) }}"
- name: Run container with restart policy always
containers.podman.podman_container:
@ -325,6 +349,7 @@
name: idempotency
state: present
restart_policy: always
podman_socket: "{{ podman_socket | default(omit) }}"
register: test22
- name: Check info with restart policy always
@ -338,6 +363,7 @@
name: idempotency
state: present
restart_policy: always
podman_socket: "{{ podman_socket | default(omit) }}"
register: test23
- name: Check info with restart policy always again
@ -351,6 +377,7 @@
name: idempotency
state: present
restart_policy: on-failure
podman_socket: "{{ podman_socket | default(omit) }}"
register: test24
- name: Check info with restart policy on-failure
@ -363,6 +390,7 @@
image: "{{ idem_image }}"
name: idempotency
state: present
podman_socket: "{{ podman_socket | default(omit) }}"
register: test25
- name: Check info w/o restart policy
@ -375,6 +403,7 @@
image: "{{ idem_image }}"
name: idempotency
state: present
podman_socket: "{{ podman_socket | default(omit) }}"
register: test26
- name: Check info with PID
@ -388,6 +417,7 @@
name: idempotency2
state: present
pid: "container:idempotency"
podman_socket: "{{ podman_socket | default(omit) }}"
register: test27
- name: Check info of second container with PID
@ -401,6 +431,7 @@
name: idempotency2
state: present
pid: "container:idempotency"
podman_socket: "{{ podman_socket | default(omit) }}"
register: test28
- name: Check info of second container with PID again
@ -414,6 +445,7 @@
name: idempotency2
state: present
pid: "container:{{ test26.container.Id }}"
podman_socket: "{{ podman_socket | default(omit) }}"
register: test29
- name: Check info of second container with PID of container ID again
@ -590,9 +622,11 @@
executable: "{{ test_executable | default('podman') }}"
name: idempotency2
state: absent
podman_socket: "{{ podman_socket | default(omit) }}"
- name: Remove test container
containers.podman.podman_container:
executable: "{{ test_executable | default('podman') }}"
name: idempotency
state: absent
podman_socket: "{{ podman_socket | default(omit) }}"

View file

@ -3,6 +3,7 @@
executable: "{{ test_executable | default('podman') }}"
name: "idempotency"
state: absent
podman_socket: "{{ podman_socket | default(omit) }}"
- name: Run container with boolean key-value type - 1
containers.podman.podman_container:
@ -11,6 +12,7 @@
image: "{{ idem_image }}"
state: present
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: resultx1
- name: Run container with boolean key-value type - 2
@ -20,6 +22,7 @@
image: "{{ idem_image }}"
state: present
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: resultx2
- name: Run container with boolean key-value type - 3
@ -30,6 +33,7 @@
state: present
command: 1h
tls_verify: false
podman_socket: "{{ podman_socket | default(omit) }}"
register: resultx3
- name: Run container with boolean key-value type - 4
@ -40,6 +44,7 @@
state: present
command: 1h
tls_verify: false
podman_socket: "{{ podman_socket | default(omit) }}"
register: resultx4
- name: Run container with boolean key-value type - 5
@ -50,6 +55,7 @@
state: present
command: 1h
tls_verify: true
podman_socket: "{{ podman_socket | default(omit) }}"
register: resultx5
- name: Run container with boolean key-value type - 6
@ -60,6 +66,7 @@
state: present
command: 1h
tls_verify: true
podman_socket: "{{ podman_socket | default(omit) }}"
register: resultx6
- name: Run container with boolean key-value type - 7
@ -70,6 +77,7 @@
state: present
command: 1h
tls_verify: false
podman_socket: "{{ podman_socket | default(omit) }}"
register: resultx7
- name: Run container with boolean key-value type - 8
@ -80,6 +88,7 @@
state: present
command: 1h
# tls_verify: false
podman_socket: "{{ podman_socket | default(omit) }}"
register: resultx8
- name: Run container with boolean key-value type - 9
@ -90,6 +99,7 @@
state: present
command: 1h
tls_verify: true
podman_socket: "{{ podman_socket | default(omit) }}"
register: resultx9
- name: Run container with boolean key-value type - 10
@ -100,6 +110,7 @@
state: present
command: 1h
# tls_verify: true
podman_socket: "{{ podman_socket | default(omit) }}"
register: resultx10
- name: Assert checks
@ -121,6 +132,7 @@
executable: "{{ test_executable | default('podman') }}"
name: "idempotency"
state: absent
podman_socket: "{{ podman_socket | default(omit) }}"
- name: Run container with list type - 1
containers.podman.podman_container:
@ -133,6 +145,7 @@
- HOME
- TERM
- USER
podman_socket: "{{ podman_socket | default(omit) }}"
register: resultq1
- name: Run container with list type - 2
@ -146,6 +159,7 @@
- HOME
- TERM
- USER
podman_socket: "{{ podman_socket | default(omit) }}"
register: resultq2
- name: Run container with list type - 3
@ -157,6 +171,7 @@
command: 1h
unsetenv:
- HOME
podman_socket: "{{ podman_socket | default(omit) }}"
register: resultq3
- name: Run container with list type - 4
@ -168,6 +183,7 @@
command: 1h
unsetenv:
- HOME
podman_socket: "{{ podman_socket | default(omit) }}"
register: resultq4
- name: Run container with list type - 5
@ -177,6 +193,7 @@
image: "{{ idem_image }}"
state: present
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: resultq5
- name: Run container with list type - 6
@ -186,6 +203,7 @@
image: "{{ idem_image }}"
state: present
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: resultq6
- name: Run container with list type - 7
@ -197,6 +215,7 @@
command: 1h
unsetenv:
- USER
podman_socket: "{{ podman_socket | default(omit) }}"
register: resultq7
- name: Run container with list type - 8
@ -208,6 +227,7 @@
command: 1h
unsetenv:
- USER
podman_socket: "{{ podman_socket | default(omit) }}"
register: resultq8
- name: Run container with list type - 9
@ -217,6 +237,7 @@
image: "{{ idem_image }}"
state: present
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: resultq9
- name: Assert checks
@ -237,6 +258,7 @@
executable: "{{ test_executable | default('podman') }}"
name: "idempotency"
state: absent
podman_socket: "{{ podman_socket | default(omit) }}"
- name: Run container with boolean trigger type - 1
containers.podman.podman_container:
@ -245,6 +267,7 @@
image: "{{ idem_image }}"
state: present
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: resulty1
- name: Run container with boolean trigger type - 2
@ -254,6 +277,7 @@
image: "{{ idem_image }}"
state: present
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: resulty2
- name: Run container with boolean trigger type - 3
@ -264,6 +288,7 @@
state: present
command: 1h
no_healthcheck: false
podman_socket: "{{ podman_socket | default(omit) }}"
register: resulty3
- name: Run container with boolean trigger type - 4
@ -274,6 +299,7 @@
state: present
command: 1h
no_healthcheck: false
podman_socket: "{{ podman_socket | default(omit) }}"
register: resulty4
- name: Run container with boolean trigger type - 5
@ -284,6 +310,7 @@
state: present
command: 1h
no_healthcheck: true
podman_socket: "{{ podman_socket | default(omit) }}"
register: resulty5
- name: Run container with boolean trigger type - 6
@ -294,6 +321,7 @@
state: present
command: 1h
no_healthcheck: true
podman_socket: "{{ podman_socket | default(omit) }}"
register: resulty6
- name: Run container with boolean trigger type - 7
@ -304,6 +332,7 @@
state: present
command: 1h
no_healthcheck: false
podman_socket: "{{ podman_socket | default(omit) }}"
register: resulty7
- name: Run container with boolean trigger type - 8
@ -314,6 +343,7 @@
state: present
command: 1h
# no_healthcheck: false
podman_socket: "{{ podman_socket | default(omit) }}"
register: resulty8
- name: Run container with boolean trigger type - 9
@ -324,6 +354,7 @@
state: present
command: 1h
no_healthcheck: true
podman_socket: "{{ podman_socket | default(omit) }}"
register: resulty9
- name: Run container with boolean trigger type - 10
@ -334,6 +365,7 @@
state: present
command: 1h
# no_healthcheck: true
podman_socket: "{{ podman_socket | default(omit) }}"
register: resulty10
- name: Assert checks
@ -341,12 +373,12 @@
that:
- resulty1.changed == true
- resulty2.changed == false
- resulty3.changed == false
- resulty3.changed == false or podman_socket is defined
- resulty4.changed == false
- resulty5.changed == true
- resulty6.changed == false
- resulty7.changed == true
- resulty8.changed == false
- resulty8.changed == false or podman_socket is defined
- resulty9.changed == true
- resulty10.changed == true
@ -356,6 +388,7 @@
executable: "{{ test_executable | default('podman') }}"
name: "idempotency"
state: absent
podman_socket: "{{ podman_socket | default(omit) }}"
- name: Run container with dict type - 1
containers.podman.podman_container:
@ -368,6 +401,7 @@
max_size: 10m
tag: test
path: /var/log
podman_socket: "{{ podman_socket | default(omit) }}"
register: resultv1
- name: Run container with dict type - 2
@ -381,6 +415,7 @@
max_size: 10m
tag: test
path: /var/log
podman_socket: "{{ podman_socket | default(omit) }}"
register: resultv2
- name: Run container with dict type - 3
@ -392,6 +427,7 @@
command: 1h
log_opt:
max_size: 10m
podman_socket: "{{ podman_socket | default(omit) }}"
register: resultv3
- name: Run container with dict type - 4
@ -403,6 +439,7 @@
command: 1h
log_opt:
max_size: 10m
podman_socket: "{{ podman_socket | default(omit) }}"
register: resultv4
- name: Run container with dict type - 5
@ -412,6 +449,7 @@
image: "{{ idem_image }}"
state: present
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: resultv5
- name: Run container with dict type - 6
@ -421,6 +459,7 @@
image: "{{ idem_image }}"
state: present
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: resultv6
- name: Run container with dict type - 7
@ -432,6 +471,7 @@
command: 1h
log_opt:
tag: test
podman_socket: "{{ podman_socket | default(omit) }}"
register: resultv7
- name: Run container with dict type - 8
@ -443,6 +483,7 @@
command: 1h
log_opt:
tag: test
podman_socket: "{{ podman_socket | default(omit) }}"
register: resultv8
- name: Run container with dict type - 9
@ -452,6 +493,7 @@
image: "{{ idem_image }}"
state: present
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: resultv9
- name: Assert checks

View file

@ -3,6 +3,7 @@
executable: "{{ test_executable | default('podman') }}"
name: idempotency
state: absent
podman_socket: "{{ podman_socket | default(omit) }}"
- containers.podman.podman_container:
executable: "{{ test_executable | default('podman') }}"
@ -10,6 +11,7 @@
name: idempotency
state: started
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
- containers.podman.podman_container:
executable: "{{ test_executable | default('podman') }}"
@ -17,6 +19,7 @@
name: idempotency
state: present
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test1
- name: check test1
@ -32,6 +35,7 @@
key: "amazing value"
nobody: "cares"
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test2
- name: check test2
@ -44,6 +48,7 @@
name: idempotency
state: present
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test3
- name: check test3
@ -61,6 +66,7 @@
OEIWIOP: eufslsa
ieui4: KDJSL4D
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test4
- name: check test4
@ -78,6 +84,7 @@
OEIWIOP: eufslsa
ieui4: KDJSL4D
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test5
- name: check test5
@ -90,6 +97,7 @@
name: idempotency
state: present
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test6
- name: check test6
@ -104,6 +112,7 @@
label:
test: notest
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test7
- name: check test7
@ -119,6 +128,7 @@
key: "amazing value"
nobody: "cares"
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test8
- name: check test8
@ -131,6 +141,7 @@
name: idempotency
state: present
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test9
- name: check test9
@ -141,6 +152,7 @@
executable: "{{ test_executable | default('podman') }}"
name: idempotency1
state: absent
podman_socket: "{{ podman_socket | default(omit) }}"
- containers.podman.podman_container:
executable: "{{ test_executable | default('podman') }}"
@ -148,6 +160,7 @@
name: idempotency1
state: present
command: sleep 1h
podman_socket: "{{ podman_socket | default(omit) }}"
- containers.podman.podman_container:
executable: "{{ test_executable | default('podman') }}"
@ -155,6 +168,7 @@
name: idempotency1
state: present
command: sleep 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test10
- name: check test10
@ -169,6 +183,7 @@
label:
razraz: dva
command: sleep 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test11
- name: check test11
@ -181,6 +196,7 @@
name: idempotency1
state: present
command: sleep 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test12
- name: check test12
@ -193,6 +209,7 @@
name: idempotency1
state: present
command: sleep 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test13
- name: check test13

View file

@ -3,6 +3,7 @@
executable: "{{ test_executable | default('podman') }}"
name: netcontainer
state: absent
podman_socket: "{{ podman_socket | default(omit) }}"
- name: Run container with {{ item.first_net }}
containers.podman.podman_container:
@ -12,6 +13,7 @@
command: 1h
state: started
network: "{{ item.first_net }}"
podman_socket: "{{ podman_socket | default(omit) }}"
- name: Run container again with {{ item.first_net }}
containers.podman.podman_container:
@ -21,6 +23,7 @@
command: 1h
state: present
network: "{{ item.first_net }}"
podman_socket: "{{ podman_socket | default(omit) }}"
register: info
- name: Check info for 2 runs of {{ item.first_net }}
@ -36,6 +39,7 @@
command: 1h
state: present
network: "{{ item.next_net }}"
podman_socket: "{{ podman_socket | default(omit) }}"
register: info1
- name: Check info

View file

@ -9,6 +9,7 @@
executable: "{{ test_executable | default('podman') }}"
name: testpod_container1
state: absent
podman_socket: "{{ podman_socket | default(omit) }}"
- name: Create pod
containers.podman.podman_pod:
@ -30,6 +31,7 @@
test: test2
volumes:
- /tmp:/data
podman_socket: "{{ podman_socket | default(omit) }}"
- name: Start test container again
containers.podman.podman_container:
@ -44,6 +46,7 @@
test: test2
volumes:
- /tmp:/data
podman_socket: "{{ podman_socket | default(omit) }}"
register: info
- name: Check starting container
@ -57,6 +60,7 @@
name: testpod_container1
pod: testpod
state: started
podman_socket: "{{ podman_socket | default(omit) }}"
register: info1
- name: Check starting container changed
@ -70,6 +74,7 @@
name: testpod_container1
pod: testpod
state: started
podman_socket: "{{ podman_socket | default(omit) }}"
register: info2
- name: Check starting container again

View file

@ -3,6 +3,7 @@
executable: "{{ test_executable | default('podman') }}"
name: idempotency
state: absent
podman_socket: "{{ podman_socket | default(omit) }}"
- containers.podman.podman_container:
executable: "{{ test_executable | default('podman') }}"
@ -10,6 +11,7 @@
name: idempotency
state: started
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
- containers.podman.podman_container:
executable: "{{ test_executable | default('podman') }}"
@ -17,6 +19,7 @@
name: idempotency
state: present
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test1
- name: check test1
@ -45,6 +48,7 @@
- 0.0.0.0:20000-20010:20000-20010/tcp
- "10000-10010:10000-10010/udp"
- "[::1]:3001-3003:3001-3003"
podman_socket: "{{ podman_socket | default(omit) }}"
register: test2
- name: check test2
@ -73,6 +77,7 @@
- 0.0.0.0:20000-20010:20000-20010/tcp
- "10000-10010:10000-10010/udp"
- "[::1]:3001-3003:3001-3003"
podman_socket: "{{ podman_socket | default(omit) }}"
register: test3
- name: check test3
@ -86,6 +91,7 @@
state: present
publish_all: true
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test4
- name: check test4
@ -99,6 +105,7 @@
state: present
publish_all: true
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test5
- name: check test5
@ -111,6 +118,7 @@
name: idempotency
state: present
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test6
- name: check test6
@ -125,6 +133,7 @@
ports:
- 10000:8080
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test7
- name: check test7
@ -139,6 +148,7 @@
ports:
- 10001:8080
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test8
- name: check test8
@ -153,6 +163,7 @@
ports:
- 10001:8080/tcp
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test9
- name: check test9
@ -168,6 +179,7 @@
- 10001:8080/tcp
publish_all: false
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test9a
- name: check test9a
@ -180,6 +192,7 @@
name: idempotency
state: present
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test9b
- name: check test9b
@ -190,6 +203,7 @@
executable: "{{ test_executable | default('podman') }}"
name: idempotency1
state: absent
podman_socket: "{{ podman_socket | default(omit) }}"
- containers.podman.podman_container:
executable: "{{ test_executable | default('podman') }}"
@ -197,6 +211,7 @@
name: idempotency1
state: present
command: sleep 1h
podman_socket: "{{ podman_socket | default(omit) }}"
- containers.podman.podman_container:
executable: "{{ test_executable | default('podman') }}"
@ -204,6 +219,7 @@
name: idempotency1
state: present
command: sleep 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test10
- name: check test10
@ -217,6 +233,7 @@
state: present
publish_all: false
command: sleep 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test11
- name: check test11
@ -230,6 +247,7 @@
state: present
publish_all: true
command: sleep 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test11a
- name: check test11a
@ -244,6 +262,7 @@
ports:
- 10000:8080
command: sleep 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test12
- name: check test12
@ -256,6 +275,7 @@
name: idempotency1
state: present
command: sleep 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test13
- name: check test13
@ -268,6 +288,7 @@
name: idempotency1
state: present
command: sleep 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test14
- name: check test14

View file

@ -3,6 +3,7 @@
executable: "{{ test_executable | default('podman') }}"
name: idempotency
state: absent
podman_socket: "{{ podman_socket | default(omit) }}"
- containers.podman.podman_container:
executable: "{{ test_executable | default('podman') }}"
@ -10,6 +11,7 @@
name: idempotency
state: started
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
- containers.podman.podman_container:
executable: "{{ test_executable | default('podman') }}"
@ -17,6 +19,7 @@
name: idempotency
state: present
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test1
- name: check test1
@ -30,6 +33,7 @@
state: present
stop_signal: 9
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test2
- name: check test2
@ -55,6 +59,7 @@
name: idempotency
state: present
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test3
- name: check test3
@ -68,6 +73,7 @@
state: present
stop_signal: 10
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test4
- name: check test4
@ -81,6 +87,7 @@
state: present
stop_signal: 10
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test5
- name: check test5
@ -93,6 +100,7 @@
name: idempotency
state: present
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test6
- name: check test6
@ -106,6 +114,7 @@
state: present
stop_signal: 15
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test7
- name: check test7
@ -119,6 +128,7 @@
state: present
stop_signal: 9
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test8
- name: check test8
@ -131,6 +141,7 @@
name: idempotency
state: present
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test9
- name: check test9
@ -144,6 +155,7 @@
state: present
stop_signal: 15
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test9a
- name: check test9a
@ -156,6 +168,7 @@
name: idempotency
state: present
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test9b
- name: check test9b
@ -166,6 +179,7 @@
executable: "{{ test_executable | default('podman') }}"
name: idempotency1
state: absent
podman_socket: "{{ podman_socket | default(omit) }}"
- containers.podman.podman_container:
executable: "{{ test_executable | default('podman') }}"
@ -173,6 +187,7 @@
name: idempotency1
state: present
command: sleep 1h
podman_socket: "{{ podman_socket | default(omit) }}"
- containers.podman.podman_container:
executable: "{{ test_executable | default('podman') }}"
@ -180,6 +195,7 @@
name: idempotency1
state: present
command: sleep 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test10
- name: check test10
@ -193,6 +209,7 @@
state: present
stop_signal: 15
command: sleep 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test11
- name: check test11
@ -206,6 +223,7 @@
state: present
stop_signal: 10
command: sleep 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test12
- name: check test12
@ -218,6 +236,7 @@
name: idempotency1
state: present
command: sleep 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test13
- name: check test13
@ -230,6 +249,7 @@
name: idempotency1
state: present
command: sleep 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test14
- name: check test14

View file

@ -3,6 +3,7 @@
executable: "{{ test_executable | default('podman') }}"
name: idempotency
state: absent
podman_socket: "{{ podman_socket | default(omit) }}"
- containers.podman.podman_container:
executable: "{{ test_executable | default('podman') }}"
@ -10,6 +11,7 @@
name: idempotency
state: started
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
- containers.podman.podman_container:
executable: "{{ test_executable | default('podman') }}"
@ -17,6 +19,7 @@
name: idempotency
state: present
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test1
- name: check test1
@ -30,6 +33,7 @@
state: present
user: user
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test2
- name: check test2
@ -42,6 +46,7 @@
name: idempotency
state: present
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test3
- name: check test3
@ -55,6 +60,7 @@
state: present
user: user2
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test4
- name: check test4
@ -68,6 +74,7 @@
state: present
user: user2
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test5
- name: check test5
@ -80,6 +87,7 @@
name: idempotency
state: present
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test6
- name: check test6
@ -93,6 +101,7 @@
state: present
user: user2
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test7
- name: check test7
@ -106,6 +115,7 @@
state: present
user: user
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test8
- name: check test8
@ -118,6 +128,7 @@
name: idempotency
state: present
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test9
- name: check test9
@ -128,6 +139,7 @@
executable: "{{ test_executable | default('podman') }}"
name: idempotency1
state: absent
podman_socket: "{{ podman_socket | default(omit) }}"
- containers.podman.podman_container:
executable: "{{ test_executable | default('podman') }}"
@ -142,6 +154,7 @@
name: idempotency1
state: present
command: sleep 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test10
- name: check test10
@ -155,6 +168,7 @@
state: present
user: nobody
command: sleep 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test11
- name: check test11
@ -167,6 +181,7 @@
name: idempotency1
state: present
command: sleep 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test12
- name: check test12
@ -179,6 +194,7 @@
name: idempotency1
state: present
command: sleep 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test13
- name: check test13

View file

@ -3,6 +3,7 @@
executable: "{{ test_executable | default('podman') }}"
name: idempotency
state: absent
podman_socket: "{{ podman_socket | default(omit) }}"
- containers.podman.podman_container:
executable: "{{ test_executable | default('podman') }}"
@ -10,6 +11,7 @@
name: idempotency
state: started
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
- containers.podman.podman_container:
executable: "{{ test_executable | default('podman') }}"
@ -17,6 +19,7 @@
name: idempotency
state: present
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test1
- name: check test1
@ -29,6 +32,7 @@
name: idempotency
state: present
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test2
- name: check test2
@ -41,6 +45,7 @@
name: idempotency
state: present
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test3
- name: check test3
@ -55,6 +60,7 @@
volumes:
- /opt:/somedir/
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test4
- name: check test4
@ -69,6 +75,7 @@
volumes:
- /opt/://somedir/
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test5
- name: check test5
@ -81,6 +88,7 @@
name: idempotency
state: present
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test6
- name: check test6
@ -96,6 +104,7 @@
- /opt:/somedir
- /data
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test7
- name: check test7
@ -110,6 +119,7 @@
volumes:
- /data
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test8
- name: check test8
@ -122,6 +132,7 @@
name: idempotency
state: present
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test9
- name: check test9
@ -142,6 +153,7 @@
volumes:
- "/opt:/anotherdir"
- "local_volume1:/data"
podman_socket: "{{ podman_socket | default(omit) }}"
register: test10
- name: check test10
@ -157,6 +169,7 @@
volumes:
- "/opt//:/anotherdir"
- "local_volume1:/data/"
podman_socket: "{{ podman_socket | default(omit) }}"
register: test11
- name: check test11
@ -172,6 +185,7 @@
volumes:
- "/opt:/anotherdir"
- "local_volume2:/data"
podman_socket: "{{ podman_socket | default(omit) }}"
register: test12
- name: check test12
@ -186,6 +200,7 @@
command: 1h
volumes:
- "/opt:/anotherdir"
podman_socket: "{{ podman_socket | default(omit) }}"
register: test13
- name: check test13
@ -196,6 +211,7 @@
executable: "{{ test_executable | default('podman') }}"
name: idempotency1
state: absent
podman_socket: "{{ podman_socket | default(omit) }}"
- containers.podman.podman_container:
executable: "{{ test_executable | default('podman') }}"
@ -203,6 +219,7 @@
name: idempotency1
state: present
command: sleep 1h
podman_socket: "{{ podman_socket | default(omit) }}"
- containers.podman.podman_container:
executable: "{{ test_executable | default('podman') }}"
@ -210,6 +227,7 @@
name: idempotency1
state: present
command: sleep 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test14
- name: check test14
@ -224,6 +242,7 @@
volumes:
- /opt:/data
command: sleep 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test15
- name: check test15
@ -236,6 +255,7 @@
name: idempotency1
state: present
command: sleep 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test16
- name: check test16
@ -248,6 +268,7 @@
name: idempotency1
state: present
command: sleep 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test17
- name: check test17

View file

@ -3,6 +3,7 @@
executable: "{{ test_executable | default('podman') }}"
name: idempotency
state: absent
podman_socket: "{{ podman_socket | default(omit) }}"
- containers.podman.podman_container:
executable: "{{ test_executable | default('podman') }}"
@ -10,6 +11,7 @@
name: idempotency
state: started
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
- containers.podman.podman_container:
executable: "{{ test_executable | default('podman') }}"
@ -17,6 +19,7 @@
name: idempotency
state: present
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test1
- name: check test1
@ -30,6 +33,7 @@
state: present
workdir: /work
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test2
- name: check test2
@ -43,6 +47,7 @@
state: present
workdir: /work
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test3
- name: check test3
@ -56,6 +61,7 @@
state: present
workdir: /var
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test4
- name: check test4
@ -69,6 +75,7 @@
state: present
workdir: /var
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test5
- name: check test5
@ -81,6 +88,7 @@
name: idempotency
state: present
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test6
- name: check test6
@ -94,6 +102,7 @@
state: present
workdir: /var
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test7
- name: check test7
@ -107,6 +116,7 @@
state: present
workdir: /work
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test8
- name: check test8
@ -119,6 +129,7 @@
name: idempotency
state: present
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test9
- name: check test9
@ -132,6 +143,7 @@
state: present
workdir: /
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test9a
- name: check test9a
@ -144,6 +156,7 @@
name: idempotency
state: present
command: 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test9b
- name: check test9b
@ -154,6 +167,7 @@
executable: "{{ test_executable | default('podman') }}"
name: idempotency1
state: absent
podman_socket: "{{ podman_socket | default(omit) }}"
- containers.podman.podman_container:
executable: "{{ test_executable | default('podman') }}"
@ -161,6 +175,7 @@
name: idempotency1
state: present
command: sleep 1h
podman_socket: "{{ podman_socket | default(omit) }}"
- containers.podman.podman_container:
executable: "{{ test_executable | default('podman') }}"
@ -168,6 +183,7 @@
name: idempotency1
state: present
command: sleep 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test10
- name: check test10
@ -181,6 +197,7 @@
state: present
workdir: /
command: sleep 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test11
- name: check test11
@ -194,6 +211,7 @@
state: present
workdir: /var
command: sleep 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test12
- name: check test12
@ -206,6 +224,7 @@
name: idempotency1
state: present
command: sleep 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test13
- name: check test13
@ -218,6 +237,7 @@
name: idempotency1
state: present
command: sleep 1h
podman_socket: "{{ podman_socket | default(omit) }}"
register: test14
- name: check test14

View file

@ -6,12 +6,13 @@
executable: "{{ test_executable | default('podman') }}"
name: netcontainer
state: absent
podman_socket: "{{ podman_root_socket | default(omit) }}"
- name: Create network testnet
command: podman network create testnet --subnet 10.92.92.0/24
shell: podman network exists testnet || podman network create testnet --subnet 10.92.92.0/24
- name: Create network anothernet
command: podman network create anothernet --subnet 10.72.72.0/24
shell: podman network exists anothernet || podman network create anothernet --subnet 10.72.72.0/24
- name: List current networks
command: podman network ls
@ -64,6 +65,7 @@
executable: "{{ test_executable | default('podman') }}"
name: netcontainer
state: absent
podman_socket: "{{ podman_root_socket | default(omit) }}"
- name: Delete all network leftovers from tests
shell: |

View file

@ -5,6 +5,7 @@
executable: "{{ test_executable | default('podman') }}"
name: root-idempotency
state: absent
podman_socket: "{{ podman_root_socket | default(omit) }}"
- name: Run container as is
containers.podman.podman_container:
@ -13,6 +14,7 @@
name: root-idempotency
state: started
command: 1h
podman_socket: "{{ podman_root_socket | default(omit) }}"
- name: Run container as is again
containers.podman.podman_container:
@ -21,6 +23,7 @@
name: root-idempotency
state: present
command: 1h
podman_socket: "{{ podman_root_socket | default(omit) }}"
register: info_a
- name: Check that it is not recreated
@ -38,6 +41,7 @@
ulimit:
- 'nofile=55535:55535'
- 'memlock=-1:-1'
podman_socket: "{{ podman_root_socket | default(omit) }}"
register: info
- name: Check that it is recreated
@ -55,6 +59,7 @@
ulimit:
- 'nofile=55535:55535'
- 'memlock=-1:-1'
podman_socket: "{{ podman_root_socket | default(omit) }}"
register: info1
- name: Check that it is recreated
@ -72,6 +77,7 @@
ulimit:
- 'nofile=55535:65535'
- 'memlock=-1:-1'
podman_socket: "{{ podman_root_socket | default(omit) }}"
register: info2
- name: Check that it is recreated
@ -89,6 +95,7 @@
ulimit:
- 'nofile=55535:65535'
- 'memlock=-1:-1'
podman_socket: "{{ podman_root_socket | default(omit) }}"
register: info3
- name: Check that it is recreated
@ -103,6 +110,7 @@
name: root-idempotency
state: started
command: 1h
podman_socket: "{{ podman_root_socket | default(omit) }}"
- name: Run containers with MAC address
containers.podman.podman_container:
@ -112,6 +120,7 @@
state: started
command: 1h
mac_address: 44:55:66:77:88:99
podman_socket: "{{ podman_root_socket | default(omit) }}"
register: info4
- name: Check that it is not recreated
@ -128,6 +137,7 @@
state: present
command: 1h
mac_address: 44:55:66:77:88:99
podman_socket: "{{ podman_root_socket | default(omit) }}"
register: info5
- name: Check that it is not recreated
@ -143,6 +153,7 @@
state: present
command: 1h
mac_address: 44:55:66:77:88:33
podman_socket: "{{ podman_root_socket | default(omit) }}"
register: info6
- name: Check that it is recreated
@ -157,6 +168,7 @@
name: root-idempotency
state: present
command: 1h
podman_socket: "{{ podman_root_socket | default(omit) }}"
register: info7
- name: Check that it is recreated
@ -179,6 +191,7 @@
- "127.0.0.3:43423:8872"
- "[::1]:34523:35425"
- "40001-40010"
podman_socket: "{{ podman_root_socket | default(omit) }}"
register: info8
- name: Check that it is recreated
@ -201,6 +214,7 @@
- "127.0.0.3:43423:8872"
- "[::1]:34523:35425"
- "40001-40010"
podman_socket: "{{ podman_root_socket | default(omit) }}"
register: info9
- name: Check that it is recreated
@ -213,3 +227,4 @@
executable: "{{ test_executable | default('podman') }}"
name: root-idempotency
state: absent
podman_socket: "{{ podman_root_socket | default(omit) }}"

View file

@ -6,12 +6,14 @@
executable: "{{ test_executable | default('podman') }}"
name: rootlessnet2
state: absent
podman_socket: "{{ podman_socket | default(omit) }}"
- name: Remove container rootlessnet
containers.podman.podman_container:
executable: "{{ test_executable | default('podman') }}"
name: rootlessnet
state: absent
podman_socket: "{{ podman_socket | default(omit) }}"
- name: Run container with no specified networks
containers.podman.podman_container:
@ -20,6 +22,7 @@
image: "{{ idem_image }}"
command: 1h
state: started
podman_socket: "{{ podman_socket | default(omit) }}"
- name: Run container again with no specified networks
containers.podman.podman_container:
@ -28,6 +31,7 @@
image: "{{ idem_image }}"
command: 1h
state: present
podman_socket: "{{ podman_socket | default(omit) }}"
register: info
- name: Check info for no specified networks
@ -43,6 +47,7 @@
command: 1h
state: present
network: host
podman_socket: "{{ podman_socket | default(omit) }}"
register: info1
- name: Check info with network mode host
@ -58,6 +63,7 @@
command: 1h
state: present
network: host
podman_socket: "{{ podman_socket | default(omit) }}"
register: info2
- name: Check info with network mode host again
@ -73,6 +79,7 @@
command: 1h
state: present
network: none
podman_socket: "{{ podman_socket | default(omit) }}"
register: info3
- name: Check info without network at all
@ -88,6 +95,7 @@
command: 1h
state: present
network: none
podman_socket: "{{ podman_socket | default(omit) }}"
register: info4
- name: Check info without network at all again
@ -102,6 +110,7 @@
image: "{{ idem_image }}"
command: 1h
state: present
podman_socket: "{{ podman_socket | default(omit) }}"
register: info5
- name: Check info with default network mode
@ -121,12 +130,14 @@
state: present
network:
- slirp4netns:allow_host_loopback=true,cidr=10.0.3.0/24
podman_socket: "{{ podman_socket | default(omit) }}"
register: info6
- name: Check info with slirp4netns options
assert:
that:
- info6 is changed
when: podman_socket is not defined
- name: Run container with slirp4netns options - again
containers.podman.podman_container:
@ -137,6 +148,7 @@
state: present
network:
- slirp4netns:allow_host_loopback=true,cidr=10.0.3.0/24
podman_socket: "{{ podman_socket | default(omit) }}"
register: info7
- name: Check info with slirp4netns options - again
@ -153,12 +165,14 @@
state: present
network:
- slirp4netns:allow_host_loopback=true,cidr=10.0.4.0/24
podman_socket: "{{ podman_socket | default(omit) }}"
register: info8
- name: Check info with different slirp4netns options
assert:
that:
- info8 is changed
when: podman_socket is not defined
- when: podman_version | int >= 5
@ -173,6 +187,7 @@
state: present
network:
- "pasta:-4,-t,8007,-u,4443,-T,3000"
podman_socket: "{{ podman_socket | default(omit) }}"
register: info6
- name: Check info with pasta options
@ -189,6 +204,7 @@
state: present
network:
- "pasta:-4,-t,8007,-u,4443,-T,3000"
podman_socket: "{{ podman_socket | default(omit) }}"
register: info7
- name: Check info with pasta options - again
@ -205,6 +221,7 @@
state: present
network:
- "pasta:-4,-t,8008,-u,4443,-T,3000"
podman_socket: "{{ podman_socket | default(omit) }}"
register: info8
- name: Check info with different pasta options
@ -219,12 +236,14 @@
image: "{{ idem_image }}"
command: 1h
state: present
podman_socket: "{{ podman_socket | default(omit) }}"
register: info9
- name: Check info without options
assert:
that:
- info9 is changed
when: podman_socket is not defined
- name: Run container without options - again
containers.podman.podman_container:
@ -233,6 +252,7 @@
image: "{{ idem_image }}"
command: 1h
state: present
podman_socket: "{{ podman_socket | default(omit) }}"
register: info10
- name: Check info without options - again
@ -248,12 +268,15 @@
command: 1h
state: started
network: 'container:rootlessnet'
podman_socket: "{{ podman_socket | default(omit) }}"
register: info11
when: podman_socket is not defined
- name: Check info container network attached to first one
assert:
that:
- info11 is changed
when: podman_socket is not defined
- name: Run container network attached to first one - again
containers.podman.podman_container:
@ -263,12 +286,16 @@
command: 1h
state: started
network: 'container:rootlessnet'
podman_socket: "{{ podman_socket | default(omit) }}"
register: info12
when: podman_socket is not defined
- name: Check info container network attached to first one - again
assert:
that:
- info12 is not changed
when: podman_socket is not defined
always:
- name: Delete all containers leftovers from tests
@ -276,9 +303,11 @@
executable: "{{ test_executable | default('podman') }}"
name: rootlessnet2
state: absent
podman_socket: "{{ podman_socket | default(omit) }}"
- name: Delete all containers leftovers from tests 2
containers.podman.podman_container:
executable: "{{ test_executable | default('podman') }}"
name: rootlessnet
state: absent
podman_socket: "{{ podman_socket | default(omit) }}"

View file

@ -10,11 +10,13 @@
executable: "{{ test_executable | default('podman') }}"
name: "{{ container_name }}"
state: absent
podman_socket: "{{ podman_socket | default(omit) }}"
- name: Get missing container info
containers.podman.podman_container_info:
executable: "{{ test_executable | default('podman') }}"
name: "{{ container_name }}"
podman_socket: "{{ podman_socket | default(omit) }}"
register: nonexist
- name: Check results of missing container info
@ -31,6 +33,7 @@
- "{{ container_name }}"
- neverexist
- whatever
podman_socket: "{{ podman_socket | default(omit) }}"
register: nonexist2
ignore_errors: true
@ -48,6 +51,7 @@
containers.podman.podman_container_info:
executable: "{{ test_executable | default('podman') }}"
name: "{{ container_name }}"
podman_socket: "{{ podman_socket | default(omit) }}"
register: existing_container
- name: Get mixed existing and non-existing container info
@ -56,10 +60,12 @@
name:
- "{{ container_name }}"
- whatever
podman_socket: "{{ podman_socket | default(omit) }}"
register: mixed_existing_container
- name: Get all containers info
containers.podman.podman_container_info:
podman_socket: "{{ podman_socket | default(omit) }}"
executable: "{{ test_executable | default('podman') }}"
register: all_containers
@ -79,6 +85,7 @@
executable: "{{ test_executable | default('podman') }}"
name: "{{ container_name }}"
state: absent
podman_socket: "{{ podman_socket | default(omit) }}"
- name: Make checks
# https://github.com/containers/podman/issues/9490
@ -99,3 +106,4 @@
executable: "{{ test_executable | default('podman') }}"
name: "{{ container_name }}"
state: absent
podman_socket: "{{ podman_socket | default(omit) }}"