-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial import_playbook support #268
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wow, very nice work!
just a few nits and we're good to merge
ansible_bender/core.py
Outdated
@@ -173,6 +174,29 @@ def _get_path_our_site(self): | |||
# hence, let's add the site ab is installed in to sys.path | |||
return os.path.dirname(os.path.dirname(ansible_bender.__file__)) | |||
|
|||
def _correct_host_entries(self, playbook_path, tmpDir): | |||
""" Correct the host entries in the playbook and all imported playbooks """ | |||
tmp_pb_path = os.path.join(tmpDir, str(uuid.uuid4()) + ".yaml") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
love using the uuid here! could we please prefix the uuid string with e.g. ab_
so that people know the file is coming from ansible-bender?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 2abc606 🙂
ansible_bender/core.py
Outdated
import_base_path = os.path.dirname(playbook_path) | ||
imported_playbook_path = os.path.join(import_base_path, imported_playbook) | ||
doc["import_playbook"] = self._correct_host_entries(imported_playbook_path, tmpDir) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would some logger.debug make sense here as well? especially when it's called recursively
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made a simple one in 2abc606 🙂 Does it look okay?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup, looks fine!
merging, thank you so much for taking time to improve bender! I'll try to fix some of the test runs in a separate PR so we can get green CI |
Basics
Ignores adjusting hosts for import_playbooks statements, as those should not have a host entry. Instead we have to read the imported playbook and correct the possible hosts entries there (this goes on recursively by need, so can support a very big import_playbook-depth). The hosts-corrected imported playbook path/name will need to be used in place of the old one in the playbook that imports it. I decided on a uuid based filename for the temp files, because of the low likelihood of "name-crashes". Currently the temp-file was named p.yaml, and if we have several ones that would off course not work. This PR implements those fixes.
tl;dr: fixes #109
About the testing
I initially planned to do everything in tests_core.py, but after some thinking decided to create e2e'ish test in tests_api.py instead. This is because the tests in core would have needed either a lot of setup (duplication of api.py-code maybe), or mocking (in which I think it wouldn't be as useful). Hopefully this is not an issue, as I think the tests I made still verifies the functionality in an ok way.
The tests tests the example from #109, as well as a recursive one (import_playbook inside an imported playbook). The last one might be overkills. I have also tested manually, and it seems to work as expected in the tests I've done so far 🙂