机密
创建加密文件
//创建
[root@192 group_vars]# ansible-vault create group_vars/apache
New Vault password:
Confirm New Vault password:
[WARNING]: group_vars does not exist, creating...
//查看
[root@192 group_vars]# ansible-vault view group_vars/apache
Vault password:
passwd:123456
//解密
[root@192 playbook]# ansible-vault decrypt group_vars/apache
Vault password:
Decryption successful
//查看是否还需要密码
[root@192 playbook]# cat group_vars/apache
passwd:123456
//加密,apache事先存在
[root@192 playbook]# ansible-vault encrypt group_vars/apache
New Vault password:
Confirm New Vault password:
Encryption successful
//查看
[root@192 playbook]# ansible-vault view group_vars/apache
Vault password:
passwd:123456
//之前加密文件内容是passwd:123456,现在重新编辑为000000
[root@192 playbook]# ansible-vault edit group_vars/apache
Vault password:
[root@192 playbook]# ansible-vault view group_vars/apache
Vault password:
passwd:000000
//之前group_vars/apache加密的密码是123456,现在改为111111
[root@192 playbook]# ansible-vault rekey group_vars/apache
Vault password:
New Vault password:
Confirm New Vault password:
Rekey successful //修改密码成功
使用文件加密
- 把密码放在文件里,使用文件加密,可以把文件设置为隐藏文件,名字不要太明显
- 使用文件加密好处还有就是查看加密文件时不需要手动输入密码
- 命令:–vault-password-file=密码存放的文件名字
//把密码放进隐藏文件
[root@192 playbook]# vim .np
123456
//使用文件查看
[r