src, copy and included playbooks

Sorry if I sound like a broken record. When I ran afoul of this initially, it was with playbook includes, and that's been fixed. My next run-in was with templating, which I understand is slated to be fixed in the templating rewrite. Now I'm hitting it with copy.

In short, if I have one playbook that includes another, and that second playbook wants to copy a file, the file is searched for relative to the first playbook.

I looked at the copy module, and src is just passed through expanduser. It doesn't run through path_dwim.

Is there any way for a playbook to communicate its base directory to a module? I think that copy might work if src is run through path_dwim with a basedir of the most recently-run playbook--IOW, exactly how playbook includes work. I looked at the module tutorial and through a bit of the code, and didn't immediately spot a way to do this.

If this is also related to the template rewrite somehow, then I apologize for raising the same issue again and again. If not though, then I'd be happy to try tweaking copy and other modules to resolve src from the last included playbook if such a thing is possible.

Thanks.

Currently there's only logic for the one basedir path when looking for
template files and so on.

And yes, it does require that template rewrite :slight_smile:

NOTE: I'm NOT working on this presently, and not planning to. I'm
not sure about anyone else attempting this short term.

Right, but my point is that there is a path_dwim function, and then there's this from the copy module:

     src = os.path.expanduser(module.params['src'])

Were that to instead be:

     src = path_dwim(basedir, module.params['src'])

then if the playbook calling a module could somehow communicate its basedir to that module, then this would seem to solve the copy problem. And that would seem to be simpler than a full template rewrite for this specific case. Then, later when the template rewrite lands, this and other bits of code can be refactored to the new lookup mechanism.

Am I right? I'm not trying to be impatient, but rather attempting to understand the code and problem so maybe I can put together a pull request.

Thanks.

Nolan Darilek wrote:

Right, but my point is that there is a path_dwim function, and then
there's this from the copy module:

     src = os.path.expanduser(module.params['src'])

Were that to instead be:

     src = path_dwim(basedir, module.params['src'])

then if the playbook calling a module could somehow communicate its
basedir to that module, then this would seem to solve the copy problem.
And that would seem to be simpler than a full template rewrite for this
specific case. Then, later when the template rewrite lands, this and
other bits of code can be refactored to the new lookup mechanism.

Modules will never know anything about dwimming, it happens before they are
even copied to the target node.

Am I right? I'm not trying to be impatient, but rather attempting to
understand the code and problem so maybe I can put together a pull
request.

No. path_dwim is already called in copy, and with the basedir of the play
it was defined in. (Note, play, meaning not task include.) See
lib/ansible/runner/action_plugins/copy.py.

Daniel

Michael DeHaan wrote:

Currently there's only logic for the one basedir path when looking for
template files and so on.

And yes, it does require that template rewrite :slight_smile:

NOTE: I'm NOT working on this presently, and not planning to. I'm
not sure about anyone else attempting this short term.

I'm planning on doing this in the next week or so.

Daniel

excellent!