mirror of
https://github.com/containers/ansible-podman-collections.git
synced 2026-02-04 07:11:49 +00:00
Run black -l 120 on all Python files to unify the style (#939)
Signed-off-by: Sagi Shnaidman <sshnaidm@redhat.com>
This commit is contained in:
parent
50c5a2549d
commit
4c682e170c
39 changed files with 3828 additions and 3129 deletions
|
|
@ -4,9 +4,10 @@
|
|||
# Copyright (c) 2023, Takuya Nishimura <@nishipy>
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
from __future__ import absolute_import, division, print_function
|
||||
|
||||
__metaclass__ = type
|
||||
|
||||
DOCUMENTATION = r'''
|
||||
DOCUMENTATION = r"""
|
||||
module: podman_container_exec
|
||||
author:
|
||||
- Takuya Nishimura (@nishipy)
|
||||
|
|
@ -68,9 +69,9 @@ requirements:
|
|||
- podman
|
||||
notes:
|
||||
- See L(the Podman documentation,https://docs.podman.io/en/latest/markdown/podman-exec.1.html) for details of podman-exec(1).
|
||||
'''
|
||||
"""
|
||||
|
||||
EXAMPLES = r'''
|
||||
EXAMPLES = r"""
|
||||
- name: Execute a command with workdir
|
||||
containers.podman.podman_container_exec:
|
||||
name: ubi8
|
||||
|
|
@ -93,9 +94,9 @@ EXAMPLES = r'''
|
|||
name: detach_container
|
||||
command: "cat redhat-release"
|
||||
detach: true
|
||||
'''
|
||||
"""
|
||||
|
||||
RETURN = r'''
|
||||
RETURN = r"""
|
||||
stdout:
|
||||
type: str
|
||||
returned: success
|
||||
|
|
@ -118,65 +119,65 @@ exec_id:
|
|||
sample: f99002e34c1087fd1aa08d5027e455bf7c2d6b74f019069acf6462a96ddf2a47
|
||||
description:
|
||||
- The ID of the exec session.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
import shlex
|
||||
from ansible.module_utils.six import string_types
|
||||
from ansible.module_utils._text import to_text
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible_collections.containers.podman.plugins.module_utils.podman.common import run_podman_command
|
||||
from ansible_collections.containers.podman.plugins.module_utils.podman.common import (
|
||||
run_podman_command,
|
||||
)
|
||||
|
||||
|
||||
def run_container_exec(module: AnsibleModule) -> dict:
|
||||
'''
|
||||
"""
|
||||
Execute podman-container-exec for the given options
|
||||
'''
|
||||
exec_with_args = ['container', 'exec']
|
||||
"""
|
||||
exec_with_args = ["container", "exec"]
|
||||
# podman_container_exec always returns changed=true
|
||||
changed = True
|
||||
exec_options = []
|
||||
|
||||
name = module.params['name']
|
||||
argv = module.params['argv']
|
||||
command = module.params['command']
|
||||
detach = module.params['detach']
|
||||
env = module.params['env']
|
||||
privileged = module.params['privileged']
|
||||
tty = module.params['tty']
|
||||
user = module.params['user']
|
||||
workdir = module.params['workdir']
|
||||
executable = module.params['executable']
|
||||
name = module.params["name"]
|
||||
argv = module.params["argv"]
|
||||
command = module.params["command"]
|
||||
detach = module.params["detach"]
|
||||
env = module.params["env"]
|
||||
privileged = module.params["privileged"]
|
||||
tty = module.params["tty"]
|
||||
user = module.params["user"]
|
||||
workdir = module.params["workdir"]
|
||||
executable = module.params["executable"]
|
||||
|
||||
if command is not None:
|
||||
argv = shlex.split(command)
|
||||
|
||||
if detach:
|
||||
exec_options.append('--detach')
|
||||
exec_options.append("--detach")
|
||||
|
||||
if env is not None:
|
||||
for key, value in env.items():
|
||||
if not isinstance(value, string_types):
|
||||
module.fail_json(
|
||||
msg="Specify string value %s on the env field" % (value))
|
||||
msg="Specify string value %s on the env field" % (value)
|
||||
)
|
||||
|
||||
to_text(value, errors='surrogate_or_strict')
|
||||
exec_options += ['--env',
|
||||
'%s=%s' % (key, value)]
|
||||
to_text(value, errors="surrogate_or_strict")
|
||||
exec_options += ["--env", "%s=%s" % (key, value)]
|
||||
|
||||
if privileged:
|
||||
exec_options.append('--privileged')
|
||||
exec_options.append("--privileged")
|
||||
|
||||
if tty:
|
||||
exec_options.append('--tty')
|
||||
exec_options.append("--tty")
|
||||
|
||||
if user is not None:
|
||||
exec_options += ['--user',
|
||||
to_text(user, errors='surrogate_or_strict')]
|
||||
exec_options += ["--user", to_text(user, errors="surrogate_or_strict")]
|
||||
|
||||
if workdir is not None:
|
||||
exec_options += ['--workdir',
|
||||
to_text(workdir, errors='surrogate_or_strict')]
|
||||
exec_options += ["--workdir", to_text(workdir, errors="surrogate_or_strict")]
|
||||
|
||||
exec_options.append(name)
|
||||
exec_options.extend(argv)
|
||||
|
|
@ -184,71 +185,72 @@ def run_container_exec(module: AnsibleModule) -> dict:
|
|||
exec_with_args.extend(exec_options)
|
||||
|
||||
rc, stdout, stderr = run_podman_command(
|
||||
module=module, executable=executable, args=exec_with_args, ignore_errors=True)
|
||||
module=module, executable=executable, args=exec_with_args, ignore_errors=True
|
||||
)
|
||||
|
||||
result = {
|
||||
'changed': changed,
|
||||
'podman_command': exec_options,
|
||||
'rc': rc,
|
||||
'stdout': stdout,
|
||||
'stderr': stderr,
|
||||
"changed": changed,
|
||||
"podman_command": exec_options,
|
||||
"rc": rc,
|
||||
"stdout": stdout,
|
||||
"stderr": stderr,
|
||||
}
|
||||
|
||||
if detach:
|
||||
result['exec_id'] = stdout.replace('\n', '')
|
||||
result["exec_id"] = stdout.replace("\n", "")
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def main():
|
||||
argument_spec = {
|
||||
'name': {
|
||||
'type': 'str',
|
||||
'required': True,
|
||||
"name": {
|
||||
"type": "str",
|
||||
"required": True,
|
||||
},
|
||||
'command': {
|
||||
'type': 'str',
|
||||
"command": {
|
||||
"type": "str",
|
||||
},
|
||||
'argv': {
|
||||
'type': 'list',
|
||||
'elements': 'str',
|
||||
"argv": {
|
||||
"type": "list",
|
||||
"elements": "str",
|
||||
},
|
||||
'detach': {
|
||||
'type': 'bool',
|
||||
'default': False,
|
||||
"detach": {
|
||||
"type": "bool",
|
||||
"default": False,
|
||||
},
|
||||
'executable': {
|
||||
'type': 'str',
|
||||
'default': 'podman',
|
||||
"executable": {
|
||||
"type": "str",
|
||||
"default": "podman",
|
||||
},
|
||||
'env': {
|
||||
'type': 'dict',
|
||||
"env": {
|
||||
"type": "dict",
|
||||
},
|
||||
'privileged': {
|
||||
'type': 'bool',
|
||||
'default': False,
|
||||
"privileged": {
|
||||
"type": "bool",
|
||||
"default": False,
|
||||
},
|
||||
'tty': {
|
||||
'type': 'bool',
|
||||
'default': False,
|
||||
"tty": {
|
||||
"type": "bool",
|
||||
"default": False,
|
||||
},
|
||||
'user': {
|
||||
'type': 'str',
|
||||
"user": {
|
||||
"type": "str",
|
||||
},
|
||||
'workdir': {
|
||||
'type': 'str',
|
||||
"workdir": {
|
||||
"type": "str",
|
||||
},
|
||||
}
|
||||
|
||||
module = AnsibleModule(
|
||||
argument_spec=argument_spec,
|
||||
supports_check_mode=True,
|
||||
required_one_of=[('argv', 'command')],
|
||||
required_one_of=[("argv", "command")],
|
||||
)
|
||||
|
||||
result = run_container_exec(module)
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue