To automate the creation of users, assignment to groups, and password management across multiple Linux servers using Ansible. Sensitive data such as passwords will be securely stored using Ansible Vault to ensure security.
sudo apt update && sudo apt install -y ansible
ssh-keygen -t rsa -b 4096
ssh-copy-id user@managed_node_ip
[linux_servers]
server1 ansible_host=192.168.1.10 ansible_user=admin
server2 ansible_host=192.168.1.11 ansible_user=admin
ansible-vault create secret.yml
users:
- name: devuser
password: "$6$rounds=5000$EXAMPLE$hash"
- name: opsuser
password: "$6$rounds=5000$EXAMPLE$hash"
ansible-vault encrypt secret.yml
ansible-vault edit secret.yml
ansible-galaxy init roles/user_management
- name: Create user accounts
user:
name: "{{ item.name }}"
password: "{{ item.password }}"
state: present
shell: /bin/bash
groups: "developers"
append: yes
loop: "{{ users }}"
---
- name: Manage Users and Groups
hosts: linux_servers
become: yes
vars_files:
- secret.yml
roles:
- user_management
ansible-playbook user_management.yml --ask-vault-pass
cat /etc/passwd | grep devuser
cat /etc/group | grep developers
devuser
, opsuser
) are created on all managed nodes.This setup ensures scalable, automated user and group management with secure password handling using Ansible and Ansible Vault.