【ansible】使用ansible-vault加密數(shù)/解密數(shù)據(jù)文件

一 、實(shí)驗(yàn)背景


眾所周知,ansible是很火的一個(gè)自動(dòng)化部署工具,在ansible控制節(jié)點(diǎn)內(nèi),存放著當(dāng)前環(huán)境服務(wù)的所有服務(wù)的配置信息,其中自然也包括一些敏感的信息,例如明文密碼、IP地址等等。

從安全角度來(lái)講,這些敏感數(shù)據(jù)的文件不應(yīng)該以明文的形式存在。此時(shí)就用到了ansible加密的特性。

ansible通過(guò)命令行「ansible-vault」給你目標(biāo)文件/字符串進(jìn)行加密。在執(zhí)行playbook時(shí),通過(guò)指定相應(yīng)參數(shù)來(lái)給目標(biāo)文件解密,從而實(shí)現(xiàn)ansible vault的功能。

ansible可以加密任何部署相關(guān)的文件數(shù)據(jù),例如:

主機(jī)/組變量等所有的變量文件

tasks、hanlders等所有的playbook文件

命令行導(dǎo)入的文件(eg : -e @file.yaml? ,-e @file.json)

copy,template的模塊里src參數(shù)所使用的文件,甚至是二進(jìn)制文件。

playbook里用到的某個(gè)字符串參數(shù)也可以加密(Ansible>=2.3)


二、查看命令幫助和man手冊(cè)


# yum? -y install? epel-release

# yum -y install ansbile?


# ansible-vault --help

# man ansible-vault > ansible-vault.md



三、一般使用


準(zhǔn)備一個(gè)寫(xiě)有明文的文件

# 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


如果不想先解密后執(zhí)行,可以在執(zhí)行安裝命令前,讀取密碼文件,解密安裝文件

# ansible-playbook -vault-password-file /path/to/passwd.txt /path/to/hosts install_X.yml


注意:用一個(gè)playbook只能用同一個(gè)明文密碼加密,安裝完成后正確地處理明文密碼文件


四、參考

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加密數(shù)據(jù)

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基礎(chǔ):加密

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添加用戶(hù),密碼加密

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設(shè)置java環(huán)境變量后不生效解決方法

https://blog.csdn.net/yushi6310/article/details/78683123


關(guān)于ansible遠(yuǎn)程執(zhí)行的環(huán)境變量問(wèn)題(login shell & nonlogin shelll)

https://blog.csdn.net/u010871982/article/details/78525367

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容