IT automation and orchestratio...
Ansible
Configure Ansible
5min
this section shows how to configure the ansible instance to integrate with the {{futurex}} pkcs #11 library create a key pair perform the tasks in the following sections to create a key pair on the {{k3}} set {{futurex}} pkcs #11 environment variables perform the following steps to set {{futurex}} pkcs #11 environment variables in a terminal, run the following commands to set the required fxpkcs11 environment variables export fxpkcs11 module=/path/to/libfxpkcs11 so; export fxpkcs11 cfg=/path/to/fxpkcs11 cfg; be sure to modify the file path to match the location of libfxpkcs11 so and fxpkcs11 cfg on your system create a key pair on the kmes series 3 by using pkcs11 tool perform the following steps to create a key pair on the {{k3}} by using pkcs11 tool in a terminal, run the following command to create a new rsa key pair on the {{k}} sudo pkcs11 tool module $fxpkcs11 module login keypairgen key type rsa 2048 label "ansible rsa privatekey" id "123456" 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 {{k}} ansible playbooks in ansible, playbooks perform automated tasks you can reference the {{futurex}} pkcs #11 library when performing these tasks inside the playbook file to perform various functions, such as ssh and signing data for more information on ansible playbooks, see the ansible documentation ssh example the following example uses {{futurex}} pkcs #11 with ansible create an ansible project working directory and switch to it sudo mkdir /ansible project cd /ansible project create an inventory file sudo nano inventory the following code shows an example inventory file using localhost \[local] localhost ansible connection=local create a playbook yml file sudo nano playbook yml the following code shows an example ansible playbook file for testing ssh referencing the private key created in the previous section ( ansible rsa privatekey ) \ hosts local vars pkcs11 module "/usr/local/bin/fxpkcs11/libfxpkcs11 so" pkcs11 pin "safest" pkcs11 key id "ansible rsa privatekey" tasks \ name test connectivity command echo "hello, pkcs#11" \ name ssh to localhost using pkcs#11 command ssh i {{ pkcs11 module }} jtitus\@localhost echo "ssh with pkcs#11" register ssh result \ name show ssh result debug var ssh result stdout replace pkcs11 module with the location of the {{futurex}} pkcs #11 library on your system replace pkcs11 pin with the password you configured for the identity created for this integration replace pkcs11 key id with the label of the key you set when creating the key pair through pkcs11 tool to execute the playbook and reference the private key stored on the hsm during ssh connection, run the following command, setting the username, inventory, and playbook file information according to your setup sudo ansible playbook u \<your username> i inventory playbook yml k when prompted, enter the become password in ansible the become directive escalates privileges when running tasks, similar to using sudo in the command line the become password is the password for the user specified in become user (which defaults to root if not specified) when prompted for the password of the user you are connecting to the machine with through ssh, enter it to complete the process if successful, you should see a response similar to the following play \[local] task \[gathering facts] ok \[localhost] task \[test connectivity] changed \[localhost] task \[ssh to localhost using pkcs#11] user\@localhost's password changed \[localhost] task \[show ssh result] ok \[localhost] => { "ssh result stdout" "\<fxpkcs11 log output>" } play recap you can verify the successful pull of the private key within the fxpkcs11 log file or the log output shown in the command response signing data example the following example uses pkcs #11 with ansible create an ansible project working directory and switch to it sudo mkdir /ansible project cd /ansible project create an inventory file sudo nano inventory the following code shows an example inventory file using localhost \[local] localhost ansible connection=local create a playbook yml file sudo nano playbook yml the following code shows an example ansible playbook file for signing data referencing the private key created in the previous section ( ansible rsa privatekey ) \ hosts local vars pkcs11 module "/usr/local/bin/fxpkcs11/libfxpkcs11 so" pkcs11 pin "safest" pkcs11 key id "ansible rsa privatekey" data to sign "sign this data" tasks \ name sign data using pkcs#11 shell | echo n "{{ data to sign }}" | openssl dgst engine pkcs11 keyform engine sign "pkcs11\ object={{ pkcs11 key id }}" out signed data bin register sign result environment pkcs11 module "{{ pkcs11 module }}" pkcs11 pin "{{ pkcs11 pin }}" \ name show signing result debug msg "data signed successfully" replace pkcs11 module with the location of the {{futurex}} pkcs #11 library on your system replace pkcs11 pin with the password you configured for the identity created for this integration replace pkcs11 key id with the label of the key you set when creating the key pair through pkcs11 tool to execute the playbook and reference the private key stored on the hsm during ssh connection, run the following command, setting the username, inventory, and playbook file information according to your setup sudo ansible playbook u \<your username> i inventory playbook yml k when prompted, enter the become password in ansible the become directive escalates privileges when running tasks, similar to using sudo in the command line the become password is the password for the user specified in become user (which defaults to root if not specified) when prompted for the password of the user you are connecting to the machine with through ssh, enter it to complete the process if successful, you should see a response similar to the following play \[local] task \[gathering facts] ok \[localhost] task \[sign data using pkcs#11] changed \[localhost] task \[show signing result] ok \[localhost] => { "msg" "data signed successfully" } play recap localhost ok=3 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 you can verify the signing operations within the fxpkcs11 log file or by checking the output file contents