wavedocs
2/25/2016 - 9:11 AM

Create a user in an Ansible playbook with a set, but unknown password so the account is not locked. Makes it possible to log on the account

Create a user in an Ansible playbook with a set, but unknown password so the account is not locked. Makes it possible to log on the account with a public key. This example requires mkpasswd, but that can be replaced with any other password generator.

---
- hosts: all
  gather_facts: yes

    ##
    # Create the password then create the user
    #
    - name: Users | Generate password for new user
      shell: makepasswd --chars=20
      register: user_password 

    - name: Users | Create new user
      user: name=new-user createhome=yes home=/home/new-user generate_ssh_key=yes shell=/bin/bash password=${user_password.stdout}