Select Page
- name: create new sudoer user - intended for Digital Ocean and AWS EC2
  hosts: your_instance
  become: yes
  become_method: sudo
  gather_facts: no
  vars:
    user_name: your_user_name
    user_group: your_user_group

  tasks:
  - name: show hosts
    debug: msg="play_hosts={{play_hosts}}"

  - group:
      name: "{{item}}"
      state: present
    with_items:
    - "{{user_group}}"
    
  - user:
      name: "{{user_name}}"
      shell: /bin/bash
      createhome: yes
      group: "{{user_group}}"
      groups: ubuntu,adm,dialout,cdrom,floppy,sudo,audio,dip,video,plugdev,netdev,lxd
      home: "/home/{{user_name}}"
      state: present
      append: yes

  - name: "set {{user_group}} group as sudoer without password"
    lineinfile:
      dest: /etc/sudoers
      state: present
      regexp: '^%{{user_group}}'
      line: '%{{user_group}} ALL=(ALL) NOPASSWD: ALL'