As mentioned in the comments, you can set your secrets in variables and display them in templates at the time of submission, but if for some reason you want to keep your entire template a secret, there are workarounds.
Processing Encrypted Templates
As a workaround, you can temporarily decrypt the template locally, and after deployment, delete the decrypted file using the module local_action. Suppose your encrypted template is in the template.encroles directory templates.
---
- name: Decrypt template
local_action: "shell {{ view_encrypted_file_cmd }} {{ role_path }}/templates/template.enc > {{ role_path }}/templates/template"
changed_when: False
- name: Deploy template
template:
src=templates/template
dest=/home/user/file
- name: Remove decrypted template
local_action: "file path={{ role_path }}/templates/template state=absent"
changed_when: False
changed_when: False. idempotence - , playbook, .
group_vars/all.yml , , view_encrypted_file_cmd.
group_vars/all.yml
view_encrypted_file_cmd: "ansible-vault
:
(, ) .
var.yml
---
my_private_key: |
YOUR KEY
asfdlsafkj
asdlkfjasf
/private_key.j2
{{ private_key }}
/main.yml
---
template:
src=templates/private_key.j2
dest=/home/user/.ssh/id_rsa
vars:
private_key: "{{ my_private_key }}"
:
lookup pipe, content copy - .
---
- copy:
dest=/your/dest
content=lookup('pipe', 'VAULT_PASSWORD_FILE=path/to/pass_file ansible-vault view path/to/file.enc')