Asible 修改密码

[root@libin 2022-08-16-ChagePasswd]# cat chagepasswd.yml 
---
- hosts: task
  remote_user: root
  gather_facts: no
  tasks:  
    - name: chage passwd1
      user:
        name: 用户名1
        password: "{{ '密码1' | password_hash('sha512', 'helloworld') }}"
        update_password: always
    - name: chage passwd2
      user:
        name: 用户名2
        password: "{{ '密码2' | password_hash('sha512', 'helloworld') }}"
        update_password: always
    - name: chage passwd3
      user:
        name: 用户名3
        password: "{{ '密码3' | password_hash('sha512', 'helloworld') }}"
        update_password: always

[root@libin2022-08-16-ChagePasswd]# cat hosts 
[task]
IP地址
...

[task:vars]
ansible_become=yes
ansible_become_method=sudo
ansible_become_user=root
ansible_become_password=hellword  #sudo提权密码
ansible_user=libin
ansible_password=hellword         #普通用户密码


[root@libin 2022-08-16-ChagePasswd]# ansible-playbook -i hosts sn.yaml  #执行剧本

  

posted @ 2022-08-17 11:07  LB_运维技术  阅读(25)  评论(0编辑  收藏  举报