Infra_mgmt/roles/docker/tasks/docker.yml

62 lines
1.4 KiB
YAML
Raw Normal View History

2023-02-12 23:18:14 +01:00
- name: Install dependencies for Docker
apt:
name: "{{ docker_dependencies }}"
update_cache: true
- name: Add Docker apt key.
get_url:
url: "{{ docker_apt_gpg_key }}"
dest: /etc/apt/trusted.gpg.d/docker.asc
mode: '0644'
force: true
register: add_repository_key
- name: Add Docker repository
apt_repository:
repo: "{{ docker_apt_repository }}"
state: present
update_cache: true
- name: Install Docker packages
apt:
name: "{{ docker_packages }}"
- name: Ensure /etc/docker/ directory exists
file:
path: /etc/docker
state: directory
mode: 0755
when: docker_daemon_options.keys() | length > 0
- name: Configure Docker daemon options
copy:
content: "{{ docker_daemon_options | to_nice_json }}"
dest: /etc/docker/daemon.json
mode: 0644
when: docker_daemon_options.keys() | length > 0
notify: restart docker
- name: Ensure Docker is started and enabled at boot.
service:
name: docker
state: started
enabled: true
- name: Get docker group info using getent.
getent:
database: group
key: docker
split: ':'
when: docker_users | length > 0
- name: Check if there are any users to add to the docker group
set_fact:
add_to_group: true
when:
- docker_users | length > 0
- item not in ansible_facts.getent_group["docker"][2]
with_items: "{{ docker_users }}"
- include_tasks: docker-users.yml
when: add_to_group is defined