Ansible role to create linux users with Github accounts ssh key

In this short tutorial we’ll learn how to create or delete the linux user accounts with public ssh keys associated with their Github accounts using Ansible, so please create a Github account if you don’t already have one, and follow the instructions for associated SSH keys with your account, if you didn’t perform it already.

First, download this Repository from the GitHub:

git clone

Note: If git is not installed then you can simply download the zip file.

Move inside the cloned directory:

cd ansible-roles

To use this role, edit the site.yml file:

vi site.yml

After that, edit the hosts file and enter the ip of your remote server, on which you want to perform all these tasks:

vi hosts

In my case, it is


After that edit the users-with-github-key/defaults/main.yml file:

Change the username(s), type(either admin/sudo user or not) and state of the user(want to create or remove it on the target system). These are self explanatory.

There are generally two classes of users:
(1) admin users with full sudo permissions
(2) normal login users without any special permissions
The parameter "type" sets the user in one of these two categories:
(1) type: admin
(2) type: normal

Then run this command:

ansible-playbook -i hosts -u arbabnazar site.yml


Note: Please don’t forget to change arbabnazar with your username, although it first try to use login user but I have mentioned it explicitly to show the complete example.

Enjoy :-)

Hope this will help you!

Please Remember me in your prayers!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: