mirror of
https://github.com/morten-olsen/configs.git
synced 2026-02-08 00:46:24 +01:00
93 lines
2.1 KiB
YAML
93 lines
2.1 KiB
YAML
---
|
|
# https://medium.com/@GarisSpace/how-to-install-docker-using-ansible-01a674086f8c
|
|
- name: Setting host facts
|
|
ansible.builtin.set_fact:
|
|
arch_mapping: # Map ansible architecture {{ ansible_architecture }} names to Docker's architecture names
|
|
x86_64: amd64
|
|
aarch64: arm64
|
|
tags:
|
|
- always
|
|
|
|
- name: Install required packages
|
|
tags:
|
|
- install
|
|
ansible.builtin.apt:
|
|
pkg:
|
|
- apt-transport-https
|
|
- ca-certificates
|
|
- curl
|
|
- gnupg
|
|
- software-properties-common
|
|
|
|
- name: Create directory for Docker's GPG key
|
|
tags:
|
|
- install
|
|
ansible.builtin.file:
|
|
path: /etc/apt/keyrings
|
|
state: directory
|
|
mode: "0755"
|
|
|
|
- name: Add Docker's official GPG key
|
|
tags:
|
|
- install
|
|
ansible.builtin.apt_key:
|
|
url: https://download.docker.com/linux/ubuntu/gpg
|
|
keyring: /etc/apt/keyrings/docker.gpg
|
|
state: present
|
|
|
|
- name: Print architecture variables
|
|
tags:
|
|
- install
|
|
ansible.builtin.debug:
|
|
msg: "Architecture: {{ ansible_architecture }}, Codename: {{ ansible_lsb.codename }}"
|
|
|
|
- name: Add Docker repository
|
|
tags:
|
|
- install
|
|
ansible.builtin.apt_repository:
|
|
repo: >-
|
|
deb [arch={{ arch_mapping[ansible_architecture] | default(ansible_architecture) }}
|
|
signed-by=/etc/apt/keyrings/docker.gpg]
|
|
https://download.docker.com/linux/ubuntu {{ ansible_lsb.codename }} stable
|
|
filename: docker
|
|
state: present
|
|
|
|
- name: Install Docker and related packages
|
|
tags:
|
|
- install
|
|
ansible.builtin.apt:
|
|
name:
|
|
- docker-ce
|
|
- docker-ce-cli
|
|
- containerd.io
|
|
- docker-buildx-plugin
|
|
- docker-compose-plugin
|
|
state: present
|
|
update_cache: true
|
|
|
|
- name: Add Docker group
|
|
tags:
|
|
- install
|
|
ansible.builtin.group:
|
|
name: docker
|
|
state: present
|
|
|
|
- name: Add user to Docker group
|
|
tags:
|
|
- install
|
|
ansible.builtin.user:
|
|
name: "{{ username }}"
|
|
groups: docker
|
|
append: true
|
|
|
|
- name: Enable and start Docker services
|
|
tags:
|
|
- install
|
|
ansible.builtin.systemd:
|
|
name: "{{ item }}"
|
|
enabled: true
|
|
state: started
|
|
loop:
|
|
- docker.service
|
|
- containerd.service
|