-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Integer key inside dictionary imported as string when inventory is sourced from a project #991
Comments
For any questions like these, we have to be extremely careful that the behavior of AWX is congruent with Ansible core, itself. If Ansible core does something wrong, we may actually prefer to pass-through that wrong behavior and ask that Ansible core fixes the issue. I believe this is one of those cases. Here is a test set inside of my inventory examples. AlanCoding/Ansible-inventory-file-examples@c2ef46d Inventory content can be tested using the {
"_meta": {
"hostvars": {
"foobar": {
"loader1_var": {
"subvar1": {
"1": [
"foo"
],
"2": [
"bar"
]
}
}
}
}
},
"all": {
"children": [
"ungrouped"
]
},
"ungrouped": {
"hosts": [
"foobar"
]
}
} Feel free to raise an issue inside of https://github.com/ansible/ansible/issues if you want this fixed, and they will triage it (although it may result in it being closed, depending on their expectation). |
If an inventory containing these host/group vars is used directly by ansible, it preserves the type of the dictionary keys:
However, since we use There's always the |
The example that @cchurch somewhat violates the principle of However, I see the problem with compatibility as we cross over multiple formats. The python JSON implementation (and possibly the standard itself) does not support this type structure. The following example really shows the crux of the issue. ansible-inventory -i issues/AWX991/inv --list --yaml
all:
children:
ungrouped:
hosts:
foobar:
loader1_var:
subvar1:
1:
- foo
2:
- bar I have tested this in the sense that I pipe that output to a file, and then use the python yaml library to parse it and obtain... >>> [type(k) for k in adict['all']['children']['ungrouped']['hosts']['foobar']['loader1_var']['subvar1'].keys()]
[<type 'int'>, <type 'int'>] Thus this issue may actually be resolvable by having AWX always use the yaml option for inventory imports. |
No I am not! As mentioned below: https://github.com/ansible/awx/blob/1ccdb305e3497f1958fa0229bf82edc262686836/awx/main/management/commands/inventory_import.py |
No, that's a special script for importing inventory from another server. This would require finding the Not sure if this breaks anything else unexpected, might be good to ping the Ansible core mailing list about that. They are more savvy about JSON vs. YAML than I am. |
@steaksauce- The changes needed to support your use case will need to be made in https://github.com/ansible/awx/blob/devel/awx/main/management/commands/inventory_import.py#L165, like @AlanCoding said. The file you mentioned will need to be modified to support pulling inventory from another AWX/Tower instance while preserving integer dictionary keys, and we'll also need to update the |
D'oh! Thanks for letting me know! |
The use of YAML looks like it may have some overlap with other requests I'm dealing with, so I probably need to carry out some of this basic research myself. |
From what I was finding, there's no way this will work without some other substantial concessions made by Ansible core, and there's nothing on the horizon for this. The YAML inventory format would give the correct types, but the structure would destroy the performance of our imports to make many large inventories unusable, even assuming the importing algorithm is updated correctly. |
ISSUE TYPE
COMPONENT NAME
SUMMARY
When you have a dictionary defined in your project which has keys that are integers, AWX imports them as strings when using a project as the inventory source.
ENVIRONMENT
STEPS TO REPRODUCE
EXPECTED RESULTS
Dictionary is imported as laid out in the source file with the keys as integers:
ACTUAL RESULTS
Dictionary is imported with the keys converted to strings:
The text was updated successfully, but these errors were encountered: