# Custom Ansible collection module - not able to import from Ansible.parsing.vault

**URL:** <https://forum.ansible.com/t/custom-ansible-collection-module-not-able-to-import-from-ansible-parsing-vault/8052>\
**Category:** Collection Development\
**Tags:** collections, ee\
**Created:** [August 22, 2024, 6:27pm UTC](https://forum.ansible.com/t/custom-ansible-collection-module-not-able-to-import-from-ansible-parsing-vault/8052 "2024-08-22T18:27:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aaron\_Hodges](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/aaron_hodges/32/3688_2.png) [@Aaron\_Hodges](https://forum.ansible.com/u/Aaron_Hodges)\
**Post date:** [August 22, 2024, 6:27pm UTC](https://forum.ansible.com/t/custom-ansible-collection-module-not-able-to-import-from-ansible-parsing-vault/8052/1 "2024-08-22T18:27:06Z")

</div>

Hello!

Issue: I am creating a custom collection and inside my Python script, I want to import VaultLib and VaultSecret from ansible.parsing.vault. I am installing the collection in a private automation hub, as well as inside of an execution environment.

When running a playbook using the collection, I receive an error stating that VaultLib and VaultSecret are not defined. Basically, the library is not being imported. In the docs, I’ve seen where it’s mentioned that you can only import from ansible.module\_utils from inside a module. Is this a true statement? Is there some other way to import this library inside of the custom module? Thank you for your help!

---

<div class="post-metadata">

**Author:** ![felixfontein](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixfontein/32/7530_2.png) [@felixfontein](https://forum.ansible.com/u/felixfontein)\
**Post date:** [August 22, 2024, 6:56pm UTC](https://forum.ansible.com/t/custom-ansible-collection-module-not-able-to-import-from-ansible-parsing-vault/8052/2 "2024-08-22T18:56:04Z")

</div>

> [@Aaron\_Hodges](#):
>
> In the docs, I’ve seen where it’s mentioned that you can only import from ansible.module\_utils from inside a module. Is this a true statement?

Yes, that’s true.

> [@Aaron\_Hodges](#):
>
> Is there some other way to import this library inside of the custom module?

Vault is something you can only use on the controller / in the controller environment itself. Modules generally don’t run in the controller environment (even with `connection: local`, they might use another Python).

But you could create an action plugin instead. That is executed on the controller in the controller’s context, and can import and use everything from ansible-core. It can also execute a module (or multiple modules).

The most famous action plugin is probably the ansible.builtin.template “module”, which is in fact an action plguin: the templating happens on the controller (since only there you have access to all variables and even to vault), and then template action uses the ansible.builtin.copy module to copy the result (put into a temporary file) to the target.

---

<div class="post-metadata">

**Author:** ![felixfontein](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixfontein/32/7530_2.png) [@felixfontein](https://forum.ansible.com/u/felixfontein)\
**Post date:** [August 22, 2024, 6:56pm UTC](https://forum.ansible.com/t/custom-ansible-collection-module-not-able-to-import-from-ansible-parsing-vault/8052/3 "2024-08-22T18:56:51Z")

</div>

(I’ve moved this discussion to the Collection Development category. Development questions are better suited there.)

---

<div class="post-metadata">

**Author:** ![flowerysong](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/flowerysong/32/2305_2.png) [@flowerysong](https://forum.ansible.com/u/flowerysong)\
**Post date:** [August 23, 2024, 3:22am UTC](https://forum.ansible.com/t/custom-ansible-collection-module-not-able-to-import-from-ansible-parsing-vault/8052/4 "2024-08-23T03:22:03Z")

</div>

> [@felixfontein](#):
>
> template action uses the ansible.builtin.copy module to copy the result (put into a temporary file) to the target.

This isn’t strictly accurate; it actually uses the `ansible.legacy.copy` _action_ to copy the resulting file, which can then call either the `ansible.legacy.copy` module or the `ansible.legacy.file` module (if the file contents are already correct.)
