众所周知,ansible是很火的一个自动化部署工具,在ansible控制节点内,存放着当前环境服务的所有服务的配置信息,其中自然也包括一些敏感的信息,例如明文密码、IP地址等等。
从安全角度来讲,这些敏感数据的文件不应该以明文的形式存在。此时就用到了ansible加密的特性。
ansible通过命令行「ansible-vault」给你目标文件/字符串进行加密。在执行playbook时,通过指定相应参数来给目标文件解密,从而实现ansible vault的功能。
ansible可以加密任何部署相关的文件数据,例如:
主机/组变量等所有的变量文件
tasks、hanlders等所有的playbook文件
命令行导入的文件(eg : -e @file.yaml ,-e @file.json)
copy,template的模块里src参数所使用的文件,甚至是二进制文件。
playbook里用到的某个字符串参数也可以加密(Ansible>=2.3)
# yum -y install epel-release
# yum -y install ansbile
# ansible-vault --help
# man ansible-vault > ansible-vault.md
准备一个写有明文的文件
# echo "123456" > /path/to/passwd.txt
读取密码加密hosts或者yml文件
# ansible-vault encrypt --vault-password-file /path/to/passwd.txt /path/to/hosts
# ansible-vault encrypt --vault-password-file /path/to/passwd.txt /path/to/install_X.yml
读取明文密码,解密文件
# ansible-vault decrypt --vault-password-file /path/to/passwd.txt /path/to/hosts
# ansible-vault decrypt --vault-password-file /path/to/passwd.txt /path/to/install_X.yml
如果不想先解密后执行,可以在执行安装命令前,读取密码文件,解密安装文件
# ansible-playbook -vault-password-file /path/to/passwd.txt /path/to/hosts install_X.yml
注意:用一个playbook只能用同一个明文密码加密,安装完成后正确地处理明文密码文件
Ansible Vault
https://docs.ansible.com/ansible/latest/user_guide/vault.html
Ansible-vault doesn't work with --vault-password-file
https://stackoverflow.com/questions/42109626/ansible-vault-doesnt-work-with-vault-password-file
使用ansible-vault加密数据
https://www.colabug.com/5801314.html
ansible-vault加密和解密文件
https://www.cnblogs.com/nb-blog/p/10614946.html
朱双印 ansible-vault
http://www.zsythink.net/archives/3250
ansible基础:加密
https://mp.weixin.qq.com/s?__biz=MzUzMDc0MjgwNg%3D%3D&idx=1&mid=2247483753&sn=720a3aa215e6335657f7ff01c8f00b00
https://www.cnblogs.com/mauricewei/p/10056476.html
Docs » User Guide » Working With Playbooks » Best Practices
https://docs.ansible.com/ansible/latest/user_guide/playbooks_best_practices.html
Ansible: How to encrypt some variables in an inventory file in a separate vault file?
https://stackoverflow.com/questions/30209062/ansible-how-to-encrypt-some-variables-in-an-inventory-file-in-a-separate-vault
How do I generate encrypted passwords for the user module?
https://docs.ansible.com/ansible/latest/reference_appendices/faq.html#how-do-i-generate-crypted-passwords-for-the-user-module
Ansible添加用户,密码加密
https://www.zhukun.net/archives/8108
passlib.hash.sha512_crypt - SHA-512 Crypt
https://passlib.readthedocs.io/en/stable/lib/passlib.hash.sha512_crypt.html
Creating a new user and password with Ansible
https://stackoverflow.com/questions/19292899/creating-a-new-user-and-password-with-ansible
ansible-playbook设置java环境变量后不生效解决方法
https://blog.csdn.net/yushi6310/article/details/78683123
关于ansible远程执行的环境变量问题(login shell & nonlogin shelll)
https://blog.csdn.net/u010871982/article/details/78525367