Ansible Vault configuration
This section details the steps to configure the Ansible instance to integrate with the PKCS #11 library.
Perform the following two tasks to create a key pair:
In a terminal, run the following commands to set the required FXPKCS11 environment variables:
Be sure to modify the file path to match the location of libfxpkcs11.so and fxpkcs11.cfg on your system.
In a terminal, run the following command to create a new ECC key pair on the by using pkcs11-tool:
When prompted for the user PIN, enter the password of the identity configured in the fxpkcs11.cfg file.
If successful, the command output lists the keys that pkcs11-tool created on the .
In Ansible, playbooks perform automated tasks. You can reference the PKCS #11 library when performing these tasks inside the playbook file to perform various functions, including encrypting and decrypting files.
You must create a file for the Vault Password (such as vault_password_file.txt) and place it in the appropriate folder. This is the password that Ansible Vault uses to encrypt the HSM key and the file to be encrypted with the HSM key.
You must adjust the security of this file based on your organizations best practices.
For the following examples, this file is placed in the /tmp/ directory on the Linux machine.
You must copy and paste the contents of this example into a file with the .yml extension and modify as needed. (such as, encrypt.yml)
The following example, performs the follwing actions
- Retrieves the key from the HSM.
- Stores the key in a temporary file.
- Encryptes the temporary file with Ansible Vault.
- Uses the encrypted temporary key file to encrypt the target file.
- Cleans the encrypted temporary key file from the system.
After you modify the playbook file according to your own environment, use the following shell command to run the playbook:
You must copy and paste the contents of this example into a file with the .yml extension and modify as needed. (such as, decrypt.yml)
The following example, performs the follwing actions
- Retrieves the key from the HSM.
- Stores the key in a temporary file.
- Encryptes the temporary file with Ansible Vault.
- Uses the encrypted temporary key file to decrypt the target file.
- Cleans the encrypted temporary key file from the system.
After you modify the playbook file according to your own environment, use the following shell command to run the playbook: