From 14cd8ac5d22422ec859e529ab5b58882123d21c8 Mon Sep 17 00:00:00 2001 From: Kienan Stewart Date: Mon, 22 Jan 2024 10:43:31 -0500 Subject: [PATCH] ansible: Add docker role for developer nodes Change-Id: If8df43b443c547f9229c8502146c4c2b9456afc2 Signed-off-by: Kienan Stewart --- .../ansible/roles/docker/defaults/main.yml | 13 ++++++ .../ansible/roles/docker/files/daemon.json | 7 ++++ .../ansible/roles/docker/handlers/main.yml | 5 +++ .../ansible/roles/docker/tasks/main.yml | 42 +++++++++++++++++++ automation/ansible/site.yml | 1 + 5 files changed, 68 insertions(+) create mode 100644 automation/ansible/roles/docker/defaults/main.yml create mode 100644 automation/ansible/roles/docker/files/daemon.json create mode 100644 automation/ansible/roles/docker/handlers/main.yml create mode 100644 automation/ansible/roles/docker/tasks/main.yml diff --git a/automation/ansible/roles/docker/defaults/main.yml b/automation/ansible/roles/docker/defaults/main.yml new file mode 100644 index 0000000..a5f2b6d --- /dev/null +++ b/automation/ansible/roles/docker/defaults/main.yml @@ -0,0 +1,13 @@ +--- + +docker_upstream: true +docker_upstream_packages: + - 'docker-ce' + - 'docker-ce-cli' + - 'containerd.io' + - 'docker-buildx-plugin' + - 'docker-compose-plugin' + +docker_Debian_packages: + - 'docker.io' + - 'docker-compose' diff --git a/automation/ansible/roles/docker/files/daemon.json b/automation/ansible/roles/docker/files/daemon.json new file mode 100644 index 0000000..ac52aef --- /dev/null +++ b/automation/ansible/roles/docker/files/daemon.json @@ -0,0 +1,7 @@ +{ + "bip": "10.11.0.1/16", + "default-address-pools": + [ + {"base":"10.10.0.0/16","size":24} + ] +} diff --git a/automation/ansible/roles/docker/handlers/main.yml b/automation/ansible/roles/docker/handlers/main.yml new file mode 100644 index 0000000..2ec6cb1 --- /dev/null +++ b/automation/ansible/roles/docker/handlers/main.yml @@ -0,0 +1,5 @@ +--- +- name: 'Restart docker' + ansible.builtin.service: + name: 'docker' + state: 'restarted' diff --git a/automation/ansible/roles/docker/tasks/main.yml b/automation/ansible/roles/docker/tasks/main.yml new file mode 100644 index 0000000..775c70c --- /dev/null +++ b/automation/ansible/roles/docker/tasks/main.yml @@ -0,0 +1,42 @@ +--- + +- when: ansible_distribution_release in ['trixie', 'sid'] + ansible.builtin.set_fact: + docker_upstream: false +- ansible.builtin.set_fact: + docker_packages: "{{docker_upstream|ternary(docker_upstream_packages, lookup('vars', 'docker_' + ansible_distribution + '_packages', default=[]))}}" +- when: docker_upstream + block: + - name: Add upstream docker apt key + ansible.builtin.apt_key: + url: 'https://download.docker.com/linux/debian/gpg' + - name: Add upstream docker sources + when: ansible_distribution == 'Debian' + ansible.builtin.apt_repository: + filename: 'docker' + repo: "deb https://download.docker.com/linux/debian {{ansible_distribution_release}} stable" +- name: Deploy docker network configuration + block: + - name: Create docker configuration directory + ansible.builtin.file: + path: '/etc/docker' + state: 'directory' + owner: 'root' + group: 'root' + mode: '0755' + - name: Copy docker configuration + ansible.builtin.copy: + src: 'daemon.json' + dest: '/etc/docker/daemon.json' + owner: 'root' + group: 'root' + mode: '0644' + notify: + - 'Restart docker' +- name: Install docker + ansible.builtin.package: + name: "{{docker_packages}}" +- name: Ensure docker is running + ansible.builtin.service: + name: 'docker' + state: 'started' diff --git a/automation/ansible/site.yml b/automation/ansible/site.yml index a9fef39..b113e9a 100644 --- a/automation/ansible/site.yml +++ b/automation/ansible/site.yml @@ -30,3 +30,4 @@ - hosts: developer roles: - developer + - docker -- 2.34.1