ansible 非root 用户 批量修改用户密码

方法一、测试过
ansible使用执行脚本 修改密码

1、
# vi change-root-password.sh 
#!/bin/bash
sudo echo "123456" | sudo passwd --stdin root

2、
# cat host
[total:vars]
ansible_ssh_user=test
ansible_ssh_pass=******
[total]
20.40.1.5
20.40.1.6
20.40.1.7
20.40.1.8

3、
执行脚本
# ansible total -m script -a " change-root-password.sh" -i  host

方法二、测试过

# cat  change-root-password.yaml
---
- hosts: "{{ zone }}"
  gather_facts: no

  tasks:
    - name: change root password
      shell: sudo echo "123456" | sudo passwd --stdin root


[root@xy-ironic-rebuild-test1 ironic]# cat test 
[total:vars]
ansible_ssh_user=ironic
ansible_ssh_pass=******

[total]
20.40.1.28  
20.40.1.21  


# ansible-playbook -e zone=total change-root-password.yaml -i test

PLAY [total] ******************************************************************************************************************************************************************************

TASK [change root password] ***************************************************************************************************************************************************************
[WARNING]: Consider using 'become', 'become_method', and 'become_user' rather than running sudo

changed: [20.40.1.21]
changed: [20.40.1.28]

PLAY RECAP ********************************************************************************************************************************************************************************
20.40.1.21                 : ok=1    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
20.40.1.28                 : ok=1    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值