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
openssh_keypair: prevent error when path includes no path #50106
openssh_keypair: prevent error when path includes no path #50106
Conversation
Should this stuff really work with relative paths? |
Yes, why should it not? |
(Main use case is |
Well, the module would write private keys somewhere and while I would usually expect to have ansible modules execute in $HOME on a remote machine I'm not sure if the path where it will run is actually specified...? |
With |
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.
Wonder if it would be worth updating the docs for path
to make this clearer.
@@ -272,7 +272,7 @@ def main(): | |||
) | |||
|
|||
# Check if Path exists | |||
base_dir = os.path.dirname(module.params['path']) | |||
base_dir = os.path.dirname(module.params['path']) or '.' | |||
if not os.path.isdir(base_dir): | |||
module.fail_json( | |||
name=base_dir, |
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.
Add a note here stating that - where we failed to find the file.
The local/remote directory '%s' ...
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.
That's already there in line 279. Currently, when base_dir
is the empty string, it doesn't read very nice, though (The directory does not exist or the file is not a directory
-- watch the double space).
Updating the docs for Also, since the module is only added in the next version, I'm not sure if a changelog entry is needed, but it won't hurt for sure. For the record, I don't feel very strongly either way on the relative path issue, but I would consider it bad style if I saw it in a playbook that I would expect to be idempotent (unless I've missed something in the docs, as I said I think the working directory of Ansible is not strongly defined and could change). |
I wouldn't do that.
Well, all the ones I used / worked on so far don't do such checks on paths, so they do work fine.
Ah, good point. I completely forgot about that. I'll remove the changelog fragment!
I don't think it is documented or advertised anywhere. It's still very useful in some edge cases, like testing or using Ansible instead of a complicated shell script. (In fact, I just tested that, you can put I wouldn't really advertise this, but I also don't want that this is made not possible (without jumping through additional hoops by prefixing filenames with |
4e00e6f
to
b1e571a
Compare
An integration test would also be nice to have for this one, sounds like something that might/should be eventually refactored (if someone goes through the hassle of writing a python library that does the stuff |
I don't think this part will be affected by a refactoring away from calling |
shipit |
@MarkusTeufelberger @gundalow @Akasurde thanks for your reviews! |
SUMMARY
Prevents error when
path
includes no path, only a filename (i.e. references to a file in cwd).ISSUE TYPE
COMPONENT NAME
openssh_keypair