Base64 encoding

When reading content from remote hosts, such as with the slurp module (used to read file content from remote hosts into a variable), the content will be Base64 encoded. To decode such content, Ansible provides a b64decode filter. Similarly, if running a task that requires Base64 encoded input, regular strings can be encoded with the b64encode filter.

Let's read content from the derp file, as shown in the following code:

--- 
- name: demo the filters 
  hosts: localhost 
  gather_facts: false  
  tasks: 
    - name: read file 
      slurp: 
        src: derp 
      register: derp  
    - name: display file content (undecoded) 
      debug: 
        var: derp.content  
    - name: display file content (decoded) 
      debug: 
        var: derp.content | b64decode

The output is shown in the following screenshot:

Here, we can see that we successfully read the small file we created into a variable's, and that we can see the variable contents in the Base64 encoded form (remember that this encoding was performed by the slurp module). We can then decode it using a filter to see the original file contents.

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

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