# Is there a module that can encrypt a file with vault in tasks?

**URL:** <https://forum.ansible.com/t/is-there-a-module-that-can-encrypt-a-file-with-vault-in-tasks/37237>\
**Category:** Ansible Project\
**Created:** [October 17, 2022, 3:18am UTC](https://forum.ansible.com/t/is-there-a-module-that-can-encrypt-a-file-with-vault-in-tasks/37237 "2022-10-17T03:18:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Glen\_Huang](https://avatars.discourse-cdn.com/v4/letter/g/edb3f5/32.png) [@Glen\_Huang](https://forum.ansible.com/u/Glen_Huang)\
**Post date:** [October 17, 2022, 3:18am UTC](https://forum.ansible.com/t/is-there-a-module-that-can-encrypt-a-file-with-vault-in-tasks/37237/1 "2022-10-17T03:18:45Z")

</div>

I use playbook to locally generate a private key, and after that I’d like to encrypt it with vault so another playbook can use it to copy to a remote hosts.

Is there a module that can encrypt a file with vault? Or should I simply use the command module to run “ansible-vault encrypt”?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [October 17, 2022, 5:40pm UTC](https://forum.ansible.com/t/is-there-a-module-that-can-encrypt-a-file-with-vault-in-tasks/37237/2 "2022-10-17T17:40:54Z")

</div>

no, but there is a filter  
[https://docs.ansible.com/ansible/devel/collections/ansible/builtin/vault\_filter.html](https://docs.ansible.com/ansible/devel/collections/ansible/builtin/vault_filter.html)

---

<div class="post-metadata">

**Author:** ![Glen\_Huang](https://avatars.discourse-cdn.com/v4/letter/g/edb3f5/32.png) [@Glen\_Huang](https://forum.ansible.com/u/Glen_Huang)\
**Post date:** [October 19, 2022, 2:38am UTC](https://forum.ansible.com/t/is-there-a-module-that-can-encrypt-a-file-with-vault-in-tasks/37237/3 "2022-10-19T02:38:55Z")

</div>

That works for me. Thanks a lot.
