Adding and modifying users with Ansible

Whether you are configuring a brand new server for the first time after it has been built or making changes when a new employee joins the company, adding user accounts to a server is a commonly required task. Thankfully, Ansible has a module called user, which is designed to perform user account management tasks, and we shall proceed to use exactly this.

Throughout our previous examples, we have been very careful to highlight the differences between platforms such as Ubuntu and CentOS, and user account management requires a little consideration here too.

Take, for example, the following shell command (which we will later automate in Ansible):

$ useradd -c "John Doe" -s /bin/bash johndoe 

This command ...

Get Hands-On Enterprise Automation on Linux now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.