Skip to content

Instantly share code, notes, and snippets.

@bidhanahdib
Last active June 29, 2021 09:30
Show Gist options
  • Save bidhanahdib/b1cb7a388fdf314897313fd436dd6b1a to your computer and use it in GitHub Desktop.
Save bidhanahdib/b1cb7a388fdf314897313fd436dd6b1a to your computer and use it in GitHub Desktop.
Ansible Playbook - Playbook to deploy user and their SSH Public Key
---
- name: Create New User
hosts: all
become: true
gather_facts: false
vars:
# Define your username and password here that you want to create on target hosts.
username: newuser
userpass: user_password
tasks:
- name: Create User
ansible.builtin.user:
name: "{{ username }}"
state: present
shell: /bin/bash
password: "{{ userpass | password_hash('sha512') }}"
update_password: on_create
groups: "{{ super_group }}"
append: yes
- name: Deploy SSH Public Key
ansible.posix.authorized_key:
user: "{{ username }}"
state: present
key: "{{ lookup('file', '/home/{{ username }}/.ssh/id_rsa.pub') }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment