-
Notifications
You must be signed in to change notification settings - Fork 23.7k
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
variables in hostvars are not templated #7844
Comments
Inventory variables are for simple variables, if you want to do more complex things like this you should put the variables in host_vars/group_vars, where this will work as expected. If you have any further questions regarding this, please let us know. |
This issue is not about inventory variables. My point is that the magic variable named "hostvars" should act like any other dictionary - it should run the values through jinja2 templating. At the moment it doesn't. |
Would love to see this addressed, as I ran into the same problem (where I populated host_vars/group_vars files with complex yaml). Again, variables are interpolated with templates but not via the hostvars[] call. |
I have also come across this problem, simple example here: https://gist.github.com/hughsaunders/517b7a1867cb5e87e7ad I think it would be great if accessing a variable directly always gave the same result as accessing it via hostvars. Would you mind having another look @jimi-c ? |
We'll take another look at this. |
@hughsaunders / @ktosiek I've just pushed the above commit to my personal repo, if either of you'd like to give it a try. My approach was to template the variables directly in the HostVars class when fetching the item (where it is cached too) so hopefully that will reduce the impact of templating. This also includes some refactoring of the runner code where we build the injectable variables for the task. |
@jimi-c Thanks so much for working on this, sadly your patch didn't work for me, see inline comment jimi-c@128cb3b#commitcomment-7766169 |
@hughsaunders I've updated the commit per your note and re-pushed, if you'd like to retest it now. Beyond that typo, was everything else working for you? |
Closing This TicketHi! We believe the above commit should resolve this problem for you. This will also be included in the next major release. If you continue seeing any problems related to this issue, or if you have any further questions, please let us know by stopping by one of the two mailing lists, as appropriate:
Because this project is very active, we're unlikely to see comments made on closed tickets, but the mailing list is a great way to ask questions, or post if you don't think this particular issue is resolved. Thank you! |
There was a regression shortly after the fix for this issue was landed. Hostvars are expanded correctly in 4a9cf3f, but expansion is broken from e9229cf. @jimi-c any chance we can get this issue reopened? Example:In the examples, note the abbreviated SHAs in []. Working, y is defined as {{x}} which is correctly exapanded to value_of_x:
Not working, {{x}} is not expanded:
inventory/group_vars/g1.yml:
playbook:
|
@hughsaunders if you're still seeing this, could you please open a new issue (if you have not done so already)? Thanks! |
continuing this discussion in #8213 |
Cinder requires temporary working space to convert images. This patch exposes cinder_volume_lv_size_gb to the user config file, so the user can decide how large the cinder volumes container should be based on available space and the size of images that will need to be converted. cinder_volume_lv_size_gb is used to override container_lvm_fssize in group_vars/cinder_volume. Simple enough but doesn't work because templated variables (or indirect variables) are not expanded when accessed via hostvars[] see: ansible/ansible#7844. In order to work around that, I have eliminated hostvars[] usage from the container creation mechanism. This may have positive speed implications as the limit of container creation parallelism is now forks rather than number of hosts. However it does make this change larger than a small bug fix. Also note that this patch makes use of delegate_to, so specific ansible versions must be used to avoid ansible/ansible#8705. Our requirements file currently specifies a version before this bug was introduced. There are two commits in this PR as one is the actual bugfix, the other is infrastructure changes required for that bugfix to work. Also only the bugfix may be needed if the upstream bugs are fixed. Closes-Bug: #1399427 Change-Id: I2b5c5e692d3d72b603fdd6298475cb76c52c66df
Closing This TicketHi! We believe the above commit should resolve this problem for you. This will also be included in the next major release. If you continue seeing any problems related to this issue, or if you have any further questions, please let us know by stopping by one of the two mailing lists, as appropriate:
Because this project is very active, we're unlikely to see comments made on closed tickets, but the mailing list is a great way to ask questions, or post if you don't think this particular issue is resolved. Thank you! |
still seeing the same behavior: hostvars are not template expanded:
|
@michaelw this fix was included in 2.1.1. |
Issue Type: Bug Report
Ansible Version: ansible 1.7 (devel d0dd4ac)
Environment: N/A
Summary:
Values comming from hostvars should go through similar variable expansion process as all the others.
Steps To Reproduce:
$ ansible-playbook -i vars_inv hostvars_example.yml
vars_inv:
hostvars_example.yml:
Expected Results:
Actual Results:
Other notes:
The expected result above was created with help of the patch below.
I'm afraid it's not usable as is, that's why I'm submitting this as an issue and not a PR - if you think otherwise I'll happily resubmit it as one
The text was updated successfully, but these errors were encountered: