示例-2密码文件[root@test01 ansible-test]# echo "This-is_a#Test!2o22" > pwdfileecho "This-is_a#Testhistoryo22" > pwdfile[root@test01 ansible-test]#[root@test01 ansible-test]# cat pwdfileThis-is_a#Testhistoryo22[root@test01 ansible-test]#[root@test01 ansible-test]# ansible-vault encrypt test-vault.yml --vault-password-file pwdfileEncryption successful[root@test01 ansible-test]#[root@test01 ansible-test]# cat test-vault.yml$ANSIBLE_VAULT;1.1;AES256633430303766616432376532663661333137353636303535643636313765636132363838633462646163303562643831636237633038373265616334343234630a613466663138396334303463623665303536323962363064356330623838646464666162613930643136333736353536336561613932663234326635323438610a376631323634316663313130356466306238306638613261663138333663303634616164336435306565623131393038313463653465313035306662363730383064356363383966643232646531383461316435643665336665613861363430333934613035303331333030373330643934383363333261646366396330343164393236633138383137316166643966393838396464643238633065393335346639383939623262313731376136306236353135343561633632616262623765[root@test01 ansible-test]#[root@test01 ansible-test]# ansible-vault viewtest-vault.yml --vault-password-file pwdfile- hosts: tagather_facts: notasks:- debug:msg: "test ansible-vault"[root@test01 ansible-test]#[root@test01 ansible-test]# ansible-playbook test-vault.yml --vault-password-file pwdfilePLAY [ta] *********************************************************************************************************************************************************************************************TASK [debug] ******************************************************************************************************************************************************************************************ok: [172.20.8.247] => {"msg": "test ansible-vault"}PLAY RECAP ********************************************************************************************************************************************************************************************172.20.8.247: ok=1changed=0unreachable=0failed=0skipped=0rescued=0ignored=0[root@test01 ansible-test]#[root@test01 ansible-test]# ansible-vault decrypt test-vault.yml --vault-password-file pwdfileDecryption successful[root@test01 ansible-test]#[root@test01 ansible-test]# cat test-vault.yml- hosts: tagather_facts: notasks:- debug:msg: "test ansible-vault"[root@test01 ansible-test]#
示例-3加密字符串[root@test01 ansible-test]# ansible-vault encrypt_string "test123456"New Vault password:Confirm New Vault password:!vault |$ANSIBLE_VAULT;1.1;AES256333833363537373464306531653266653934303465393763343963353365306133306437643139623438366538366262316666353962663564666532393333300a333934633664393262653065343864636533616661333638623530613232383763356661653131303936646237613930333431363432656166663630353038380a6661646435653433363730623231356430383634363439383833633036326230Encryption successful[root@test01 ansible-test]#[root@test01 ansible-test]# vim test-encrypt_string.yaml[root@test01 ansible-test]#[root@test01 ansible-test]# cat test-encrypt_string.yaml- hosts: tagather_facts: novars:test_user: "testuser"test_passwd: !vault |$ANSIBLE_VAULT;1.1;AES256333833363537373464306531653266653934303465393763343963353365306133306437643139623438366538366262316666353962663564666532393333300a333934633664393262653065343864636533616661333638623530613232383763356661653131303936646237613930333431363432656166663630353038380a6661646435653433363730623231356430383634363439383833633036326230tasks:- debug:msg: "{{test_user}}"- debug:msg: "{{test_passwd}}"[root@test01 ansible-test]#[root@test01 ansible-test]# ansible-playbook test-encrypt_string.yaml --ask-vault-passVault password: PLAY [ta] *********************************************************************************************************************************************************************************************TASK [debug] ******************************************************************************************************************************************************************************************ok: [172.20.8.247] => {"msg": "testuser"}TASK [debug] ******************************************************************************************************************************************************************************************ok: [172.20.8.247] => {"msg": "test123456"}PLAY RECAP ********************************************************************************************************************************************************************************************172.20.8.247: ok=2changed=0unreachable=0failed=0skipped=0rescued=0ignored=0[root@test01 ansible-test]#
经验总结扩展阅读
- 自动化专业有必要转计算机吗 未来就业前景好吗
- 机械自动化属于自动化类吗 就业方向及前景怎么样
- 自动化类和计算机类哪个好 发展前景怎么样
- 自动化专业属于计算机大类吗 都学什么课程
- 自动化专业是哪个大类 都学什么课程
- 自动化专业和计算机专业区别 哪个专业前景好
- 小样本利器4. 正则化+数据增强 Mixup Family代码实现
- 从0搭建vue3组件库:自动化发布、管理版本号、生成 changelog、tag
- ansible使用临时命令通过模块来执行任务
- Ansible 批处理实战