diff --git a/inventory/hosts.yml b/inventory/hosts.yml index 2c226df..6b13e52 100644 --- a/inventory/hosts.yml +++ b/inventory/hosts.yml @@ -72,6 +72,10 @@ all: ansible_host: 192.168.50.186 vars: ip: 186 + remote_server: + ansible_host: + ansible_become_password: + ansible_user: ubuntu children: raspberry: hosts: diff --git a/main.yml b/main.yml index f295e65..2951cdf 100644 --- a/main.yml +++ b/main.yml @@ -19,3 +19,7 @@ - hosts: router.lan roles: - router + +- hosts: remote_server + roles: + - docker diff --git a/roles/docker/tasks/docker-cron.yml b/roles/docker/tasks/docker-cron.yml new file mode 100644 index 0000000..ef8cc82 --- /dev/null +++ b/roles/docker/tasks/docker-cron.yml @@ -0,0 +1,17 @@ +- name: Clean docker system + become: yes + ansible.builtin.cron: + user: root + name: "clean docker system" + minute: "0" + hour: "3" + job: "/usr/bin/docker system prune -f" + +- name: Clean docker image cache + become: yes + ansible.builtin.cron: + user: root + name: "clean docker system" + minute: "0" + hour: "3" + job: "/usr/bin/docker image prune -a -f" diff --git a/roles/docker/tasks/install-docker-ce.yml b/roles/docker/tasks/install-docker-ce.yml new file mode 100644 index 0000000..3dbd2c8 --- /dev/null +++ b/roles/docker/tasks/install-docker-ce.yml @@ -0,0 +1,49 @@ +--- +- 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 {{ ansible_distribution_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 + + - name: start and enable docker + systemd: + name: docker + state: started + enabled: true + + - name: add current user to docker group + user: + name: "{{ ansible_user_id }}" + append: yes + groups: docker diff --git a/roles/docker/tasks/install-docker-io.yml b/roles/docker/tasks/install-docker-io.yml new file mode 100644 index 0000000..d322d19 --- /dev/null +++ b/roles/docker/tasks/install-docker-io.yml @@ -0,0 +1,20 @@ +--- +- become: yes + block: + - name: install needed packages + apt: + update_cache: yes + pkg: + - docker.io + + - name: start and enable docker + systemd: + name: docker + state: started + enabled: true + + - name: add current user to docker group + user: + name: "{{ ansible_user_id }}" + append: yes + groups: docker diff --git a/roles/docker/tasks/main.yml b/roles/docker/tasks/main.yml new file mode 100644 index 0000000..6828e80 --- /dev/null +++ b/roles/docker/tasks/main.yml @@ -0,0 +1,8 @@ +--- +- 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: docker-cron.yml \ No newline at end of file