Skip to content

Commit

Permalink
Add support for ansible-vault
Browse files Browse the repository at this point in the history
Signed-off-by: Gaël Goinvic <[email protected]>
  • Loading branch information
gaelgatelement committed Mar 3, 2022
1 parent a69e89d commit 22e969b
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/ansiblecmdb/ansible_via_api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import os
from ansible.parsing.dataloader import DataLoader
from ansible.module_utils._text import to_bytes
from ansible.parsing.vault import VaultSecret
from ansible.inventory.manager import InventoryManager
from ansible.vars.manager import VariableManager

Expand All @@ -18,6 +21,9 @@ class AnsibleViaAPI(Ansible):
def load_inventories(self):
"""Load host inventories using the Ansible Python API."""
loader = DataLoader()
vault_pass = os.environ.get("ANSIBLE_VAULT_PASSWORD", "")
if vault_pass:
loader.set_vault_secrets([('default', VaultSecret(_bytes=to_bytes(vault_pass)))])
inventory = InventoryManager(loader=loader, sources=self.inventory_paths)
variable_manager = VariableManager(loader=loader, inventory=inventory)

Expand Down

0 comments on commit 22e969b

Please sign in to comment.