Files

62 lines
1.4 KiB
YAML

---
- name: Install Docker on VPS
hosts: vps
become: true
tasks:
- name: Update apt cache
apt:
update_cache: yes
- name: Install prerequisites
apt:
name:
- ca-certificates
- curl
- gnupg
state: present
- name: Ensure keyrings directory exists
file:
path: /etc/apt/keyrings
state: directory
mode: '0755'
- name: Download Docker GPG key
get_url:
url: https://download.docker.com/linux/ubuntu/gpg
dest: /etc/apt/keyrings/docker.asc
mode: '0644'
- name: Add Docker APT repository
ansible.builtin.deb822_repository:
name: docker
types: deb
uris: https://download.docker.com/linux/ubuntu
suites: "{{ ansible_facts['distribution_release'] }}"
components: stable
signed_by: /etc/apt/keyrings/docker.asc
- name: Install Docker packages
apt:
name:
- docker-ce
- docker-ce-cli
- containerd.io
- docker-buildx-plugin
- docker-compose-plugin
state: present
- name: Add ubuntu user to docker group
user:
name: ubuntu
groups: docker
append: yes
- name: Start and enable Docker services
systemd:
name: "{{ item }}"
state: started
enabled: yes
loop:
- containerd
- docker