mirror of
https://github.com/containers/ansible-podman-collections.git
synced 2026-02-04 07:11:49 +00:00
Add force option for podman_generate_systemd
Signed-off-by: nishipy <goodisonev4@gmail.com>
This commit is contained in:
parent
cb1ce120e9
commit
aafe92d678
1 changed files with 22 additions and 7 deletions
|
|
@ -4,6 +4,10 @@
|
|||
# 2022, Sébastien Gendre <seb@k-7.ch>
|
||||
# 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)
|
||||
from ansible_collections.containers.podman.plugins.module_utils.podman.common import compare_systemd_file_content
|
||||
import json
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
import os
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
|
|
@ -27,6 +31,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.
|
||||
|
|
@ -216,11 +226,6 @@ podman_command:
|
|||
'''
|
||||
|
||||
|
||||
import os
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
import json
|
||||
from ansible_collections.containers.podman.plugins.module_utils.podman.common import compare_systemd_file_content
|
||||
|
||||
RESTART_POLICY_CHOICES = [
|
||||
'no-restart',
|
||||
'on-success',
|
||||
|
|
@ -446,8 +451,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 +498,11 @@ def run_module():
|
|||
'required': False,
|
||||
'default': False,
|
||||
},
|
||||
'force': {
|
||||
'type': 'bool',
|
||||
'required': False,
|
||||
'default': False,
|
||||
},
|
||||
'restart_policy': {
|
||||
'type': 'str',
|
||||
'required': False,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue