Skip to content

Commit

Permalink
Make vault_password available to BangsibleInventory.
Browse files Browse the repository at this point in the history
Both the PlayBook and the Inventory require access to the vault_password
because the Inventory needs it when reading group_vars files
independently of the PlayBook run.
  • Loading branch information
fr33jc committed Sep 11, 2015
1 parent 90a3763 commit d4ab3c5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 5 additions & 2 deletions bang/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ def get_ansible_groups(group_map):


class BangsibleInventory(ansible.inventory.Inventory):
def __init__(self, groups, hostvars):
super(BangsibleInventory, self).__init__(None)
def __init__(self, groups, hostvars, vault_password=None):
super(BangsibleInventory, self).__init__(
host_list=None,
vault_password=vault_password
)
self.groups = get_ansible_groups(groups)

# Prepopulate the cache. The base Inventory only gathers host vars as
Expand Down
4 changes: 3 additions & 1 deletion bang/stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ def configure(self):
verbose=ansible_verbosity
)

vault_password = ansible_cfg.get(A.ansible.VAULT_PASS)
extra_kwargs = {
'playbook': playbook_path,

Expand All @@ -300,13 +301,14 @@ def configure(self):
# ``host_list`` is used to generate the inventory, but
# don't worry, we override the inventory later
'host_list': [],
'vault_password': ansible_cfg.get(A.ansible.VAULT_PASS),
'vault_password': vault_password,
}
pb_kwargs.update(extra_kwargs)
pb = PlayBook(**pb_kwargs)
inventory = BangsibleInventory(
copy.deepcopy(self.groups_and_vars.lists),
copy.deepcopy(self.groups_and_vars.dicts),
vault_password=vault_password
)
inventory.set_playbook_basedir(playbook_dir)
pb.inventory = inventory
Expand Down

0 comments on commit d4ab3c5

Please sign in to comment.