Closed rwhagw closed 5 months ago
Looks like this might need to be addressed in the ansible core repo:
https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/inventory/__init__.py#L351
@rwhagw Thank you for raising this. The values in compose are Jinja expressions and the double quotes that you included are YAML syntax will go away when the file is parsed. Including quotes in the dict values, so that they are valid Jinja expressions, should solve your issue.
If I use location: "'east_coast'"
, I can see it in the result.
{
"_meta": {
"hostvars": {
"instance-01": {
...
"location": "east_coast",
"location_vars": {
"location": "east_coast"
},
"maintenance_options": {
"auto_recovery": "default"
},
...
Hello,
I can confirm the trick of "'whatever'"
works perfectly with strings.
By other hand, in my case, I have a more difficult string to append that it has quotes. For example to assign value to ansible_ssh_common_args
variable.
I have a command that seems like -o StrictHostKeyChecking=no -o ProxyCommand="sh -c \"custom command\""
I tried several ways, even with {%raw%} custom command {% endraw %}
with zero result.
Could you give me a clue about that?
Thanks 😄
I missed the notification for this; thank you @alinabuzachis, that works!
@adrian-arapiles maybe like this:
"'-o StrictHostKeyChecking=no -o ProxyCommand=\"sh -c \"custom command\"\"'"
It appears that this issue has been resolved in the latest release. If you believe otherwise, please feel free to reopen the issue.
Summary
When adding variables under compose in an inventory file, any dictionaries, lists, and tuples are applied to the hosts, but string variables are ignored.
Issue Type
Bug Report
Component Name
amazon.aws.aws_ec2 - EC2 inventory source
Ansible Version
Collection Versions
AWS SDK versions
Configuration
OS / Environment
Host OS: Arch Linux Target OS: CentOS 7.6
Steps to Reproduce
After running
ansible-inventory --host HOSTNAME
with the above inventory file, "location_vars.location" is set but "location" is not.Expected Results
I expected "location" to be set as the string value defined in the inventory file.
Actual Results
location is not in the dictionary of variables.
Code of Conduct