Get the App
SLTechnology News&Howtos  ›  Servers  › 

Ansible-playbook batch increases users, modifies user passwords, and deletes users in batch

Shulou Source: shulou.com Published: 2022-06-03 03:03:33 10月02日 Update

1. Add users in batch: ansible-playbook adduser.yml

[root@mgr ~] # cat adduser.yml-hosts: all remote_user: root tasks:-user: name= "{{item.name}}" group= "{{item.group}}" password= "{{'123456' | password_hash (' sha512')}}" with_items:-{name: "user1", group: "root"}-{name: "user2", group: "root"}-{name: "user3" Group: "apache"} [root@mgr ~] #

2. Modify user password in batches: ansible-playbook moduserpw.yml

[root@mgr ~] # cat moduserpw.yml-hosts: all remote_user: root tasks:-user: name= "{{item.name}}" group= "{{item.group}}" password= "{{'1234567' | password_hash (' sha512')}}" update_password=always with_items:-{name: "user1", group: "root"}-{name: "user2" Group: "root"}-{name: "user3", group: "apache"} [root@mgr ~] #

3. Delete users in batches: ansible-playbook deluser.yml

[root@mgr ~] # cat deluser.yml-hosts: all remote_user: root tasks:-user: name= "{{item.name}}" group= "{{item.group}}" password= "{{'123456' | password_hash (' sha512')}}" state=absent remove=yes with_items:-{name: "user1", group: "root"}-{name: "user2" Group: "root"}-{name: "user3", group: "apache"} [root@mgr ~] #

Tags: User password Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Shulou Technology Docker Microsoft MariaDB