Add extra args and executable name to podman connection plugin (#63166)

* Add extra args and executable name to podman connection plugin

Like there is for docker plugin, add extra arguments for command
line of podman. Also add configurable executable and checking if
this executable exists on host. Fail module if executable is not
in PATH.

* Update changelogs/fragments/63166-add-extra-args-executalbe-podman-connection.yaml

Co-Authored-By: Felix Fontein <felix@fontein.de>
pull/63669/head
Sergey 5 years ago committed by Abhijeet Kasurde
parent b6ea43efc3
commit e3c7e35656

@ -0,0 +1,2 @@
minor_changes:
- podman connection - allow to add extra arguments to podman command and to configure the executable.

@ -10,6 +10,7 @@
from __future__ import (absolute_import, division, print_function) from __future__ import (absolute_import, division, print_function)
__metaclass__ = type __metaclass__ = type
import distutils.spawn
import shlex import shlex
import shutil import shutil
import subprocess import subprocess
@ -48,6 +49,25 @@ DOCUMENTATION = """
- name: ANSIBLE_REMOTE_USER - name: ANSIBLE_REMOTE_USER
vars: vars:
- name: ansible_user - name: ansible_user
podman_extra_args:
description:
- Extra arguments to pass to the podman command line.
default: ''
ini:
- section: defaults
key: podman_extra_args
vars:
- name: ansible_podman_extra_args
env:
- name: ANSIBLE_PODMAN_EXTRA_ARGS
podman_executable:
description:
- Executable for podman command.
default: podman
vars:
- name: ansible_podman_executable
env:
- name: ANSIBLE_PODMAN_EXECUTABLE
""" """
@ -79,7 +99,17 @@ class Connection(ConnectionBase):
:param in_data: data passed to podman's stdin :param in_data: data passed to podman's stdin
:return: return code, stdout, stderr :return: return code, stdout, stderr
""" """
local_cmd = ['podman', cmd] podman_exec = self.get_option('podman_executable')
podman_cmd = distutils.spawn.find_executable(podman_exec)
if not podman_cmd:
raise AnsibleError("%s command not found in PATH" % podman_exec)
local_cmd = [podman_cmd]
if self.get_option('podman_extra_args'):
local_cmd += shlex.split(
to_native(
self.get_option('podman_extra_args'),
errors='surrogate_or_strict'))
local_cmd.append(cmd)
if use_container_id: if use_container_id:
local_cmd.append(self._container_id) local_cmd.append(self._container_id)
if cmd_args: if cmd_args:

@ -5,3 +5,10 @@ set -eux
./posix.sh "$@" ./posix.sh "$@"
ANSIBLE_REMOTE_TMP="/tmp" ANSIBLE_REMOTE_USER="1000" ./posix.sh "$@" ANSIBLE_REMOTE_TMP="/tmp" ANSIBLE_REMOTE_USER="1000" ./posix.sh "$@"
ANSIBLE_PODMAN_EXECUTABLE=fakepodman ./posix.sh "$@" 2>&1 | grep "fakepodman command not found in PATH"
ANSIBLE_PODMAN_EXECUTABLE=fakepodman ./posix.sh "$@" && {
echo "Playbook with fakepodman should fail!"
exit 1
}
ANSIBLE_VERBOSITY=4 ANSIBLE_PODMAN_EXTRA_ARGS=" --log-level debug " ./posix.sh "$@" | grep "level=debug msg="

Loading…
Cancel
Save