mirror of
https://github.com/containers/ansible-podman-collections.git
synced 2026-02-04 07:11:49 +00:00
Add a force field to podman_generate_systemd (#624)
* Add tests for podman_generate_systemd Signed-off-by: nishipy <goodisonev4@gmail.com> * Add force option for podman_generate_systemd Signed-off-by: nishipy <goodisonev4@gmail.com> * Fix test code for podman_generate_systemd Signed-off-by: nishipy <goodisonev4@gmail.com> * Fix CI error Signed-off-by: nishipy <goodisonev4@gmail.com> --------- Signed-off-by: nishipy <goodisonev4@gmail.com>
This commit is contained in:
parent
c6a80a5573
commit
04f455bec1
2 changed files with 60 additions and 2 deletions
|
|
@ -27,6 +27,12 @@ options:
|
|||
- Use C(/etc/systemd/system) for the system-wide systemd instance.
|
||||
- Use C(/etc/systemd/user) or C(~/.config/systemd/user) for use with per-user instances of systemd.
|
||||
type: path
|
||||
force:
|
||||
description:
|
||||
- Replace the systemd unit file(s) even if it already exists.
|
||||
- This works with dest option.
|
||||
type: bool
|
||||
default: false
|
||||
new:
|
||||
description:
|
||||
- Generate unit files that create containers and pods, not only start them.
|
||||
|
|
@ -446,8 +452,13 @@ def generate_systemd(module):
|
|||
unit_file_name,
|
||||
)
|
||||
|
||||
# See if we need to write the unit file, default yes
|
||||
need_to_write_file = bool(compare_systemd_file_content(unit_file_full_path, unit_content))
|
||||
if module.params['force']:
|
||||
# Force to replace the existing unit file
|
||||
need_to_write_file = True
|
||||
else:
|
||||
# See if we need to write the unit file, default yes
|
||||
need_to_write_file = bool(compare_systemd_file_content(
|
||||
unit_file_full_path, unit_content))
|
||||
|
||||
# Write the file, if needed
|
||||
if need_to_write_file:
|
||||
|
|
@ -488,6 +499,11 @@ def run_module():
|
|||
'required': False,
|
||||
'default': False,
|
||||
},
|
||||
'force': {
|
||||
'type': 'bool',
|
||||
'required': False,
|
||||
'default': False,
|
||||
},
|
||||
'restart_policy': {
|
||||
'type': 'str',
|
||||
'required': False,
|
||||
|
|
|
|||
|
|
@ -39,6 +39,48 @@
|
|||
path: "/tmp/podman_generate_systemd/{{ item.key }}.service"
|
||||
loop: "{{ postgres_local_systemd_unit.systemd_units | dict2items }}"
|
||||
|
||||
- name: Try to create a systemd unit file on the same path
|
||||
containers.podman.podman_generate_systemd:
|
||||
name: postgres_local
|
||||
dest: /tmp/podman_generate_systemd
|
||||
register: generate1
|
||||
|
||||
- name: Check the unit files exists
|
||||
ansible.builtin.stat:
|
||||
path: "/tmp/podman_generate_systemd/{{ item.key }}.service"
|
||||
loop: "{{ generate1.systemd_units | dict2items }}"
|
||||
register: unitfile1
|
||||
|
||||
- name: Get checksum value
|
||||
set_fact:
|
||||
checksum1: "{{ item.stat.checksum }}"
|
||||
with_items: "{{ unitfile1.results }}"
|
||||
|
||||
- name: Force to create a systemd unit file on the same path
|
||||
containers.podman.podman_generate_systemd:
|
||||
name: postgres_local
|
||||
dest: /tmp/podman_generate_systemd
|
||||
force: true
|
||||
register: generate2
|
||||
|
||||
- name: Check the unit files exists again
|
||||
ansible.builtin.stat:
|
||||
path: "/tmp/podman_generate_systemd/{{ item.key }}.service"
|
||||
loop: "{{ generate2.systemd_units | dict2items }}"
|
||||
register: unitfile2
|
||||
|
||||
- name: Get checksum value again
|
||||
set_fact:
|
||||
checksum2: "{{ item.stat.checksum }}"
|
||||
with_items: "{{ unitfile2.results }}"
|
||||
|
||||
- name: Check if the sytemd unit files are as expected
|
||||
assert:
|
||||
that:
|
||||
- generate1 is not changed
|
||||
- generate2 is changed
|
||||
- checksum1 != checksum2
|
||||
|
||||
- name: Regenerate the systemd units with all the options
|
||||
containers.podman.podman_generate_systemd:
|
||||
name: postgres_local
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue