linux批量改密码ansible实战(转)

使用Ansible的user模块批量修改远程客户机的用户密码

[root@localhost ansible]# cat root_passwd.yaml
---
  - hosts: web
    gather_facts: false
    tasks:
    - name: change user passwd
      user: name={{ item.name }} password={{ item.chpass | password_hash('sha512') }}  update_password=always
      with_items:
           - { name: 'root', chpass: 'kevin@123' }
             # - { name: 'app', chpass: 'bjop123' }
[root@localhost ansible]# ansible-playbook root_passwd.yaml

修改远程主机的单个用户密码使用此方法比较方便

[root@localhost ansible]# cat root_passwd2.yaml
---
  - hosts: 10.65.78.71
    gather_facts: false
    tasks:
    - name: Change password
      user: name={{ name1 }}  password={{ chpass | password_hash('sha512') }}  update_password=always
[root@localhost ansible]# ansible-playbook root_passwd2.yaml -e "name1=root chpass=kevin@123"

posted @ 2023-02-09 11:04  寻梦99  阅读(339)  评论(0编辑  收藏  举报