Uses usermod and groupmod to rename an user
The role
- Assumes that the user
user
also has a associated primary groupuser
. - Requires a working
become
forroot
(via passwordlesssudo
or configuredansible_become_pass
using passwordstore) - Asserts that old user and group exist and that new user and group don't exists
- Don't assumes the home directory is in
/home
(i.e. computes new path from old)
Notes that usermod correctly remames user in group_name from
/etc/group
Using a simple requirement file
- src: https://github.com/thydel/ar-rename-user.git
name: rename-user
version: master
ansible-galaxy install -r requirement.yml
Using ansible-toolbox, from a playbook-dir with a valid
inventory and roles_path defined via ansible.cfg
ansible-role -GH a_node rename-user -e old=dupont -e new=dupond -C
Or Using play.yml to first select nodes where user exists and apply role (Still from a playbook-dir with a valid inventory and roles_path)
roles/rename-user/play.yml -l a_group -e old=dupont -e new=dupond -C