Last active
September 24, 2024 12:40
-
-
Save Alevsk/8737d992cae94c6f66e713403234d587 to your computer and use it in GitHub Desktop.
Ansible playbook to install docker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- hosts: "{{ HOSTS }}" | |
name: Install Docker | |
become: yes | |
vars: | |
docker_group: docker | |
tasks: | |
- name: Install apt-transport-https | |
ansible.builtin.apt: | |
name: | |
- apt-transport-https | |
- ca-certificates | |
- lsb-release | |
- gnupg | |
state: latest | |
update_cache: true | |
- name: Add signing key | |
ansible.builtin.apt_key: | |
url: "https://download.docker.com/linux/{{ ansible_os_family | lower }}/gpg" | |
state: present | |
- name: Get DEB architecture | |
shell: dpkg --print-architecture | |
register: deb_architecture | |
- name: Check distribution | |
set_fact: | |
distribution: Debian | |
distribution_release: bullseye | |
when: ansible_distribution == "Kali" and ansible_distribution_release == "kali-rolling" | |
- name: Set default distribution values | |
set_fact: | |
distribution: "{{ ansible_distribution }}" | |
distribution_release: "{{ ansible_distribution_release }}" | |
when: distribution is not defined and distribution_release is not defined | |
- name: Add repository into sources list | |
ansible.builtin.apt_repository: | |
repo: "deb [arch={{ deb_architecture.stdout }}] https://download.docker.com/linux/{{ distribution | lower }} {{ distribution_release }} stable" | |
state: present | |
filename: docker | |
- name: Install Docker | |
ansible.builtin.apt: | |
name: | |
- docker-ce | |
- docker-ce-cli | |
- containerd.io | |
- docker-compose | |
- docker-compose-plugin | |
state: latest | |
update_cache: true | |
- name: Start and enable service docker | |
ansible.builtin.service: | |
name: docker | |
enabled: yes | |
state: started | |
- name: Create docker group | |
group: | |
name: "{{ docker_group }}" | |
state: present | |
- name: Add user to docker group | |
user: | |
name: "{{ ansible_user }}" | |
group: "{{ docker_group }}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment