# This task maintains elevated access for specific users and adds them to the docker group.

---
- block:
  - name: Add users to sudoer file
    lineinfile:
      dest: /etc/sudoers
      line: '{{ item }}   ALL=(ALL:ALL) NOPASSWD: ALL'
      insertafter: EOF
      validate: /usr/sbin/visudo -csf %s
    loop: '{{ users_list }}'

  - name: Create docker group
    group:
      name: docker

  - name: Add user to docker group
    user:
      name: "{{ item }}"
      groups: docker
      append: yes
    loop: '{{ users_list }}'

  - name: Add user to dialout group
    user:
      name: "{{ item }}"
      groups: dialout
      append: yes
    loop: '{{ users_list }}'

  become: yes
