Pass file paths through python's glob lib#47
Conversation
This reverts commit d293ea9.
|
Test added |
Sispheor
left a comment
There was a problem hiding this comment.
Just a comment on the tmp file approach
| 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) |
There was a problem hiding this comment.
instead of creating a temporary file, could we use glob to detect valid extra_var files and inject paths in the command?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 | |||
There was a problem hiding this comment.
not sure if this is a valid yaml syntax.
There was a problem hiding this comment.
It's an empty yaml object e.g.
import yaml
yaml.dump(dict())| 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) |
There was a problem hiding this comment.
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.
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.