Ansible - ansible-vault view command

The ansible-vault command can be used to perform a number of tasks.

Additionally, there are a few command line options to be aware of.

 

Let's say you used the ansible-vault create command to create foo.txt, and foo.txt contains "Hello World".

The ansible-vault view command is used to view the content of a file that was encrypted by the ansible-vault createansible-vault edit or ansible-vault encrypt command.

Before viewing the file, you'll want to determine if the file was encrypted using a certain vault id. In this example, the file was encrypted using the "test" id.

~]$ cat foo.txt
$ANSIBLE_VAULT;1.2;AES256;test
38626262613533326438383838363032346366643231633838393661633061633830383832643062
6666663233666435636165323038653462343732343264310a616532376238616537613832363565
63336561303230626332326436303830356335343061386333636131386435316633396464353832
3631303831333164610a393266346630313635313831626639303961663330333736393236373032
3062

 

The following command will view the file.

ansible-vault view foo.txt

 

You will be prompted to for the vault password.

Vault password:

 

After providing the valid vault password, the content of the encrypted file will be displayed.

Hello World

 

Or, to avoid being prompted for the vault password, if the file is not associated with a vault id, the --vault-password-file command line option can be used.

ansible-vault view --vault-password-file /usr/local/vault/.vault_password.txt foo.txt

 

If the file is associated with a vault id, the --vault-id command line option can be used.

ansible-vault view --vault-id test@/usr/local/ansible/vault/.vault_password.txt foo.txt

 

In a playbook, the shell module could be used to invoke the ansible-vault command. In this example, the register parameter is used to store the output in the "out" variable.

- name: "ansible-vault view foo.txt"
  shell: "ansible-vault view --vault-id test@/usr/local/ansible/vault/.vault_password.txt foo.txt"
  register: out

 

The debug module could be used to validate that the "out" variable contains the plain text content of foo.txt.

- name: "output the 'out' variable"
  debug: 
    var: out

 

Which should output something like this.

TASK [output the 'out' variable]
ok: [server1.example.com] => {
    "msg": "Hello World"
}

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.





Please enter 79538 in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |