ansible/ansible — pull request #8110 by bcoca (2014-07-13 00:35:07+00:00)
Title: Lookup vault file

now the file lookup plugin will automatically decrypt vault files, it should also be easy to add vault support to other lookups using this.

example:

```
- hosts: localhost
connection: local
tasks:
- name: "Show secret stuff"
debug: msg="{{ lookup('file', 'files/secret_stuff') }}"

- name: "non secret stuff"
debug: msg="{{ lookup('file', 'files/not_secret') }}"
```

output of : ansible-playbook -i 'localhost,' test.yml

```
PLAY [localhost] **************************************************************

GATHERING FACTS ***************************************************************
ok: [localhost]

TASK: [Show secret stuff] *****************************************************
ok: [localhost] => {
"msg": "$ANSIBLE_VAULT;1.1;AES256\n39623566663433343066313837336334663830616434343631383366353461353666303336316165\n3563656235663731363464643137316662376631373430380a623736323765663637363734306133\n62313933636265643263333564653533626135653162613235623232623334663638373238626462\n3933366466336162610a363934316333373034326665656663306333373736333163373763316666\n65666432663037663432663031356636343063356339343232623435386632636430"
}

TASK: [non secret stuff] ******************************************************
ok: [localhost] => {
"msg": "notsecret1\nnotsecret\n"
PLAY RECAP ********************************************************************
localhost : ok=3 changed=0 unreachable=0 failed=0
}
```

output of : ansible-playbook -i 'localhost,' test.yml --ask-vault-pass

```
PLAY [localhost] **************************************************************

GATHERING FACTS ***************************************************************
ok: [localhost]

TASK: [Show secret stuff] *****************************************************
ok: [localhost] => {
"msg": "secret1\nsecret2\n"
}

TASK: [non secret stuff] ******************************************************
ok: [localhost] => {
"msg": "notsecret1\notsecret2\n"
}
PLAY RECAP ********************************************************************
localhost : ok=3 changed=0 unreachable=0 failed=0
```