diff --git a/main.yml b/main.yml index e553e6e..5bb3537 100644 --- a/main.yml +++ b/main.yml @@ -1,14 +1,14 @@ --- -- hosts: iron-man.lan - roles: - - ssh - - ubuntu - -- hosts: prusa.lan - roles: - - ssh - - octoprint - - ubuntu +#- hosts: iron-man.lan +# roles: +# - ssh +# - ubuntu +# +#- hosts: prusa.lan +# roles: +# - ssh +# - octoprint +# - ubuntu - hosts: docker_cluster roles: @@ -16,7 +16,7 @@ - docker-cluster - ubuntu -- hosts: router.lan - roles: - - router +#- hosts: router.lan +# roles: +# - router diff --git a/roles/docker-cluster/tasks/docker-watcher.yml b/roles/docker-cluster/tasks/docker-watcher.yml new file mode 100644 index 0000000..33f0721 --- /dev/null +++ b/roles/docker-cluster/tasks/docker-watcher.yml @@ -0,0 +1,19 @@ +--- +- name: Create hostfile + become: yes + template: + src: usr/local/sbin/check-docker.j2 + dest: /usr/local/sbin/check-docker + +- name: Remove file (delete file) + become: yes + file: + path: /usr/local/sbin/check-docker.j2 + state: absent + +- name: create cron + become: yes + cron: + name: "check docker" + minute: "*/15" + job: "/usr/local/sbin/check-docker" \ No newline at end of file diff --git a/roles/docker-cluster/tasks/main.yml b/roles/docker-cluster/tasks/main.yml index d977b2b..6c61c31 100644 --- a/roles/docker-cluster/tasks/main.yml +++ b/roles/docker-cluster/tasks/main.yml @@ -11,3 +11,4 @@ - import_tasks: hostfile.yml +- import_tasks: docker-watcher.yml \ No newline at end of file diff --git a/roles/docker-cluster/templates/usr/local/sbin/check-docker.j2 b/roles/docker-cluster/templates/usr/local/sbin/check-docker.j2 new file mode 100644 index 0000000..c31cfef --- /dev/null +++ b/roles/docker-cluster/templates/usr/local/sbin/check-docker.j2 @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +docker node inspect {{ ansible_hostname }} --format "{{ '{{' }} .Status.State {{ '}}' }}" | grep -q 'ready' + +if [ $? == 1 ]; then + echo "Docker is down restarting" + service docker restart +else + echo "Docker is ok" +fi \ No newline at end of file