Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for ansible-vault #1

Open
wants to merge 2 commits into
base: ansible-api
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ansible-cmdb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dbg () {

# Find suitable python binary
find_py_bin () {
which -a python | while read -r TRY_PY_BIN
which -a python python3 | while read -r TRY_PY_BIN
do
dbg "Trying python bin: $TRY_PY_BIN"

Expand Down
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