Skip to content

Instantly share code, notes, and snippets.

@nitanka
Created August 14, 2017 08:00
Show Gist options
  • Save nitanka/85b912d02c6a90c4de288f5c7972ea68 to your computer and use it in GitHub Desktop.
Save nitanka/85b912d02c6a90c4de288f5c7972ea68 to your computer and use it in GitHub Desktop.
Ansible: Add user to the server
---
- name: Creating new user
user:
name: <username>
group: <groupname>
state: present
shell: /bin/bash #default shell
home: <path_to_home> #example /home/username
#if we donot want home directory to be created,then use createhome: no
password: "{{ lookup('env', 'PASSWD') }}" #set the password for the user
- name: adding keys to the server
authorized_key:
user: <username>
key: "{{ lookup('file', 'path_to/.ssh/id_rsa.pub') }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment