ansible-add-user

Created a month ago
Maintained by r4j0x00
Add user to your system with ansible
Members 1
raj committed a month ago

Add user with ansible

Adding a new user to your system with ansible

Description

Ansible is an open-source software provisioning, configuration management, and application-deployment tool. It runs on many Unix-like systems, and can configure both Unix-like systems as well as Microsoft Windows. It uses YAML syntax. The task is to add a new user to the system. The ansible user module can be used to accomplish this. The docs can be looked upon here - https://docs.ansible.com/ansible/latest/modules/user_module.html

Running the playbook

The following command can be used to run the playbook -

➜  ~ ansible-playbook adduser.yaml -e "username=yourusername password=yourpassword shell=/path/to/shell" -K

Adding a user requires root privileges so this prompts for the password. (note that the current user needs to have access to sudo)

Switching to new user

Now to switch to the newly created user we can use the following command -

➜  ~ sudo su - yourusername

This should now switch us to the newly created user.
new_shell