File tree Expand file tree Collapse file tree 2 files changed +60
-2
lines changed
tests/integration/targets/podman_generate_systemd/tasks Expand file tree Collapse file tree 2 files changed +60
-2
lines changed Original file line number Diff line number Diff line change 2727 - Use C(/etc/systemd/system) for the system-wide systemd instance.
2828 - Use C(/etc/systemd/user) or C(~/.config/systemd/user) for use with per-user instances of systemd.
2929 type: path
30+ force:
31+ description:
32+ - Replace the systemd unit file(s) even if it already exists.
33+ - This works with dest option.
34+ type: bool
35+ default: false
3036 new:
3137 description:
3238 - Generate unit files that create containers and pods, not only start them.
@@ -446,8 +452,13 @@ def generate_systemd(module):
446452 unit_file_name ,
447453 )
448454
449- # See if we need to write the unit file, default yes
450- need_to_write_file = bool (compare_systemd_file_content (unit_file_full_path , unit_content ))
455+ if module .params ['force' ]:
456+ # Force to replace the existing unit file
457+ need_to_write_file = True
458+ else :
459+ # See if we need to write the unit file, default yes
460+ need_to_write_file = bool (compare_systemd_file_content (
461+ unit_file_full_path , unit_content ))
451462
452463 # Write the file, if needed
453464 if need_to_write_file :
@@ -488,6 +499,11 @@ def run_module():
488499 'required' : False ,
489500 'default' : False ,
490501 },
502+ 'force' : {
503+ 'type' : 'bool' ,
504+ 'required' : False ,
505+ 'default' : False ,
506+ },
491507 'restart_policy' : {
492508 'type' : 'str' ,
493509 'required' : False ,
Original file line number Diff line number Diff line change 3939 path : " /tmp/podman_generate_systemd/{{ item.key }}.service"
4040 loop : " {{ postgres_local_systemd_unit.systemd_units | dict2items }}"
4141
42+ - name : Try to create a systemd unit file on the same path
43+ containers.podman.podman_generate_systemd :
44+ name : postgres_local
45+ dest : /tmp/podman_generate_systemd
46+ register : generate1
47+
48+ - name : Check the unit files exists
49+ ansible.builtin.stat :
50+ path : " /tmp/podman_generate_systemd/{{ item.key }}.service"
51+ loop : " {{ generate1.systemd_units | dict2items }}"
52+ register : unitfile1
53+
54+ - name : Get checksum value
55+ set_fact :
56+ checksum1 : " {{ item.stat.checksum }}"
57+ with_items : " {{ unitfile1.results }}"
58+
59+ - name : Force to create a systemd unit file on the same path
60+ containers.podman.podman_generate_systemd :
61+ name : postgres_local
62+ dest : /tmp/podman_generate_systemd
63+ force : true
64+ register : generate2
65+
66+ - name : Check the unit files exists again
67+ ansible.builtin.stat :
68+ path : " /tmp/podman_generate_systemd/{{ item.key }}.service"
69+ loop : " {{ generate2.systemd_units | dict2items }}"
70+ register : unitfile2
71+
72+ - name : Get checksum value again
73+ set_fact :
74+ checksum2 : " {{ item.stat.checksum }}"
75+ with_items : " {{ unitfile2.results }}"
76+
77+ - name : Check if the sytemd unit files are as expected
78+ assert :
79+ that :
80+ - generate1 is not changed
81+ - generate2 is changed
82+ - checksum1 != checksum2
83+
4284- name : Regenerate the systemd units with all the options
4385 containers.podman.podman_generate_systemd :
4486 name : postgres_local
You can’t perform that action at this time.
0 commit comments