---
# Tasks for user
# If GID was specified use that
- name: add defined user group
  action: group name={{username | mandatory}} gid={{gid}} state=present
  when: gid is defined
# Otherwise use the next GID available to the system
- name: add default user group
  action: group name={{username | mandatory}} state=present
  when: gid is not defined
# If UID was specified use that 
- name: add user with defined uid
  action: user
    name={{username | mandatory}}
    uid={{uid}}
    shell=/bin/bash
    group={{username | mandatory}}
    groups=sudo,vboxsf,vagrant
    append=yes
    password={{password | mandatory}}
    update_password=on_create
    state=present
  when: uid is defined
# Otherwise use the next UID available to the system (seems like a lot of copy/pasta)
- name: add user with default uid
  action: user
    name={{username | mandatory}}
    shell=/bin/bash
    group={{username | mandatory}}
    groups=sudo,vboxsf,vagrant
    append=yes
    password={{password | mandatory}}
    update_password=on_create
    state=present
  when: uid is not defined

---
# Tasks for user
# If GID was specified use that
- name: add defined user group
  action: group name={{username | mandatory}} gid={{gid}} state=present
  when: gid is defined
# Otherwise use the next GID available to the system
- name: add default user group
  action: group name={{username | mandatory}} state=present
  when: gid is not defined
# If UID was specified use that 
- name: add user with defined uid
  action: user
    name={{username | mandatory}}
    uid={{uid}}
    shell=/bin/bash
    group={{username | mandatory}}
    groups=sudo,vboxsf,vagrant
    append=yes
    password={{password | password_hash('sha512') | mandatory}}
    update_password=on_create
    state=present
  when: uid is defined
# Otherwise use the next UID available to the system (seems like a lot of copy/pasta)
- name: add user with default uid
  action: user
    name={{username | mandatory}}
    shell=/bin/bash
    group={{username | mandatory}}
    groups=sudo,vboxsf,vagrant
    append=yes
    password={{password | password_hash('sha512') | mandatory}}
    update_password=on_create
    state=present
  when: uid is not defined
# Install an SSH key for the user if specified
- name: install user SSH key
  action: authorized_key user={{ username | mandatory }} key="{{sshkey}}"
  when: sshkey is defined

Fix setting default password, add authorized_key
Fix setting default password, add authorized_key
