Skip to content

Instantly share code, notes, and snippets.

@13rac1
Created March 18, 2013 22:18
Show Gist options
  • Save 13rac1/5191334 to your computer and use it in GitHub Desktop.
Save 13rac1/5191334 to your computer and use it in GitHub Desktop.
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}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment