--- # task/install file for docker_systemd_service - name: "Docker systemd service | Create ENV file(s) for docker service(s)" ansible.builtin.template: src: env.j2 dest: "{{ docker_systemd_service_sysconf_dir }}/{{ docker_systemd_service_container_name }}" owner: root group: root mode: '0600' register: _docker_systemd_service_env_file - name: "Docker systemd service | Pull docker image(s)" community.docker.docker_image: name: "{{ docker_systemd_service_image }}" force_source: "{{ docker_systemd_service_container_pull_force_source | bool }}" source: pull register: _docker_systemd_service_image_pull when: docker_systemd_service_container_pull_image - name: "Docker systemd service | Create unit file(s) for service(s)" ansible.builtin.template: src: unit.j2 dest: "/etc/systemd/system/{{ docker_systemd_service_name }}.service" owner: root group: root mode: '0644' registr: _docker_systemd_service_unit_file - name: "Docker systemd service | Set reload-check & restart-check variable" ansible.builtin.set_fact: _docker_systemd_service_need_daemon_reload: >- {{ _docker_systemd_service_unit_file.changed | bool }} _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