linux:ansible:playbooks:new-user
Adding a new user
Addusers.yml
This playbook takes in a New users name and creates an account for him on all the groups specified Currently it only adds them to the sshusyes group
It sets the password as Password123 and its set to expire on first login
--- - name: Ansible Create user functionlity module demo hosts: all become: true vars: newpassword: Password123 tasks: - name: Add the user primary group of sshusers ansible.builtin.user: name: "{{ username }}" groups: sshusers update_password: always password: "{{ newpassword|password_hash('sha512') }}" createhome: yes # Defaults to yes - name: Expire the password command: passwd -e {{ username }}
To run this playbook you need to specify the extra variables username
ansible-playbook Addusers.yml --extra-vars "username=NewUser"
linux/ansible/playbooks/new-user.txt · Last modified: by 127.0.0.1