1
0
Fork 0
mirror of https://github.com/containers/ansible-podman-collections.git synced 2026-02-04 07:11:49 +00:00
Commit graph

508 commits

Author SHA1 Message Date
CyberFox001
6cf118e7a9
Podman generate systemd (#498)
* Start a new Ansible module: podman_generate_systemd

This module, when finished, will let user generate a systemd .service
unit file from a pod or a container.

If a pod is specified, then the .service file is made for the pod and
its containers.

This commit is only the beginning, with two empty functions and the
base for a Python script.

* podman_generate_systemd : Remove not needed import from __future__

* podman_generate_systemd : Import AnsibleModule and json

* podman_generate_systemd : Build podman comand from user parameters

* podman_generate_systemd : Run the podman command and manage error

* podman_generate_systemd : Manage writing of systemd files, if needed

* podman_generate_systemd : In generate_systemd(), return needed infos

In case of success in generate_systemd() function, return:
- A boolean, indicate if the state of the target systemd is modified
- A copy of the systemd unit content

* podman_generate_systemd : Write run_module() function

This function:
- Build the list of parameters user can use
- Build a default result dictionary
- Build the Ansible Module
- Generate the systemd units (with generate_systemd())
- Return the result, with module.exit_json

* podman_generate_systemd : In main(), call run_module()

* podman_generate_systemd: Return podman command, and remove debug param

The run podman command is now returned by the module, and the "debug"
option is removed.

* podman_generate_systemd: Use more direct #! to python interpreter

The run podman command is now returned by the module, and the "debug"
option is removed.

* podman_generate_systemd: Write DOCUMENTATION variable

* podman_generate_systemd: Write EXAMPLES variable

* podman_generate_systemd: Write RETURN variable

* podman_generate_systemd: Fix typo

* podman_generate_systemd: 'restart_policy, remove default

* podman_generate_systemd: Fix missing "command" return when error

When error in command execution, generate_systemd() was not returning
the command. Now it's done.

* podman_generate_systemd: Remove unnecessary return in case of fail

In generate_systemd(), in case of fail in executing the podman
command, we call module.fail_json() then we return the usual data of
generate_systemd() function.

But module.fail_json() will stop the execution of the module, so it's
not necessary to return a value from generate_systemd() after calling
module.fail_json().

* podman_generate_systemd: Remove TODO

* podman_generate_systemd: Add missing double lines between functions

* podman_generate_systemd: More readability in EXAMPLES variable

* podman_generate_systemd: EXAMPLES, add minimum podman version

When a module option require a minimum Podman version, I indicate
this required version in option description.

For example: The module option `start_timeout` use the Podman option
`--start-timout`, which was introduced in Podman 4.0.0. So, I add in
the description of `start_timeout`: Only with Podman 4.0.0 and above

Options with this information:
- start_timeout
- restart_sec
- wants
- after
- requires

* podman_generate_systemd: EXAMPLES, fix type

* podman_generate_systemd: Simpler code for wants, after and requires

`after`, `wants` and `requires` are of type list. So, no need to
test their type and manage the case where they are of type string.

* podman_generate_systemd, generate_systemd(): Improve returned command

Improve how the used Podman command, returned by generate_systemd(),
is built. Instead of print a list in a formatted string, I join the
list elements with a space char as separator.

* podman_generate_systemd: Add support for the `env` option

Add, to the podman_generate_systemd module, the support for the `env`
option. This commit include the code, the option definition for the
module, the modification of the DOCUMENTATION variable and the add of
an usage example of this new option in the EXAMPLE variable.

* podman_generate_systemd: Write the integration test

* generate_systemd: Fix of the integration test and the --env command option

On the module, I now use the command option `-e=` for the definition
of environment variables. Because the option `--env` give an error
from Podman.

Also, fix errors in the integration test for this module.

* podman_generate_systemd: Add __future__ and __metaclass__ in the module

* podman_generate_systemd: Add author github ID

* podman_generate_systemd: Use argspec type path instead of str for dest option

In the module argspec, I now use the type `path` instead of `str` for
the option `dest`. `os.path.expanduser()` is no more necessary.

* podman_generate_systemd: remove all trailing whitespaces

* podman_generate_systemd: Remove type hint for compatibility with older Python

* podman_generate_systemd: Fix Documentation

Add a default for option `new` and fix typo in `use_names` option name.

* podman_generate_systemd: restart_policy option, new choices

The choice `no` is replaced by `no-restart`

* podman_generate_systemd: dest option in documentation, set type as path

Instead of str

* DNM add CI bits for new module tests

Made by sshnaidm.

* podman_generate_systemd: Better use of fail_json()

First: When calling the method fail_json(), name the `msg` argument to
avoid confusion.

Second: In case of calling fail_json(), I now return the same
arguments than the ones returned by a success: `changed`,
`systemd_units` and `podman_command`.

For future refactoring: Instead of calling fail_json() inside
generate_systemd(), raise custom exceptions and manage calling
fail_json() or exit_json() outside of generate_systemd().

* podman_generate_systemd: Add utf-8

* podman_generate_systemd: Remove `required: false` for DOCUMENTATION var

* podman_generate_systemd: DOCUMENTATION var, use bool instead of yes/no

* podman_generate_systemd: Remove non-necessary check of restart_policy option

The possible choices for this options are set in `ansible_spec` and
will be checked by AnsibleModule code. So, no need to check manually:
`ansible_spec` won't be anything other that the possible choices.

* podman_generate_systemd: On module params, use direct access to dict

Use `module.params['']` instead of `module.params.get('')`.

Because all module's options are defined with the `argument_spec`, the
options used here exist in the params. And if the user don't set
them, the value of the option is `None`.

* podman_generate_systemd: use shlex join for command_str

* podman_generate_systemd: use same quotes for messages

* podman_generate_systemd: Replace f-strings with .format(), for Python 2

* podman_generate_systemd: Revert usage of shlex

It add weird quotes around command options like `-e='ENV_VAR=value'`.

* podman_generate_systemd: Podman command build, more Python 2 compatible

Don't use any more the asterisk to add command options to the command.

* podman_generate_systemd: Better check-mode management

Now, when check mode is enabled, the module report "changed" is
something would be changed, but w/o actually doing anything.

* podman_generate_systemd: remove all trailing whitespaces

Co-authored-by: Sébastien Gendre <seb@k-7.ch>
2022-10-31 20:51:29 +02:00
antonc42
c9008c75b4
fix pod running status for older podman versions (#500)
* fix pod running status for older podman versions

Older podman versions, such as podman 1.6.4 on CentOS 7, do not have the
pod status in the 'podman pod inspect' output. Added an attribute and a
method to PodmanPod to fetch the 'podman pod ps' output. Added an
additional status check to the exising running property that uses the
'ps' info.

Fixes #499

Signed-off-by: antonc42 <antonc42@users.noreply.github.com>
2022-10-29 15:59:20 +03:00
Yuriy Gabuev
dbdac4a52b
podman_image: add file parameter for Containerfile location (#492)
* `podman_image`: correct `path` parameter description

The `path` parameter is the last parameter when running `podman build
...`. As specified in the manpage, it is defined as the build context,
and not necessarily should it contain the Containerfile.

Signed-off-by: Yuriy Gabuev <yuriy.gabuev@holoplot.com>

* `podman_image`: add `file` parameter for Containerfile location

Add the `file` parameter to `podman_image` module which mirrors the
`--file` command line argument for `podman build ...`. This parameter
specifies the location of the Containerfile to use in case it should be
different from the one contained in the build context directory.

Signed-off-by: Yuriy Gabuev <yuriy.gabuev@holoplot.com>

* `podman_image`: add integration tests for `file` parameter

Add tests to ensure that:
- building from a directory without a Containerfile (or Dockerfile)
  fails
- specifying the location of Containerfile with `file` parameter works

Signed-off-by: Yuriy Gabuev <yuriy.gabuev@holoplot.com>

Signed-off-by: Yuriy Gabuev <yuriy.gabuev@holoplot.com>
2022-10-25 17:48:14 +03:00
dependabot[bot]
9531d15d24
Bump actions/upload-artifact from 1 to 3 (#496)
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 1 to 3.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/v1...v3)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-10-25 04:42:06 +03:00
dependabot[bot]
9fe0771f4e
Bump actions/setup-python from 2 to 4 (#497)
Bumps [actions/setup-python](https://github.com/actions/setup-python) from 2 to 4.
- [Release notes](https://github.com/actions/setup-python/releases)
- [Commits](https://github.com/actions/setup-python/compare/v2...v4)

---
updated-dependencies:
- dependency-name: actions/setup-python
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-10-25 04:41:31 +03:00
dependabot[bot]
6219c8cb34
Bump actions/checkout from 2 to 3 (#495)
Bumps [actions/checkout](https://github.com/actions/checkout) from 2 to 3.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v2...v3)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-10-25 04:39:54 +03:00
dependabot[bot]
3e71b76b2e
Bump actions/download-artifact from 1 to 3 (#494)
Bumps [actions/download-artifact](https://github.com/actions/download-artifact) from 1 to 3.
- [Release notes](https://github.com/actions/download-artifact/releases)
- [Commits](https://github.com/actions/download-artifact/compare/v1...v3)

---
updated-dependencies:
- dependency-name: actions/download-artifact
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-10-25 04:39:26 +03:00
John Losito
3b3358c811
Check for gha updates weekly using dependabot (#490)
Signed-off-by: John Losito <lositojohnj@gmail.com>

Signed-off-by: John Losito <lositojohnj@gmail.com>
2022-10-25 04:17:10 +03:00
Sergey
bf67c7e078
Improve idempotency for devices mount of rootless podman (#487)
Signed-off-by: Sagi Shnaidman <sshnaidm@redhat.com>
2022-09-28 12:39:15 +03:00
János Gerzson
5f74d5b4fb
New become plugin: podman_unshare (#455)
* New become plugin: podman_unshare

Signed-off-by: Janos Gerzson <gerzsonj@gmail.com>
2022-09-22 17:24:45 +03:00
Sagi Shnaidman
409369c9fc Add shellcheck sanity ignore list for 2.15
Signed-off-by: Sagi Shnaidman <sshnaidm@redhat.com>
2022-09-21 02:40:05 +03:00
Sagi Shnaidman
d0e3af2b99 Bump galaxy.yml for devel version
Signed-off-by: Sagi Shnaidman <sshnaidm@redhat.com>
2022-09-21 02:40:05 +03:00
Sergey
853d3a8cc7
Fix idempotency for labels in pods (#482)
Signed-off-by: Sagi Shnaidman <sshnaidm@redhat.com>
2022-09-20 12:12:17 +03:00
Sergey
31dbd55579
Prepare tests to use custom executable, part 6 (#478)
Signed-off-by: Sagi Shnaidman <sshnaidm@redhat.com>
2022-09-04 22:33:28 +03:00
Sergey
03f19dfe25
Prepare tests to use custom executable, part 5 (#477)
Signed-off-by: Sagi Shnaidman <sshnaidm@redhat.com>
2022-09-04 22:03:29 +03:00
Sergey
9c1cd62b6f
Prepare tests to use custom executable, part 4 (#476)
Signed-off-by: Sagi Shnaidman <sshnaidm@redhat.com>
2022-09-04 21:47:33 +03:00
Sergey
d21b6c0326
Prepare tests to use custom executable, part 3 (#475)
Signed-off-by: Sagi Shnaidman <sshnaidm@redhat.com>
2022-09-04 21:43:00 +03:00
Sergey
51ce943a63
Prepare tests to use custom executable, part 2 (#474)
Signed-off-by: Sagi Shnaidman <sshnaidm@redhat.com>
2022-09-04 21:28:13 +03:00
Sergey
e9d746728d
Prepare tests to use custom executable, part 1 (#473)
Signed-off-by: Sagi Shnaidman <sshnaidm@redhat.com>
2022-09-04 21:09:04 +03:00
Sergey
93b5acbf6e
Support passing multiple networks with params (#472)
Fix #467
Signed-off-by: Sagi Shnaidman <sshnaidm@redhat.com>
2022-09-03 10:40:48 +03:00
Sergey
bd0f6f9bc4
Improve networks idempotency for v4 (#471)
Signed-off-by: Sagi Shnaidman <sshnaidm@redhat.com>
2022-09-02 19:33:16 +03:00
dada513
b72a026328
generate_systemd: implement --wants, --after and --requires (GH-431) (#432)
* generate_systemd: implement --wants, --after and --requires (GH-431)

Signed-off-by: dada513 <dada513@protonmail.com>
Signed-off-by: Sagi Shnaidman <sshnaidm@redhat.com>
Co-authored-by: Sagi Shnaidman <sshnaidm@redhat.com>
2022-09-01 20:28:07 +03:00
Sergey
befb381194
Create a sponsorship file (#466)
Create a sponsorship file
2022-08-29 01:44:46 +03:00
Sergey
cecb29222e
Add --sdnotify option for container (#465)
Fix #464

Signed-off-by: Sagi Shnaidman <sshnaidm@redhat.com>
2022-08-28 16:42:31 +03:00
Nikita Tokarchuk
9068baeb99
podman_container should ensure image by using os path if rootfs is used (#458)
* Check image with os path if rootfs is used

Signed-off-by: Nikita Tokarchuk <nikita@tokarch.uk>

* Take into account rootfs usage while evaluating a diff

Signed-off-by: Nikita Tokarchuk <nikita@tokarch.uk>

* Always compare rootfs image diffparam as strict

Signed-off-by: Nikita Tokarchuk <nikita@tokarch.uk>

* Reverse image labels getter to ignore the value if None

Signed-off-by: Nikita Tokarchuk <nikita@tokarch.uk>

* Add tests to check podman rootfs containers

Signed-off-by: Nikita Tokarchuk <nikita@tokarch.uk>

Signed-off-by: Nikita Tokarchuk <nikita@tokarch.uk>
2022-08-12 06:26:16 +03:00
Albrecht
08dd7b0ceb
add required argument to example (#461)
Signed-off-by: weichweich <archbelt@posteo.de>
2022-08-08 22:28:15 +03:00
Sergey
e6544bdd0a
Fix PEP8 issue in podman_image (#459)
Signed-off-by: Sagi Shnaidman <sshnaidm@redhat.com>
2022-07-31 22:47:17 +03:00
Adrian Freund
99c2851341
Fix rerunning playbooks with generate_systemd --new (#453)
* Fix restarting containers if --rm is enabled
* Automatically enable rm if generate_systemd.new is set
* Don't assume that the 'new' key in generate_systemd exists

Signed-off-by: Adrian Freund <adrian@freund.io>
2022-07-22 17:41:21 +03:00
Sergey
ff60aed673
Set devel Ansible branch to run on Python 3.9 (#457)
Signed-off-by: Sagi Shnaidman <sshnaidm@redhat.com>
2022-07-22 12:14:47 +03:00
Sergey
3596833a7d
Remove LC_ALL=C from podman tests (#452)
Ansible requires en_US.UTF-8 from 2.14 version.

Signed-off-by: Sagi Shnaidman <sshnaidm@redhat.com>
2022-07-14 12:26:28 +03:00
Sergey
33580c8991
Fix building image with buildah and become (#451)
Probably we hit a bug in CI:
https://github.com/containers/buildah/issues/3887
Unset envs to prevent error "sd-bus call: Transport endpoint is not connected"

Signed-off-by: Sagi Shnaidman <sshnaidm@redhat.com>
2022-07-14 11:47:50 +03:00
Sergey
2c88b822cf
Set localte in CI tests to en_US.UTF-8 (#450)
Signed-off-by: Sagi Shnaidman <sshnaidm@redhat.com>
2022-07-14 11:35:47 +03:00
Sergey
33b28086ec
Release 1.9.4 version (#446)
Signed-off-by: Sagi Shnaidman <sshnaidm@redhat.com>
2022-07-04 16:03:14 +03:00
Sergey
db27c68ef9
Fix pod tests in CI (#445)
Remove 'net' from pod idempotency if it's not in inspection.
Probably a bug on Ubuntu.

Signed-off-by: Sagi Shnaidman <sshnaidm@redhat.com>
2022-07-04 15:46:35 +03:00
Sagi Shnaidman
75198ae574 Fix pod network idempotency
Signed-off-by: Sagi Shnaidman <sshnaidm@redhat.com>
2022-07-01 10:23:12 +03:00
Sagi Shnaidman
6c862b29e7 Fix pods list retrieve
Signed-off-by: Sagi Shnaidman <sshnaidm@redhat.com>
2022-07-01 10:23:12 +03:00
Sagi Shnaidman
542986cd8a Pass errors as a string instead of list 2022-07-01 10:23:12 +03:00
Sagi Shnaidman
3fe1edb5b4 Run CI on Ubuntu 22.04
Signed-off-by: Sagi Shnaidman <sshnaidm@redhat.com>
2022-07-01 10:23:12 +03:00
Rabi Mishra
6dc481ae2c
Change IpcMode default to shareable (#444)
podman 4.1.x has changed the ipc namespace mode default to
shareable[1] that results in containers being restarted.

[1] 3987c529f4

Resolves: rhbz#2101495
Signed-off-by: Rabi Mishra <ramishra@redhat.com>
2022-06-29 03:10:45 +03:00
Sergey
2cc1040f33
Use 2.13 Ansible version in CI jobs instead of 2.11 (#439)
Signed-off-by: Sagi Shnaidman <sshnaidm@redhat.com>
2022-06-28 01:04:56 +03:00
Sergey
2577f5b0f5
Remove distutils as deprecated (#437)
Fix #422
The distutils package is deprecated and slated for removal in Python 3.12

Signed-off-by: Sagi Shnaidman <sshnaidm@redhat.com>
2022-06-12 22:54:03 +03:00
Cleber Rosa
1003e966ee
Add missing docstring for method that executes the podman commands (#436)
For completeness sake (and because I looked for it and did not find
it), this adds a docstring line for the "use_container_id" parameter.

Signed-off-by: Cleber Rosa <crosa@redhat.com>
2022-06-11 14:35:29 +03:00
Sergey
25b9516488
Allow specify podman_network options MTU and VLAN separately (#435)
Before that it didn't work when only one option set.

Signed-off-by: Sagi Shnaidman <sshnaidm@redhat.com>
2022-06-08 19:37:06 +03:00
nishipy
acedce8b4b
Update podman_image to remove image with image id (#434)
* Update to remove image with image id.

Signed-off-by: nishipy <goodisonev4@gmail.com>
2022-06-08 18:51:25 +03:00
Clemens Lange
b33a657f00
Fix idempotency for podman_login (#430)
Signed-off-by: Clemens Lange <clemens.lange@cern.ch>
2022-06-06 12:18:08 +03:00
Benjamin Schubert
15dae0d9ad
podman_container.py: Fix typo in the documentation (#424)
I believe "prefix" is what was meant here

Signed-off-by: Benjamin Schubert <contact@benschubert.me>
2022-05-22 15:08:16 +03:00
Oscar
20a982b564
Fix play_kube not working when yaml not installed on target (#415) (#419)
Signed-off-by: tcmal <oscar.shrimpton.personal@gmail.com>
2022-05-01 11:48:43 +03:00
Sergey
98c516292f
Fix internal networks idempotency (#421)
Remove logic with internal and dns, since Podman supports it in
recent versions.
Fix #350
Signed-off-by: Sagi Shnaidman <sshnaidm@redhat.com>
2022-04-28 00:56:22 +03:00
Sergey
848034096c
Disable memory idempotency (#420)
Because of complexity in Podman logic and calculations of b/m/g
etc let's disable this idempotency for now.
Fix #418

Signed-off-by: Sagi Shnaidman <sshnaidm@redhat.com>
2022-04-28 00:26:28 +03:00
Sergey
e5d6136694
Change network attribute from str to list in pods #414 #416 (#417)
* Change network attribute from str to list in pods

Signed-off-by: André Cirne <dumahk21@gmail.com>

* Fix tests

Signed-off-by: Sagi Shnaidman <sshnaidm@redhat.com>

Co-authored-by: André Cirne <dumahk21@gmail.com>
2022-04-25 02:15:29 +03:00