From 7357ea4392f9c1474b9a5b44a11f8458607e016f Mon Sep 17 00:00:00 2001 From: pgrondek Date: Tue, 26 May 2020 00:08:01 +0200 Subject: [PATCH] Move docker to roles --- docker/docker.yml | 38 ------------------- docker/nfs-client.yml | 30 --------------- inventory/hosts.yml | 2 +- main.yml | 4 ++ .../docker-cluster/files}/etc/ha.d/ha.cf | 0 .../files}/etc/ha.d/haresources | 0 .../lib/systemd/system}/rpc-statd.service | 0 .../docker-cluster/tasks}/hearthbeat.yml | 9 +---- .../tasks/install-docker-ce.yml | 37 ++++++++++++++++++ .../tasks/install-docker-io.yml | 7 ++++ roles/docker-cluster/tasks/main.yml | 11 ++++++ roles/docker-cluster/tasks/nfs-client.yml | 25 ++++++++++++ 12 files changed, 87 insertions(+), 76 deletions(-) delete mode 100644 docker/docker.yml delete mode 100644 docker/nfs-client.yml rename {docker => roles/docker-cluster/files}/etc/ha.d/ha.cf (100%) rename {docker => roles/docker-cluster/files}/etc/ha.d/haresources (100%) rename {docker => roles/docker-cluster/files/lib/systemd/system}/rpc-statd.service (100%) rename {docker => roles/docker-cluster/tasks}/hearthbeat.yml (71%) create mode 100644 roles/docker-cluster/tasks/install-docker-ce.yml create mode 100644 roles/docker-cluster/tasks/install-docker-io.yml create mode 100644 roles/docker-cluster/tasks/main.yml create mode 100644 roles/docker-cluster/tasks/nfs-client.yml diff --git a/docker/docker.yml b/docker/docker.yml deleted file mode 100644 index dcab3d9..0000000 --- a/docker/docker.yml +++ /dev/null @@ -1,38 +0,0 @@ ---- -- name: install docker - hosts: node-x86.lan - become_method: sudo - become_user: root - become: yes - - tasks: - - name: install needed packages - apt: - update_cache: yes - pkg: - - apt-transport-https - - ca-certificates - - curl - - gnupg-agent - - software-properties-common - - name: add docker gpg key - apt_key: - url: https://download.docker.com/linux/ubuntu/gpg - state: present - - name: add docker repo - apt_repository: - repo: deb https://download.docker.com/linux/ubuntu {{release}} stable - state: present - filename: docker - - name: install docker - apt: - update_cache: yes - pkg: - - docker-ce - - docker-ce-cli - - containerd.io - - name: add current user to docker group - user: - name: "{{ansible_user_id}}" - groups: docker - append: yes \ No newline at end of file diff --git a/docker/nfs-client.yml b/docker/nfs-client.yml deleted file mode 100644 index dd99e44..0000000 --- a/docker/nfs-client.yml +++ /dev/null @@ -1,30 +0,0 @@ ---- -- name: setup nfs-client - hosts: docker_swarm - become_method: sudo - become_user: root - become: yes - - tasks: - - name: install nfs-client - apt: - update_cache: yes - pkg: - - nfs-common - - - name: update rpc config - copy: - src: rpc-statd.service - dest: /lib/systemd/system/rpc-statd.service - - - name: stop and disable rpc - systemd: - name: rpc-statd - state: stopped - enabled: false - - - name: start and enable rpc - systemd: - name: rpc-statd - state: started - enabled: true \ No newline at end of file diff --git a/inventory/hosts.yml b/inventory/hosts.yml index ddfc218..bf95a96 100644 --- a/inventory/hosts.yml +++ b/inventory/hosts.yml @@ -6,7 +6,7 @@ all: prusa.lan: iron-man.lan: children: - docker_swarm: + docker_cluster: hosts: node-01.lan: docker_node: node-01 diff --git a/main.yml b/main.yml index 3702643..48cb906 100644 --- a/main.yml +++ b/main.yml @@ -6,3 +6,7 @@ - hosts: prusa.lan roles: - octoprint + +- hosts: docker_cluster + roles: + - docker-cluster diff --git a/docker/etc/ha.d/ha.cf b/roles/docker-cluster/files/etc/ha.d/ha.cf similarity index 100% rename from docker/etc/ha.d/ha.cf rename to roles/docker-cluster/files/etc/ha.d/ha.cf diff --git a/docker/etc/ha.d/haresources b/roles/docker-cluster/files/etc/ha.d/haresources similarity index 100% rename from docker/etc/ha.d/haresources rename to roles/docker-cluster/files/etc/ha.d/haresources diff --git a/docker/rpc-statd.service b/roles/docker-cluster/files/lib/systemd/system/rpc-statd.service similarity index 100% rename from docker/rpc-statd.service rename to roles/docker-cluster/files/lib/systemd/system/rpc-statd.service diff --git a/docker/hearthbeat.yml b/roles/docker-cluster/tasks/hearthbeat.yml similarity index 71% rename from docker/hearthbeat.yml rename to roles/docker-cluster/tasks/hearthbeat.yml index dbfcdf0..b8e03ae 100644 --- a/docker/hearthbeat.yml +++ b/roles/docker-cluster/tasks/hearthbeat.yml @@ -1,11 +1,6 @@ --- -- name: install and configure heartbeat - hosts: docker_swarm - become_method: sudo - become_user: root - become: yes - - tasks: +- become: yes + block: - name: install heartbeat apt: update_cache: yes diff --git a/roles/docker-cluster/tasks/install-docker-ce.yml b/roles/docker-cluster/tasks/install-docker-ce.yml new file mode 100644 index 0000000..d2a8202 --- /dev/null +++ b/roles/docker-cluster/tasks/install-docker-ce.yml @@ -0,0 +1,37 @@ +--- +- become: yes + block: + - name: install needed packages + apt: + update_cache: yes + pkg: + - apt-transport-https + - ca-certificates + - curl + - gnupg-agent + - software-properties-common + + - name: add docker gpg key + apt_key: + url: https://download.docker.com/linux/ubuntu/gpg + state: present + + - name: add docker repo + apt_repository: + repo: deb https://download.docker.com/linux/ubuntu {{release}} stable + state: present + filename: docker + + - name: install docker + apt: + update_cache: yes + pkg: + - docker-ce + - docker-ce-cli + - containerd.io + + - name: add current user to docker group + user: + name: "{{ansible_user_id}}" + groups: docker + append: yes diff --git a/roles/docker-cluster/tasks/install-docker-io.yml b/roles/docker-cluster/tasks/install-docker-io.yml new file mode 100644 index 0000000..ef51958 --- /dev/null +++ b/roles/docker-cluster/tasks/install-docker-io.yml @@ -0,0 +1,7 @@ +--- +- name: install needed packages + become: yes + apt: + update_cache: yes + pkg: + - docker.io diff --git a/roles/docker-cluster/tasks/main.yml b/roles/docker-cluster/tasks/main.yml new file mode 100644 index 0000000..b4af37e --- /dev/null +++ b/roles/docker-cluster/tasks/main.yml @@ -0,0 +1,11 @@ +--- +- import_tasks: install-docker-ce.yml + when: ansible_distribution == "Ubuntu" and ansible_distribution_version == "18.04" + +- import_tasks: install-docker-io.yml + when: ansible_distribution == "Ubuntu" and ansible_distribution_version != "18.04" + +- import_tasks: nfs-client.yml + +- import_tasks: hearthbeat.yml + diff --git a/roles/docker-cluster/tasks/nfs-client.yml b/roles/docker-cluster/tasks/nfs-client.yml new file mode 100644 index 0000000..a6343c9 --- /dev/null +++ b/roles/docker-cluster/tasks/nfs-client.yml @@ -0,0 +1,25 @@ +--- +- become: yes + block: + - name: install nfs-client + apt: + update_cache: yes + pkg: + - nfs-common + + - name: update rpc config + copy: + src: lib/systemd/system/rpc-statd.service + dest: /lib/systemd/system/rpc-statd.service + + - name: stop and disable rpc + systemd: + name: rpc-statd + state: stopped + enabled: false + + - name: start and enable rpc + systemd: + name: rpc-statd + state: started + enabled: true