Add docker.yml
This commit is contained in:
60
docker.yml
Normal file
60
docker.yml
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
---
|
||||||
|
- name: Install Docker and add user to docker group
|
||||||
|
hosts: all
|
||||||
|
become: true
|
||||||
|
tasks:
|
||||||
|
- name: Update apt package index and install dependencies
|
||||||
|
ansible.builtin.apt:
|
||||||
|
name:
|
||||||
|
- ca-certificates
|
||||||
|
- curl
|
||||||
|
- gnupg
|
||||||
|
update_cache: yes
|
||||||
|
state: present
|
||||||
|
|
||||||
|
- name: Create directory for Docker's GPG key
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: /etc/apt/keyrings
|
||||||
|
state: directory
|
||||||
|
mode: '0755'
|
||||||
|
|
||||||
|
- name: Download and de-armor Docker's official GPG key
|
||||||
|
ansible.builtin.shell:
|
||||||
|
cmd: curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
|
||||||
|
creates: /etc/apt/keyrings/docker.gpg
|
||||||
|
|
||||||
|
- name: Ensure Docker GPG key has correct permissions
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: /etc/apt/keyrings/docker.gpg
|
||||||
|
mode: '0644'
|
||||||
|
|
||||||
|
- name: Set up Docker's official repository
|
||||||
|
ansible.builtin.shell:
|
||||||
|
cmd: 'echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null'
|
||||||
|
creates: /etc/apt/sources.list.d/docker.list
|
||||||
|
|
||||||
|
- name: Update apt package index after adding repo
|
||||||
|
ansible.builtin.apt:
|
||||||
|
update_cache: yes
|
||||||
|
|
||||||
|
- name: Install Docker Engine and plugins
|
||||||
|
ansible.builtin.apt:
|
||||||
|
name:
|
||||||
|
- docker-ce
|
||||||
|
- docker-ce-cli
|
||||||
|
- containerd.io
|
||||||
|
- docker-buildx-plugin
|
||||||
|
- docker-compose-plugin
|
||||||
|
state: present
|
||||||
|
|
||||||
|
- name: Create docker group
|
||||||
|
ansible.builtin.group:
|
||||||
|
name: docker
|
||||||
|
state: present
|
||||||
|
|
||||||
|
- name: Add user 'linuxadmin' to docker group
|
||||||
|
ansible.builtin.user:
|
||||||
|
name: linuxadmin
|
||||||
|
groups: docker
|
||||||
|
append: yes
|
||||||
|
# replace linuxadmin with the user you want to add to the Docker group.
|
||||||
Reference in New Issue
Block a user