ansible-更新密码

ymal配置文件

---
- hosts: password
  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: 'admin#123' }
交互式创建用户设置密码
交互式创建批量用户
[root@ansible ansible]# cat adduser.yaml 
--- 
- hosts: test
  remote_user: root
  vars_prompt:
       - name: "usename"
         prompt: "please enter your create user"
         private: no
       - name: "password"
         prompt: "please enter your password"
         encrypt: "sha512_crypt" 
         confirm: yes
  tasks: 
       - name: create user
         user: name="{{usename}}" password="{{password}}" 

[root@ansible ansible]# ansible-playbook adduser.yaml 
please enter your create user: test3 
please enter your password: 

PLAY [test] *******************************************************************************************************************************************************************************************************

TASK [Gathering Facts] ********************************************************************************************************************************************************************************************
ok: [192.168.10.21]
ok: [192.168.10.20]

TASK [create user] ************************************************************************************************************************************************************************************************
changed: [192.168.10.20]
changed: [192.168.10.21]

PLAY RECAP ********************************************************************************************************************************************************************************************************
192.168.10.20              : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
192.168.10.21              : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

[root@ansible ansible]# ssh test3@192.168.10.20 
test3@192.168.10.20's password: 
[test3@gitlab ~]$ 

  • 我的微信
  • 这是我的微信扫一扫
  • weinxin
  • 我的微信公众号
  • 我的微信公众号扫一扫
  • weinxin
avatar

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: