diff --git a/defaults/docker_systemd_service.yml.sample b/defaults/docker_systemd_service.yml.sample deleted file mode 100644 index d00d9ac..0000000 --- a/defaults/docker_systemd_service.yml.sample +++ /dev/null @@ -1,14 +0,0 @@ ---- -# docker_systemd_service_container_name: "My-Service" -# docker_systemd_service_image: -# docker_systemd_service_container_env: {} -# docker_systemd_service_container_pull_image: true -# docker_systemd_service_container_pull_force_source: true -# docker_systemd_service_flags: [] -# docker_systemd_service_container_cmd: [] -# docker_systemd_service_name: "{{ docker_systemd_service_container_name }}_container" -# docker_systemd_service_systemd_options: [] -# docker_systemd_service_enabled: true -# docker_systemd_service_masked: false -# docker_systemd_service_state: started -# docker_systemd_service_restart: true diff --git a/defaults/main.yml b/defaults/main.yml index f70688b..f5f55c1 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -9,7 +9,5 @@ docker_systemd_service_flags: [] docker_systemd_service_container_cmd: [] docker_systemd_service_name: "{{ docker_systemd_service_container_name }}_container" docker_systemd_service_systemd_options: [] -docker_systemd_service_enabled: true -docker_systemd_service_masked: false -docker_systemd_service_state: started -docker_systemd_service_restart: true + +docker_systemd_service_start: true diff --git a/molecule/default/group_vars/all.yml b/molecule/default/group_vars/all.yml index 1546e18..0c0e824 100644 --- a/molecule/default/group_vars/all.yml +++ b/molecule/default/group_vars/all.yml @@ -8,7 +8,4 @@ docker_systemd_service_flags: [] docker_systemd_service_container_cmd: [] docker_systemd_service_name: "{{ docker_systemd_service_container_name }}_container" docker_systemd_service_systemd_options: [] -docker_systemd_service_enabled: true -docker_systemd_service_masked: false -docker_systemd_service_state: stopped -docker_systemd_service_restart: false +docker_systemd_service_start: false diff --git a/molecule/default/verify.yml b/molecule/default/verify.yml index 433b360..8e4e4da 100644 --- a/molecule/default/verify.yml +++ b/molecule/default/verify.yml @@ -24,7 +24,7 @@ - stat_etc_default_nginx.stat.pw_name == 'root' - stat_etc_default_nginx.stat.gr_name == 'root' - stat_etc_default_nginx.stat.mode == '0600' - - (slurp_etc_default_nginx.content|b64decode) == '' + - (slurp_etc_default_nginx.content|b64decode) == '\n' - name: "Test: service nginx_container" block: diff --git a/molecule/default_os/group_vars/all.yml b/molecule/default_os/group_vars/all.yml index 768ded5..97cad22 100644 --- a/molecule/default_os/group_vars/all.yml +++ b/molecule/default_os/group_vars/all.yml @@ -8,7 +8,4 @@ docker_systemd_service_flags: [] docker_systemd_service_container_cmd: [] docker_systemd_service_name: "{{ docker_systemd_service_container_name }}_container" docker_systemd_service_systemd_options: [] -docker_systemd_service_enabled: true -docker_systemd_service_masked: false -docker_systemd_service_state: started -docker_systemd_service_restart: true +docker_systemd_service_start: true diff --git a/molecule/default_os/verify.yml b/molecule/default_os/verify.yml index 5e1cbce..c5dfebf 100644 --- a/molecule/default_os/verify.yml +++ b/molecule/default_os/verify.yml @@ -24,7 +24,7 @@ - stat_etc_default_nginx.stat.pw_name == 'root' - stat_etc_default_nginx.stat.gr_name == 'root' - stat_etc_default_nginx.stat.mode == '0600' - - (slurp_etc_default_nginx.content|b64decode) == '' + - (slurp_etc_default_nginx.content|b64decode) == '\n' - name: "Test: service nginx_container" block: diff --git a/molecule/with_custom_flags/group_vars/all.yml b/molecule/with_custom_flags/group_vars/all.yml index 11733c3..3b75768 100644 --- a/molecule/with_custom_flags/group_vars/all.yml +++ b/molecule/with_custom_flags/group_vars/all.yml @@ -13,7 +13,4 @@ docker_systemd_service_flags: docker_systemd_service_container_cmd: [] docker_systemd_service_name: "{{ docker_systemd_service_container_name }}_container" docker_systemd_service_systemd_options: [] -docker_systemd_service_enabled: true -docker_systemd_service_masked: false -docker_systemd_service_state: stopped -docker_systemd_service_restart: false +docker_systemd_service_start: false diff --git a/molecule/with_custom_flags_os/group_vars/all.yml b/molecule/with_custom_flags_os/group_vars/all.yml index 405fd2f..6327d85 100644 --- a/molecule/with_custom_flags_os/group_vars/all.yml +++ b/molecule/with_custom_flags_os/group_vars/all.yml @@ -13,7 +13,4 @@ docker_systemd_service_flags: docker_systemd_service_container_cmd: [] docker_systemd_service_name: "{{ docker_systemd_service_container_name }}_container" docker_systemd_service_systemd_options: [] -docker_systemd_service_enabled: true -docker_systemd_service_masked: false -docker_systemd_service_state: started -docker_systemd_service_restart: true +docker_systemd_service_start: true diff --git a/tasks/install.yml b/tasks/configure.yml similarity index 76% rename from tasks/install.yml rename to tasks/configure.yml index c770692..67e06ac 100644 --- a/tasks/install.yml +++ b/tasks/configure.yml @@ -33,13 +33,4 @@ _docker_systemd_service_need_restart: true when: _docker_systemd_service_env_file.changed or _docker_systemd_service_unit_file.changed or - docker_systemd_service_container_pull_image.changed - -- name: "Docker systemd service | Enable and start service(s)" - ansible.builtin.systemd: - name: '{{ docker_systemd_service_name }}.service' - daemon_reload: true - enabled: "{{ docker_systemd_service_enabled }}" - masked: "{{ docker_systemd_service_masked }}" - state: "{{ docker_systemd_service_state }}" - register: _enable_and_start + _docker_systemd_service_image_pull.changed diff --git a/tasks/main.yml b/tasks/main.yml index 8c0b22a..079e60d 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -5,13 +5,17 @@ _docker_systemd_service_need_daemon_reload: false _docker_systemd_service_need_restart: false -- name: "Docker systemd service | Import install.yml" - ansible.builtin.include_tasks: install.yml - when: docker_systemd_service_state != "absent" +- name: "Docker systemd service | Import configure.yml" + ansible.builtin.include_tasks: configure.yml -- name: "Docker systemd service | Import uninstall.yml" - ansible.builtin.include_tasks: uninstall.yml - when: docker_systemd_service_state == "absent" +- name: "Docker systemd service | Populate service facts" + ansible.builtin.service_facts: + +- name: "Docker systemd service | Set restart-check variable" + ansible.builtin.set_fact: + _docker_systemd_service_need_restart: true + when: + - ansible_facts.services[docker_systemd_service_name~'.service'].state != 'running' - name: "Docker systemd service | Enable service: {{ docker_systemd_service_name }}" ansible.builtin.service: @@ -28,4 +32,6 @@ name: "{{ docker_systemd_service_name }}" state: restarted throttle: 1 - when: _docker_systemd_service_need_restart + when: + - _docker_systemd_service_need_restart + - docker_systemd_service_start diff --git a/tasks/uninstall.yml b/tasks/uninstall.yml deleted file mode 100644 index 9faf8d3..0000000 --- a/tasks/uninstall.yml +++ /dev/null @@ -1,22 +0,0 @@ ---- -# task/uninstall file for docker_systemd_service -- name: "Remove ENV file(s) for service(s)" - ansible.builtin.file: - path: "{{ docker_systemd_service_sysconf_dir }}/{{ docker_systemd_service_container_name }}" - state: absent - -- name: "Disable and stop service(s)" - ansible.builtin.systemd: - name: '{{ docker_systemd_service_name }}.service' - enabled: false - state: stopped - -- name: "Remove unit file(s) for service(s)" - ansible.builtin.file: - path: /etc/systemd/system/{{ docker_systemd_service_name }}.service - state: absent - -- name: "Reload systemd units" - ansible.builtin.systemd: - daemon_reload: true - changed_when: false