/ar-rename-user

Ansible role to rename a user account

What

Uses usermod and groupmod to rename an user

  • usermod will change the login name and move home directory
  • groupmod will change the group name

The role

  • Assumes that the user user also has a associated primary group user.
  • Requires a working become for root (via passwordless sudo or configured ansible_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

How

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 

Direct use

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

Via playbook

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