---
- name: install docker
  become: yes
  apt:
    state: present
    install_recommends: no
    name:
      - docker.io
      - docker-compose
      - cadvisor
      - ctop
      - rawdns

- name: create the folder for docker
  become: yes
  file:
    path: /etc/systemd/system/docker.service.d
    state: directory

- name: create Proxy configurations
  become: yes
  template:
    src: "{{ item.src }}"
    dest: "{{ item.dest }}"
  notify: restart docker
  with_items:
    - { src: http-proxy.conf.j2, dest: /etc/systemd/system/docker.service.d/http-proxy.conf }
    - { src: https-proxy.conf.j2, dest: /etc/systemd/system/docker.service.d/https-proxy.conf }

- name: Flush changes
  become: yes
  systemd:
    daemon_reload: yes

- name: add group of docker
  become: yes
  group:
    name: docker
    state: present

- name: get the current user name
  shell: whoami
  register: current_user

- name: add the current user to the docker group
  become: yes
  user:
    name: "{{ current_user.stdout }}"
    groups: docker
    append: yes

      

---
- name: install docker
  become: yes
  apt:
    state: present
    install_recommends: no
    name:
      - docker.io
      - docker-compose
      - cadvisor
      - ctop
      - rawdns

- name: create the folder for docker
  become: yes
  file:
    path: /etc/systemd/system/docker.service.d
    state: directory

- name: create Proxy configurations
  become: yes
  template:
    src: "{{ item.src }}"
    dest: "{{ item.dest }}"
  notify: restart docker
  with_items:
    - { src: http-proxy.conf.j2, dest: /etc/systemd/system/docker.service.d/http-proxy.conf }
    - { src: https-proxy.conf.j2, dest: /etc/systemd/system/docker.service.d/https-proxy.conf }

- name: Flush changes
  become: yes
  systemd:
    daemon_reload: yes

- name: add group of docker
  become: yes
  group:
    name: docker
    state: present

- name: get the current user name
  shell: whoami
  register: current_user

- name: add the current user to the docker group
  become: yes
  user:
    name: "{{ current_user.stdout }}"
    groups: docker
    append: yes

# Out of the box a Docker installation on Ubuntu is capable of setting memory limits
-name: allow to set memory limits
  become: yes
  lineinfile:
    path: /etc/default/grub
    regexp: '^GRUB_CMDLINE_LINUX='
    line: 'GRUB_CMDLINE_LINUX="cgroup_enable=memory swapaccount=1"'
    
-name: update the grub configuration
  become: yes
  command: update-grub

Allow docker to set memory limits
Allow docker to set memory limits
