Skip to content

Pass file paths through python's glob lib#47

Open
dougle wants to merge 12 commits into
HewlettPackard:masterfrom
dougle:support-file-globbing
Open

Pass file paths through python's glob lib#47
dougle wants to merge 12 commits into
HewlettPackard:masterfrom
dougle:support-file-globbing

Conversation

@dougle

@dougle dougle commented Apr 15, 2026

Copy link
Copy Markdown

My scenarios are getting a little long so i'm separating them into individual files in a scenarios directory.

This PR passes all extra_vars files from the test suite playbook config through python's glob library and adds each one.

@dougle

dougle commented Apr 15, 2026

Copy link
Copy Markdown
Author

Test added

@dougle dougle marked this pull request as draft April 16, 2026 12:02
@dougle dougle marked this pull request as ready for review April 16, 2026 15:51

@Sispheor Sispheor left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a comment on the tmp file approach

Comment on lines +88 to +99
combined_config = {}
for file_pattern in extra_vars:
for file_path in glob.glob(file_pattern):
sub_config = yaml.safe_load(open(file_path))
# empty files can cause problems
if sub_config is not None:
combined_config = mergedeep.merge(combined_config, sub_config)

# write combined config out to temp file
combined_config_path = override_config_path or tempfile.mkstemp(prefix='monkeyble_config_')[1]
with open(combined_config_path, "w") as config_file:
yaml.dump(combined_config, config_file)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of creating a temporary file, could we use glob to detect valid extra_var files and inject paths in the command?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've used a tempfile to combine the configs because ansible-playbook doesn't combine/merge parameters to -e.

If two extra_vars files start with monkeyble_scenarios only the last file will persist.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to loop the detected files and add them to the ansible command with "-e".
And yes I if your have multiple time the same var then the last loaded one will take the lead. Like with Ansible vars.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also prefer to not touch the filesystem, but scenarios can become large and that becomes a problem if you are loading scenarios from separate files.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was also wondering about not calling the ansible command via a subprocess but calling it directly via importing the module and calling whatever the cli calls.

https://github.com/ansible/ansible/blob/devel/lib/ansible/cli/playbook.py#L230

@@ -0,0 +1 @@
{} No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if this is a valid yaml syntax.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an empty yaml object e.g.

import yaml
yaml.dump(dict())

@Sispheor Sispheor left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.

Comment thread monkeyble/cli/monkeyble_cli.py
Comment on lines +88 to +99
combined_config = {}
for file_pattern in extra_vars:
for file_path in glob.glob(file_pattern):
sub_config = yaml.safe_load(open(file_path))
# empty files can cause problems
if sub_config is not None:
combined_config = mergedeep.merge(combined_config, sub_config)

# write combined config out to temp file
combined_config_path = override_config_path or tempfile.mkstemp(prefix='monkeyble_config_')[1]
with open(combined_config_path, "w") as config_file:
yaml.dump(combined_config, config_file)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to loop the detected files and add them to the ansible command with "-e".
And yes I if your have multiple time the same var then the last loaded one will take the lead. Like with Ansible vars.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants