- Learning DevOps
- Mikael Krief
- 409字
- 2021-06-24 12:32:13
Protecting sensitive data with Ansible Vault
The configuration of a system often requires sensitive information that should not be in the wrong hands. In the Ansible tool, there is a sub-tool called Ansible Vault that protects the data transmitted to Ansible through playbooks.
We will see in our example how to manipulate Ansible Vault to encrypt and decrypt the information of the MySQL user.
The first step is to encrypt the group_vars/database/main.yml file that contains the values of the variables by executing the following command:
ansible-vault encrypt group_vars/database/main.yml
Ansible Vault requests the inclusion of a password that will be required to decrypt the file and then shows the execution of this command to encrypt the content of a file:

After the execution of this command, the content of the file is encrypted, so the values are no longer clear. The following is a sample from it:

To decrypt the file to modify it, it will be necessary to execute the decrypt command:
ansible-vault decrypt group_vars/database/main.yml
Ansible Vault requests the password that was used to encrypt the file, and the file becomes readable again.
In an Ansible usage automation process, it is preferable to store the password in a file in a protected location, for example, in the ~/.vault_pass.txt file.
Then, to encrypt the variable file with this file, we execute the ansible-vault command and add the --vault-password-file option:
ansible-vault encrypt group_vars/database/main.yml --vault-password-file ~/.vault_pass.txt
Now that the file is encrypted and the data is protected, we will run Ansible with the following commands:
In interactive mode, we will run the following:
ansible-playbook -i inventory playbook.yml --ask-vault-pass
Ansible asks the user to enter the password shown in the following screenshot:

In automatic mode, that is, in a CI/CD pipeline, we can add the --vault-password-file parameter with the path of the file that contains the password to decrypt the data:
ansible-playbook -i inventory playbook.yml --vault-password-file ~/.vault_pass.txt
That's all right. We just executed Ansible with data that is no longer clear in the code and with the use of the ansible-vault command.
In this section, we have seen how to protect sensitive data in your playbooks using the ansible-vault utility. We encrypted and decrypted variable files to protect them, and then re-ran Ansible with these encrypted files.
In the following section, we will see how to use Ansible with a dynamic inventory.
- 同仁眼超聲診斷手冊(cè)
- 腎病綜合征
- 皮膚病中藥內(nèi)用制劑
- 狡猾的細(xì)胞:癌癥的進(jìn)化故事與治愈之道
- 營(yíng)養(yǎng)與疾病預(yù)防:醫(yī)護(hù)人員讀本
- 臨床急癥介入治療學(xué)
- 醫(yī)療損害判例評(píng)析
- 硅橡膠修補(bǔ)關(guān)節(jié)軟骨的實(shí)驗(yàn)研究
- 肝臟外科名家手術(shù)精粹
- PET/CT圖譜
- 深井效應(yīng)
- 臨床兒童耳鼻咽喉頭頸外科學(xué)
- 全國(guó)醫(yī)療衛(wèi)生服務(wù)體系規(guī)劃綱要(2015-2020年)解讀
- 做·看·聽(tīng)·說(shuō):孤獨(dú)癥兒童社會(huì)性和溝通能力干預(yù)指南
- 舞動(dòng):以肢體創(chuàng)意開(kāi)啟心理療愈之旅