Manage User Accounts with Ansible

Ansible is a program designed to manage Linux servers. See blog post on setting up Ansible, creating a script, creating an inventory file, and calling a script from the command line. You can call a single server or multiple servers by separating then with a colon on the ‘hosts’ line. If a large number of hosts needs to be called, create a group in the inventory.ini file and call the group on the ‘hosts’ line.

Create a New User’s Account on Multiple Servers

When a new hire comes onboard, rather than log into each server directly and manually create their accounts, run this script and it will create the accounts on all servers simultaneously.

Get a List of Servers that have a Specific User’s Account

If a user leaves the company, you can never be sure what Linux servers they were given access to, so I run this to get a list of what servers they have accounts. It outputs the results to a text file, which the results can be easily be viewed. This script calls a host group called “all_servers” in the inventory.ini file.

Remove A User’s Account

Once you have identified which servers the user has an account on, add the username to the script and specify the target hosts. As before, you can list multiple servers, separated by a colon, or create a group in the *ini file and then add the group name to the ‘hosts’ line.

Push a Key to Multiple Servers

It is recommended that users login using public and private keys. It is easy to push a users public key to multiple servers at same time. Replace the ‘key’, with the user’s actual public key surrounded by double quotes.

The authorized key command handles creating the directors and setting permissions on all files.

Change a User’s Password

Perhaps a user forgot their password, or they have left the company. You may need to change their password. Again, modify the ‘hosts’ line as necessary, with a single, multiple, or a group of servers.

Related Posts