---
- name: Create hadoop group
  action: group name=hadoop state=present system=yes

- name: Create hadoop user
  action: user name=hadoop state=present group=hadoop comment="Hadoop user" system=yes

- name: Ensure /etc/sudoers.d directory is present
  file: path=/etc/sudoers.d state=directory

- name: Ensure /etc/sudoers.d is scanned by sudo
  action: lineinfile dest=/etc/sudoers regexp="#includedir\s+/etc/sudoers.d" line="#includedir /etc/sudoers.d"

- name: Add hadoop user to the sudoers
  action: 'lineinfile dest=/etc/sudoers.d/hadoop state=present create=yes regexp="hadoop .*" line="hadoop ALL=(ALL) NOPASSWD: ALL"'
  tags: hadoop

- name: Ensure /etc/sudoers.d/hadoop file has correct permissions
  action: file path=/etc/sudoers.d/hadoop mode=0440 state=file owner=root group=root
  tags: hadoop

