Skip to content

Commit

Permalink
Update include_vars function
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysmeister committed Jul 25, 2024
1 parent 8c83071 commit 454da7d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
23 changes: 21 additions & 2 deletions roles/mongodb_auth/molecule/default/tests/test_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,29 @@


def include_vars(host):
ansible = host.ansible("include_vars",
'file="../../defaults/main.yml"',
current_dir = os.path.dirname(os.path.abspath(__file__))
path_components = current_dir.split(os.sep)
trim_count = 0
# Weird bug where the path of this file is incorrect
# It seems the ansible module, at least when used here
# Used to run in a different directory, meaning the
# relative path was not correct. This method should mean it's
# always correct whatever the context.
for component in path_components:
if component.startswith("mongodb_"):
break
else:
trim_count += 1
trim_count = (len(path_components) - 1) - trim_count
# Trim off the dirs after the role dir
trimmed_components = path_components[:-trim_count]
trimmed_path = os.sep.join(trimmed_components)
vars_file_path = os.path.join(trimmed_path, 'defaults', 'main.yml')
ansible = host.ansible('include_vars',
f'file="{vars_file_path}"',
False,
False)
# print(str(ansible))
return ansible


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def include_vars(host):
f'file="{vars_file_path}"',
False,
False)
print(str(ansible))
# print(str(ansible))
return ansible


Expand Down

0 comments on commit 454da7d

Please sign in to comment.