方法一、测试过
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
ansible 非root 用户 批量修改用户密码
最新推荐文章于 2024-02-04 22:14:27 发布