To Create User with Password, the password must be encrypted.
Reference: https://docs.python.org/3/library/crypt.html
# created with:
# python -c 'import crypt; print crypt.crypt("sesame", "$1$opendoor$")'
- name: check if group exists
shell: /usr/bin/getent group $group | /usr/bin/wc -l | tr -d ' '
register: group_exist
- name: check if user exists
shell: /usr/bin/getent passwd $user | /usr/bin/wc -l | tr -d ' '
register: user_exist
- name: Add user "aniu" to the remote server
remote_user: root
user:
name: apple
password: $1$opendoor$oFO4rBXnUmwP3W3rK859N.
comment: "Orange Sales"
uid: 5571
group: users
append: yes
shell: /bin/bash
generate_ssh_key: yes
ssh_key_bits: 2048
ssh_key_file: .ssh/id_rsa
only_if: ${user_exist.stdout} == 0