#####################################
### someone's ansible provisioner ###
#####################################
# Part of: https://git.somenet.org/root/pub/somesible.git
# 2017-2026 by someone <someone@somenet.org>
#
---
- name: install docker and docker-compose
  apt:
    pkg:
    - docker.io
    - docker-compose
    state: present
    policy_rc_d: 101
  tags: "online"
  ignore_errors: "{{ignore_online_errors | bool}}"


- name: copy daemon.json to /etc/docker/daemon.json
  copy:
    src: "{{item}}"
    dest: "/etc/docker/daemon.json"
    mode: 0644
    owner: "root"
    group: "root"
  with_first_found:
    - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/daemon.json"
    - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/daemon.json"
    - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/daemon.json"
    - "default/daemon.json"
  notify: restart docker.service


- name: copy docker-compose.target to /etc/systemd/system/
  copy:
    src: "{{item}}"
    dest: "/etc/systemd/system/docker-compose.target"
    mode: 0644
    owner: "root"
    group: "root"
  with_first_found:
    - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/docker-compose.target"
    - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/docker-compose.target"
    - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/docker-compose.target"
    - "default/docker-compose.target"
  notify: restart docker-compose.target


- name: copy docker-compose@.service to /etc/systemd/system/
  copy:
    src: "{{item}}"
    dest: "/etc/systemd/system/docker-compose@.service"
    mode: 0644
    owner: "root"
    group: "root"
  with_first_found:
    - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/docker-compose@.service"
    - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/docker-compose@.service"
    - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/docker-compose@.service"
    - "default/docker-compose@.service"
  notify: restart docker-compose.target


- name: enable and start docker.service
  include_role: name="base/systemd/enable-and-start"
  vars:
    service_name: docker.service
