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
Add rel_file to ansible_managed template variable #69340
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.
a couple of things
a) inventory_dir
might not be present (see implicit localhost)
b) inventory is not the source for relative file paths, the 'play' is, if they happen to be the same in your setup that is coincidental, but inventory is not part of template/vars/files search path (it is for host_vars/group_vars, but that is diff system)
You might want to look at the dwim functions and how they use a search path, it is not as simple as you might think, specially when templates/
is optionally added and when roles appear in the mix, all create special cases.
I was not aware of this. However, if
Indeed, I have
Hm, grep'ing for Alternatively, might a simple |
yes, dataloader has several dwim (do what i mean) functions for resolving relative paths, depending on context, you end up using one of those cwd is not correct, you need basedir, since you can |
Okay, thanks for the info. Can you recommend a debugger (or anything more sophisticated than |
epdb is THE debugger, others exist (i do abuse In any case I would use the original argument, which might already be a relative path, if not, compare to the task's base dir and remove the common sides from the left. |
Closing this as other modifications introduced |
SUMMARY
This add a
rel_file
format string to theansible_managed
template variable.Fixes #45654
ISSUE TYPE
COMPONENT NAME
template
?ADDITIONAL INFORMATION
The relative path resolution is very simplistic: it just strips the
inventory_dir
from thetemplate_path
, which may or may not be enough for this feature.Here's a sample output of this patch applied to
stable-2.9
:TODOs
rel_file
might not be descriptive enough.inventory_dir
the wrong approach?I'm not a Python developer by trade, so this small patch might contain non-idiomatic code. I'm open for suggestions.