参考答案:
[root@ansible-server ansible]# echo whenyouwishuponastar > /ansible/secret.txt [root@ansible-server ansible]# ansible-vault create locker.yml --vault-password-file secret.txt pwd: Imadev用户变量文件:users.yml user_name: boss
create_users.yaml 要使用变量文件和密码文件 密码使用password_hash(‘sha512’)
参考答案:
[root@ansible-server ansible]# echo user_name: boss > users.yml [root@ansible-server ansible]# vim create_user.yaml --- - hosts: dev vars_files: - users.yml - locker.yml tasks: - name: Create user user: name: "{{ user_name }}" password: "{{ pwd | password_hash('sha512') }}" [root@ansible-server ansible]# ansible-playbook create_user.yaml --vault-password-file secret.txt PLAY [dev] **************************************************************************************************** TASK [Gathering Facts] **************************************************************************************** ok: [node02] TASK [Create user] ******************************************************************************************** changed: [node02] PLAY RECAP **************************************************************************************************** node02 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0更改密码文件locker.yml的保护密码 old:whenyouwishuponastar new:thankyou
参考答案:
[root@ansible-server ansible]# ansible-vault rekey --vault-password-file secret.txt --new-vault-password-file newfile locker.yml Rekey successful