Last active
June 29, 2021 09:30
-
-
Save bidhanahdib/b1cb7a388fdf314897313fd436dd6b1a to your computer and use it in GitHub Desktop.
Ansible Playbook - Playbook to deploy user and their SSH Public Key
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- 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