From ed2b519c28a9070e2617eec47b0cab36b62b957e Mon Sep 17 00:00:00 2001 From: cuqmbr Date: Fri, 10 Jan 2025 19:41:39 +0200 Subject: [PATCH] initial commit --- README.md | 44 ++++++++++++++++++++++++++++ defaults/main.yml | 2 ++ handlers/main.yml | 6 ++++ meta/main.yml | 11 +++++++ molecule/default/converge.yml | 15 ++++++++++ molecule/default/molecule.yml | 18 ++++++++++++ tasks/main.yml | 54 +++++++++++++++++++++++++++++++++++ templates/docker.j2 | 1 + 8 files changed, 151 insertions(+) create mode 100644 README.md create mode 100644 defaults/main.yml create mode 100644 handlers/main.yml create mode 100644 meta/main.yml create mode 100644 molecule/default/converge.yml create mode 100644 molecule/default/molecule.yml create mode 100644 tasks/main.yml create mode 100644 templates/docker.j2 diff --git a/README.md b/README.md new file mode 100644 index 0000000..3588f0c --- /dev/null +++ b/README.md @@ -0,0 +1,44 @@ +Docker Engine +========= + +Docker engine installation on Ubuntu 24.04. + +Requirements +------------ + +No requirements. + +Role Variables +-------------- + +Docker daemon options to pass to dockerd command (default: undefined): +`docker_daemon_run_options: "--dns 1.1.1.1 --dns 1.0.0.1"` + +Dependencies +------------ + +No dependencies. + +Example Playbook +---------------- + +--- +- hosts: goapp + + pre_tasks: + - name: Update apt cache. + ansible.builtin.apt: + update_cache: true + cache_valid_time: 86400 + + roles: + - role: cuqmbr.docker + +TODO +---------------- + +Add support for other Linux distrubitions: + +- RHEL: Almalinux, RockyLinux 9 and 8 +- Debian: Debian 12 and 11, Ubuntu 24.04 and 22.04 +- Archlinux diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..d90057a --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# docker_daemon_run_options: "" diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..1cd189d --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,6 @@ +--- + +- name: Restart docker service + ansible.builtin.service: + name: docker + state: restarted diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..368701b --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,11 @@ +--- +galaxy_info: + role_name: docker + author: cuqmbr + description: Docker engine installation for Ubuntu 24.04 + # issue_tracker_url: http://example.com/issue/tracker + license: MIT + min_ansible_version: "2.1" + galaxy_tags: [] + +dependencies: [] diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml new file mode 100644 index 0000000..e5979ee --- /dev/null +++ b/molecule/default/converge.yml @@ -0,0 +1,15 @@ +--- +- name: Converge + hosts: all + + vars: + docker_daemon_run_options: "--dns 1.1.1.1 --dns 1.0.0.1" + + pre_tasks: + - name: Update apt cache. + ansible.builtin.apt: + update_cache: true + cache_valid_time: 86400 + + roles: + - role: cuqmbr.docker diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml new file mode 100644 index 0000000..1fd6ab9 --- /dev/null +++ b/molecule/default/molecule.yml @@ -0,0 +1,18 @@ +--- +dependency: + name: galaxy +driver: + name: docker +platforms: + - name: instance + image: docker.io/geerlingguy/docker-ubuntu2404-ansible:latest + pre_build_image: true + command: ${MOLECULE_DOCKER_COMMAND:-""} + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + cgroupns_mode: host + privileged: true +provisioner: + name: ansible +verifier: + name: ansible diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..f56ed02 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,54 @@ +--- + +- name: Install dependencies. + ansible.builtin.apt: + name: + - ca-certificates + - curl + state: present + +- name: Create apt keys installation directory. + ansible.builtin.file: + path: "/etc/apt/keyrings" + state: directory + mode: "0755" + +- name: Add docker apt key. + ansible.builtin.get_url: + url: "https://download.docker.com/linux/ubuntu/gpg" + dest: "/etc/apt/keyrings/docker.asc" + mode: "0444" + +- name: Add docker apt repository. + ansible.builtin.apt_repository: + repo: "deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.asc] \ + https://download.docker.com/linux/ubuntu noble stable" + filename: docker + state: present + update_cache: true + +- name: Install docker apt packages. + ansible.builtin.apt: + name: + - docker-ce + - docker-ce-cli + - containerd.io + - docker-buildx-plugin + - docker-compose-plugin + state: present + +- name: Start and enable docker service. + ansible.builtin.service: + name: docker + state: started + enabled: true + +- name: Install service parameters file. + ansible.builtin.template: + src: docker.j2 + dest: "/etc/default/docker" + owner: root + group: root + mode: "0644" + notify: + - Restart docker service diff --git a/templates/docker.j2 b/templates/docker.j2 new file mode 100644 index 0000000..a3ab395 --- /dev/null +++ b/templates/docker.j2 @@ -0,0 +1 @@ +DOCKER_OPTS="{{ docker_daemon_run_options }}"