Executing Ansible-playbook with encrypted files

To make use of our encrypted content, we need to be able to inform ansible-playbook how to access any encrypted data it might encounter. Unlike ansible-vault, which exists solely to deal with file encryption or decryption, ansible-playbook is more general-purpose, and it will not assume it is dealing with encrypted data by default. Luckily, all of our familiar --vault-id parameters from the previous examples work just the same in ansible-playbook as they do in ansible-vault. Ansible will hold the provided passwords and IDs in memory for the duration of the playbook execution. 

Let's now create a simple playbook named show_me.yaml that will print out the value of the variable inside of a_vars_file.yaml, which we encrypted in a previous example, as follows:

--- 
- name: show me an encrypted var 
  hosts: localhost 
  gather_facts: false 
 
  vars_files: 
    - a_vars_file.yaml 
 
  tasks: 
    - name: print the variable 
      debug: 
        var: something 

Now, let's run the playbook and see what happens. Note how we use the --vault-id parameter in exactly the same way as we did with ansible-vault; continuity is maintained between the two binaries, so you are able to apply everything you learned earlier in the chapter about using --vault-id. Take a look at the following screenshot:

As you can see, the playbook runs successfully and prints out the unencrypted value of the variable, even though the source variable file we included was an Ansible Vault. Naturally, you wouldn't print a secret value to the Terminal in a real playbook run, but this demonstrates how easy it is to access data from a Vault.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.213.128