diff --git a/roles/remote/tasks/main.yml b/roles/remote/tasks/main.yml index bd5f8f3ee6..570bef496e 100644 --- a/roles/remote/tasks/main.yml +++ b/roles/remote/tasks/main.yml @@ -12,10 +12,6 @@ name: rclone when: use_remote and ('mounts' in ansible_run_tags) and remote_update_rclone -- name: "Initialize 'remote_stopped_docker' variable" - ansible.builtin.set_fact: - remote_stopped_docker: false - - name: Check to see if docker is installed ansible.builtin.stat: path: "/usr/bin/docker" @@ -37,10 +33,9 @@ register: saltbox_managed_containers ignore_errors: true - - name: "Set 'containers_list' and 'remote_stopped_docker' variables" + - name: "Set 'containers_list' variable" ansible.builtin.set_fact: containers_list: "{{ saltbox_managed_containers.stdout }}" - remote_stopped_docker: true - name: "Stop all running Docker containers" ansible.builtin.shell: "docker stop {{ containers_list }}" diff --git a/roles/unionfs/tasks/main.yml b/roles/unionfs/tasks/main.yml index 5876d8cd38..3171d2c947 100644 --- a/roles/unionfs/tasks/main.yml +++ b/roles/unionfs/tasks/main.yml @@ -28,11 +28,13 @@ - name: MergerFS Tasks ansible.builtin.include_tasks: "subtasks/mergerfs.yml" -- name: Docker Daemon Tasks - ansible.builtin.import_tasks: "subtasks/docker/daemon.yml" +- name: Mounts block when: ('mounts' in ansible_run_tags) + block: + - name: Docker Daemon Tasks + ansible.builtin.import_tasks: "subtasks/docker/daemon.yml" -# Start Docker Containers + # Start Docker Containers -- name: Docker Containers Start Tasks - ansible.builtin.import_tasks: "subtasks/docker/containers_start.yml" + - name: Docker Containers Start Tasks + ansible.builtin.import_tasks: "subtasks/docker/containers_start.yml" diff --git a/roles/unionfs/tasks/subtasks/docker/containers_stop.yml b/roles/unionfs/tasks/subtasks/docker/containers_stop.yml index f7f6009f8f..42474c28a4 100644 --- a/roles/unionfs/tasks/subtasks/docker/containers_stop.yml +++ b/roles/unionfs/tasks/subtasks/docker/containers_stop.yml @@ -7,23 +7,32 @@ # GNU General Public License v3.0 # ######################################################################### --- -- name: "Docker | Containers Stop | Gather list of running Docker containers" - ansible.builtin.shell: "docker ps --format '{{ '{{' }} .Names{{ '}}' }}' --filter label=com.github.saltbox.saltbox_managed=true | xargs echo -n" - register: saltbox_managed_containers - ignore_errors: true +- name: Populate Service Facts + ansible.builtin.service_facts: -# This is needed to not conflict with the other role -- name: "Docker | Containers Stop | Set 'containers_list' variable" +- name: Get Docker service state ansible.builtin.set_fact: - containers_list: "{{ saltbox_managed_containers.stdout }}" + remote_docker_service_running: "{{ (services['docker.service'] is defined) and (services['docker.service']['state'] == 'running') }}" + when: remote_docker_binary.stat.exists -- name: "Docker | Containers Stop | Stop all running Docker containers" - ansible.builtin.shell: "docker stop {{ containers_list }}" - ignore_errors: true - when: (containers_list | trim | length > 0) +- name: Tasks for when Docker exists and is running + when: remote_docker_binary.stat.exists and remote_docker_service_running + block: + - name: "Gather list of running Docker containers" + ansible.builtin.shell: "docker ps --format '{{ '{{' }} .Names{{ '}}' }}' --filter label=com.github.saltbox.saltbox_managed=true | xargs echo -n" + register: saltbox_managed_containers + ignore_errors: true -- name: "Docker | Containers Stop | Stop docker service" - ansible.builtin.systemd: - name: docker - state: stopped - ignore_errors: true + - name: "Set 'containers_list' variable" + ansible.builtin.set_fact: + containers_list: "{{ saltbox_managed_containers.stdout }}" + + - name: "Stop all running Docker containers" + ansible.builtin.shell: "docker stop {{ containers_list }}" + ignore_errors: true + when: (containers_list | trim | length > 0) + + - name: Stop docker service + ansible.builtin.systemd: + name: docker + state: stopped diff --git a/roles/unionfs/tasks/subtasks/docker/daemon.yml b/roles/unionfs/tasks/subtasks/docker/daemon.yml index aa638d142b..cf89b6525c 100644 --- a/roles/unionfs/tasks/subtasks/docker/daemon.yml +++ b/roles/unionfs/tasks/subtasks/docker/daemon.yml @@ -26,16 +26,16 @@ mode: "0644" force: "{{ docker_service_force }}" -- name: "Docker | Daemon | Tasks for when Docker was stopped by Remote role" - when: remote_stopped_docker - block: - - name: "Docker | Daemon | Start docker service" - ansible.builtin.systemd: - name: docker - state: started - enabled: true - daemon_reload: true +- name: "Docker | Daemon | Run systemd daemon-reload" + ansible.builtin.systemd: + daemon_reload: true - - name: "Docker | Daemon | Wait for 30 seconds before commencing" - ansible.builtin.wait_for: - timeout: 30 +- name: "Docker | Daemon | Start docker service" + ansible.builtin.systemd: + name: docker + state: restarted + enabled: true + +- name: "Docker | Daemon | Wait for 30 seconds before commencing" + ansible.builtin.wait_for: + timeout: 30