add docker_ubuntu role
This commit is contained in:
41
roles/docker_ubuntu/README.md
Normal file
41
roles/docker_ubuntu/README.md
Normal file
@@ -0,0 +1,41 @@
|
||||
docker_ubuntu
|
||||
=========
|
||||
|
||||
Install Docker ecosystem on Ubuntu.
|
||||
|
||||
[](https://github.com/corvus-migratorius/ansible-docker-ubuntu/actions/workflows/lint.yaml)
|
||||
|
||||
[](https://github.com/corvus-migratorius/ansible-docker-ubuntu/actions/workflows/molecule.yaml)
|
||||
|
||||
Requirements
|
||||
------------
|
||||
|
||||
None
|
||||
|
||||
Role Variables
|
||||
--------------
|
||||
|
||||
None
|
||||
|
||||
Dependencies
|
||||
------------
|
||||
|
||||
None
|
||||
|
||||
Example Playbook
|
||||
----------------
|
||||
|
||||
```yaml
|
||||
roles:
|
||||
- role: docker_ubuntu
|
||||
```
|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
BSD
|
||||
|
||||
Author Information
|
||||
------------------
|
||||
|
||||
corvus-migratorius@proton.me
|
||||
5
roles/docker_ubuntu/defaults/main.yml
Normal file
5
roles/docker_ubuntu/defaults/main.yml
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
du_docker_version: "27.3.1"
|
||||
du_registry_mirrors:
|
||||
- https://docker.io
|
||||
- https://mirror.gcr.io
|
||||
11
roles/docker_ubuntu/handlers/main.yml
Normal file
11
roles/docker_ubuntu/handlers/main.yml
Normal file
@@ -0,0 +1,11 @@
|
||||
---
|
||||
# handlers file for playbooks/roles/docker_ubuntu
|
||||
- name: "Restart Docker daemon"
|
||||
ansible.builtin.systemd_service:
|
||||
name: docker
|
||||
state: restarted
|
||||
daemon_reload: true
|
||||
|
||||
- name: "Sanity check" # noqa: no-changed-when
|
||||
ansible.builtin.command:
|
||||
cmd: "docker run --rm --pull=always hello-world"
|
||||
17
roles/docker_ubuntu/meta/main.yml
Normal file
17
roles/docker_ubuntu/meta/main.yml
Normal file
@@ -0,0 +1,17 @@
|
||||
---
|
||||
galaxy_info:
|
||||
role_name: docker_ubuntu
|
||||
namespace: genlab
|
||||
author: "Alexander Gorelyshev"
|
||||
company: "Genlab, LLC"
|
||||
description: "Install Docker ecosystem on Ubuntu"
|
||||
license: "MIT"
|
||||
min_ansible_version: "2.1"
|
||||
|
||||
platforms:
|
||||
- name: "Ubuntu"
|
||||
versions: [ "focal", "jammy", "noble" ]
|
||||
|
||||
galaxy_tags: [ "docker" ]
|
||||
|
||||
dependencies: []
|
||||
9
roles/docker_ubuntu/molecule/default/converge.yml
Normal file
9
roles/docker_ubuntu/molecule/default/converge.yml
Normal file
@@ -0,0 +1,9 @@
|
||||
---
|
||||
- name: Converge
|
||||
hosts: all
|
||||
roles:
|
||||
- role: genlab.docker_ubuntu
|
||||
du_docker_version: "27.3.1"
|
||||
du_registry_mirrors:
|
||||
- https://docker.io
|
||||
- https://mirror.gcr.io
|
||||
27
roles/docker_ubuntu/molecule/default/molecule.yml
Normal file
27
roles/docker_ubuntu/molecule/default/molecule.yml
Normal file
@@ -0,0 +1,27 @@
|
||||
---
|
||||
dependency:
|
||||
name: galaxy
|
||||
|
||||
driver:
|
||||
name: docker
|
||||
|
||||
platforms:
|
||||
- name: ubuntu
|
||||
image: geerlingguy/docker-${MOLECULE_DISTRO:-ubuntu2204}-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
|
||||
|
||||
lint: |
|
||||
set -e
|
||||
yamllint .
|
||||
ansible-lint .
|
||||
31
roles/docker_ubuntu/molecule/default/verify.yml
Normal file
31
roles/docker_ubuntu/molecule/default/verify.yml
Normal file
@@ -0,0 +1,31 @@
|
||||
---
|
||||
- name: Verify
|
||||
hosts: all
|
||||
gather_facts: true
|
||||
any_errors_fatal: true
|
||||
|
||||
tasks:
|
||||
# https://github.com/ansible/molecule/issues/3587#issuecomment-1158650179
|
||||
- name: "Include default vars"
|
||||
ansible.builtin.include_vars:
|
||||
dir: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/defaults/"
|
||||
extensions: [ 'yml' ]
|
||||
|
||||
- name: "Sanity check Docker by running a `hello-world` container" # noqa: no-changed-when
|
||||
ansible.builtin.command:
|
||||
cmd: "docker run --rm hello-world"
|
||||
|
||||
- name: "Check if `Compose` is available from PATH" # noqa: no-changed-when
|
||||
ansible.builtin.command:
|
||||
cmd: "docker compose version"
|
||||
|
||||
- name: "Check if Docker has the expected version" # noqa: no-changed-when
|
||||
register: docker_version
|
||||
ansible.builtin.command:
|
||||
cmd: "docker version --format '{{ '{{' }} .Server.Version {{ '}}' }}'"
|
||||
|
||||
- name: "Check if Docker has the expected version" # noqa: no-changed-when
|
||||
ansible.builtin.assert:
|
||||
that: "du_docker_version in docker_version.stdout"
|
||||
success_msg: "Docker has the expected version ({{ docker_version.stdout }} )"
|
||||
fail_msg: "Unexpected Docker version ({{ docker_version.stdout }})"
|
||||
71
roles/docker_ubuntu/tasks/main.yml
Normal file
71
roles/docker_ubuntu/tasks/main.yml
Normal file
@@ -0,0 +1,71 @@
|
||||
---
|
||||
# REF: https://www.digitalocean.com/community/tutorials/how-to-use-ansible-to-install-and-set-up-docker-on-ubuntu-20-04
|
||||
|
||||
- name: "Install aptitude"
|
||||
ansible.builtin.apt:
|
||||
name: aptitude
|
||||
state: present
|
||||
update_cache: true
|
||||
|
||||
- name: "Install required system packages"
|
||||
ansible.builtin.apt:
|
||||
pkg:
|
||||
- apt-transport-https
|
||||
- ca-certificates
|
||||
- curl
|
||||
- gpg-agent
|
||||
- python3-pip
|
||||
- python3-setuptools
|
||||
- software-properties-common
|
||||
- virtualenv
|
||||
state: present
|
||||
update_cache: true
|
||||
|
||||
- name: "Add Docker GPG apt Key"
|
||||
ansible.builtin.apt_key:
|
||||
url: https://download.docker.com/linux/ubuntu/gpg
|
||||
state: present
|
||||
|
||||
- name: "Add Docker Repository"
|
||||
ansible.builtin.apt_repository:
|
||||
repo: "deb https://download.docker.com/linux/ubuntu {{ ansible_lsb.codename }} stable"
|
||||
state: present
|
||||
|
||||
- name: "Install Docker ecosystem"
|
||||
notify: "Sanity check"
|
||||
ansible.builtin.apt:
|
||||
pkg:
|
||||
- docker-ce={{ du_docker_version_full }}
|
||||
- docker-ce-cli={{ du_docker_version_full }}
|
||||
state: present
|
||||
update_cache: true
|
||||
|
||||
- name: "Ensure the 'docker' group exists"
|
||||
ansible.builtin.group:
|
||||
name: docker
|
||||
state: present
|
||||
system: true
|
||||
|
||||
- name: "Install Python tools for Docker"
|
||||
ansible.builtin.pip:
|
||||
name: [ docker ]
|
||||
break_system_packages: true
|
||||
|
||||
- name: "Configure Docker daemon"
|
||||
notify:
|
||||
- "Restart Docker daemon"
|
||||
- "Sanity check"
|
||||
ansible.builtin.template:
|
||||
src: daemon.json.j2
|
||||
dest: /etc/docker/daemon.json
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0664"
|
||||
validate: "dockerd --validate --config-file=%s"
|
||||
|
||||
- name: "Spin up the Docker system service"
|
||||
notify: "Sanity check"
|
||||
ansible.builtin.systemd:
|
||||
name: docker
|
||||
state: started
|
||||
enabled: true
|
||||
3
roles/docker_ubuntu/templates/daemon.json.j2
Normal file
3
roles/docker_ubuntu/templates/daemon.json.j2
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"registry-mirrors": {{ du_registry_mirrors | to_json }}
|
||||
}
|
||||
2
roles/docker_ubuntu/vars/main.yml
Normal file
2
roles/docker_ubuntu/vars/main.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
---
|
||||
du_docker_version_full: "5:{{ du_docker_version }}-1~ubuntu.{{ ansible_lsb.release }}~{{ ansible_lsb.codename }}"
|
||||
Reference in New Issue
Block a user