-
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
[WIP]Suppress error when hosts key not found in playbook #178
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -205,10 +205,18 @@ def build(self, db_path): | |
tmp_pb_path = os.path.join(tmp, "p.yaml") | ||
with open(self.pb, "r") as fd_r: | ||
pb_dict = yaml.safe_load(fd_r) | ||
host_present = False | ||
for idx, doc in enumerate(pb_dict): | ||
host = doc["hosts"] | ||
logger.debug("play[%s], host = %s", idx, host) | ||
doc["hosts"] = self.builder.ansible_host | ||
try: | ||
host = doc["hosts"] | ||
host_present = True | ||
except: | ||
continue | ||
finally: | ||
if host_present: | ||
logger.debug("play[%s], host = %s", idx, host) | ||
doc["hosts"] = self.builder.ansible_host | ||
break | ||
Comment on lines
+210
to
+219
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @TomasTomecek These changes would suppress the error in #109. Another part of this issue to be solved is regarding the import playbook. Usually, one case to consider would be a single playbook imported which I guess I would repeat the process as done on the original playbook to modify the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the playbooks are being imported from within a playbook: it means that users can import from 0 to infinity playbooks and bender needs to be able to cope with that; I'd say that extra-args don't play a role here I'm personally completely unsure why the error happened in the first place - I'd suggest creating a test case using the playbook specified in the issue and check closely what exactly is going wrong There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @TomasTomecek As I went through the issue's playbooks, I understood that ab is trying to extract the host key from the primary playbook (which is not present) so throws a keyError, Perhaps as we have the options of defining host in the imported playbooks, now ansible has to go step deeper to dig the host key from the imported playbooks, Am I on the right track? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I'm not sure if that's really happening or I may not understand what you're trying to say. I still suggest to write a test case for the issue and diagnose the problem like that. I used |
||
with open(tmp_pb_path, "w") as fd: | ||
yaml.safe_dump(pb_dict, fd) | ||
playbook_base = os.path.basename(self.pb).split(".", 1)[0] | ||
|
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.
looking at my code, I can see that the host is retrieved only for logging purposes, so I'd instead do something like:
and continue with the former flow