|
1 | | -- name: "Add Docker GPG apt Key" |
2 | | - apt_key: |
| 1 | +--- |
| 2 | +- name: Update and upgrade all packages to the latest version |
| 3 | + ansible.builtin.apt: |
| 4 | + update_cache: true |
| 5 | + upgrade: dist |
| 6 | + cache_valid_time: 3600 |
| 7 | + |
| 8 | +- name: Install required packages |
| 9 | + ansible.builtin.apt: |
| 10 | + pkg: |
| 11 | + - apt-transport-https |
| 12 | + - ca-certificates |
| 13 | + - curl |
| 14 | + - gnupg |
| 15 | + - software-properties-common |
| 16 | + |
| 17 | +- name: Create directory for Docker's GPG key |
| 18 | + ansible.builtin.file: |
| 19 | + path: /etc/apt/keyrings |
| 20 | + state: directory |
| 21 | + mode: "0755" |
| 22 | + |
| 23 | +- name: Add Docker's official GPG key |
| 24 | + ansible.builtin.apt_key: |
3 | 25 | url: https://download.docker.com/linux/ubuntu/gpg |
| 26 | + keyring: /etc/apt/keyrings/docker.gpg |
| 27 | + state: present |
| 28 | + |
| 29 | +- name: Print architecture variables |
| 30 | + ansible.builtin.debug: |
| 31 | + msg: "Architecture: {{ ansible_architecture }}, Codename: {{ ansible_lsb.codename }}" |
| 32 | + |
| 33 | +- name: Add Docker repository |
| 34 | + ansible.builtin.apt_repository: |
| 35 | + repo: >- |
| 36 | + deb [arch={{ arch_mapping[ansible_architecture] | default(ansible_architecture) }} |
| 37 | + signed-by=/etc/apt/keyrings/docker.gpg] |
| 38 | + https://download.docker.com/linux/ubuntu {{ ansible_lsb.codename }} stable |
| 39 | + filename: docker |
4 | 40 | state: present |
| 41 | + vars: |
| 42 | + arch_mapping: |
| 43 | + x86_64: amd64 |
5 | 44 |
|
6 | | -- name: "Add Docker Repository" |
7 | | - apt_repository: |
8 | | - repo: "deb https://download.docker.com/linux/ubuntu {{ ansible_lsb.codename|lower }} stable" |
| 45 | +- name: Install Docker and related packages |
| 46 | + ansible.builtin.apt: |
| 47 | + name: "{{ item }}" |
9 | 48 | state: present |
| 49 | + update_cache: true |
| 50 | + with_items: |
| 51 | + - docker-buildx-plugin |
| 52 | + - docker-compose-plugin |
10 | 53 |
|
11 | | -- name: "Update apt and install docker-ce" |
12 | | - apt: update_cache=yes name=docker-ce state=latest |
13 | 54 |
|
14 | | -- name: "Install Docker Module for Python" |
15 | | - pip: |
| 55 | +- name: Install Docker |
| 56 | + apt: |
| 57 | + name: docker.io |
| 58 | + state: present |
| 59 | + tags: install |
| 60 | + |
| 61 | +- name: Configure Docker |
| 62 | + copy: |
| 63 | + content: |- |
| 64 | + { |
| 65 | + "mtu":{{ ansible_default_ipv4.mtu }} |
| 66 | + } |
| 67 | + dest: /etc/docker/daemon.json |
| 68 | + owner: root |
| 69 | + group: root |
| 70 | + mode: "0o644" |
| 71 | + |
| 72 | +- name: Restart Docker Service |
| 73 | + systemd: |
16 | 74 | name: docker |
| 75 | + state: restarted |
17 | 76 |
|
| 77 | +- name: Create docker group and change GID |
| 78 | + group: |
| 79 | + name: docker |
| 80 | + gid: 1234 |
| 81 | + state: present |
18 | 82 |
|
19 | | -- name: "Ensure the user {{ ansible_user }} is part of the docker group" |
| 83 | +- name: Append ubuntu user to group docker |
20 | 84 | user: |
21 | | - name: "{{ ansible_user }}" |
| 85 | + name: ubuntu |
| 86 | + append: true |
22 | 87 | groups: docker |
23 | | - append: yes |
24 | 88 |
|
| 89 | +- name: (Re-)start docker socket |
| 90 | + systemd: |
| 91 | + name: docker.socket |
| 92 | + state: restarted |
25 | 93 |
|
26 | 94 | - name: Create forc backup host folder |
27 | 95 | file: |
|
0 commit comments