ansible: Add docker role for developer nodes
authorKienan Stewart <kstewart@efficios.com>
Mon, 22 Jan 2024 15:43:31 +0000 (10:43 -0500)
committerKienan Stewart <kstewart@efficios.com>
Mon, 22 Jan 2024 15:43:31 +0000 (10:43 -0500)
Change-Id: If8df43b443c547f9229c8502146c4c2b9456afc2
Signed-off-by: Kienan Stewart <kstewart@efficios.com>
automation/ansible/roles/docker/defaults/main.yml [new file with mode: 0644]
automation/ansible/roles/docker/files/daemon.json [new file with mode: 0644]
automation/ansible/roles/docker/handlers/main.yml [new file with mode: 0644]
automation/ansible/roles/docker/tasks/main.yml [new file with mode: 0644]
automation/ansible/site.yml

diff --git a/automation/ansible/roles/docker/defaults/main.yml b/automation/ansible/roles/docker/defaults/main.yml
new file mode 100644 (file)
index 0000000..a5f2b6d
--- /dev/null
@@ -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 (file)
index 0000000..ac52aef
--- /dev/null
@@ -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 (file)
index 0000000..2ec6cb1
--- /dev/null
@@ -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 (file)
index 0000000..775c70c
--- /dev/null
@@ -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'
index a9fef39e1fad91b8c47477d1f67b80ffdb834597..b113e9adc0143939c8c9285c0bca4e7597542606 100644 (file)
@@ -30,3 +30,4 @@
 - hosts: developer
   roles:
     - developer
+    - docker
This page took 0.025004 seconds and 4 git commands to generate.