From 98fe69f5cff7950a8660819ef24f242d99364ada Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Goinvic?= Date: Wed, 2 Mar 2022 14:56:31 +0100 Subject: [PATCH 1/2] Add support for ansible-vault MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gaƫl Goinvic --- src/ansiblecmdb/ansible_via_api.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/ansiblecmdb/ansible_via_api.py b/src/ansiblecmdb/ansible_via_api.py index cab3d2e..a6fe566 100644 --- a/src/ansiblecmdb/ansible_via_api.py +++ b/src/ansiblecmdb/ansible_via_api.py @@ -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 @@ -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) From c9fa345e7dedd95ded4e732153e538ec744d65e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Goinvic?= Date: Tue, 8 Mar 2022 11:41:22 +0100 Subject: [PATCH 2/2] Fix python3 --- src/ansible-cmdb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ansible-cmdb b/src/ansible-cmdb index 282ab16..cb8e1fc 100755 --- a/src/ansible-cmdb +++ b/src/ansible-cmdb @@ -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"