Hi all,

I am working on an idea for an Ansible role that installs CUDA, where I 
want to have a var consisting of a list of items with multiple key/value 
pairs (some values being lists of items.) So I came up with this YAML data 
structure, in a file I named cuda_versions.yml:
---
cuda_versions:
- cuda_8_0:
    cuda_ver: 8.0.61
    min_driver_ver: 375.26
    installer_url: 
https://developer.nvidia.com/compute/cuda/8.0/Prod2/local_installers/cuda_8.0.61_375.26_linux-run
    patchset_url_list:
      - 
https://developer.nvidia.com/compute/cuda/8.0/Prod2/patches/2/cuda_8.0.61.2_linux-run

- cuda_9_0:
    cuda_ver: 9.0.176
    min_driver_ver: 384.81
    installer_url: 
https://developer.nvidia.com/compute/cuda/9.0/Prod/local_installers/cuda_9.0.176_384.81_linux-run
    patchset_url_list:
      - 
https://developer.nvidia.com/compute/cuda/9.0/Prod/patches/1/cuda_9.0.176.1_linux-run
      - 
https://developer.nvidia.com/compute/cuda/9.0/Prod/patches/2/cuda_9.0.176.2_linux-run
      - 
https://developer.nvidia.com/compute/cuda/9.0/Prod/patches/3/cuda_9.0.176.3_linux-run
      - 
https://developer.nvidia.com/compute/cuda/9.0/Prod/patches/4/cuda_9.0.176.4_linux-run

- cuda_9_1:
    cuda_ver: 9.1.85
    min_driver_ver: 387.26
    installer_url: 
https://developer.nvidia.com/compute/cuda/9.1/Prod/local_installers/cuda_9.1.85_387.26_linux
    patchset_url_list:
      - 
https://developer.nvidia.com/compute/cuda/9.1/Prod/patches/1/cuda_9.1.85.1_linux
      - 
https://developer.nvidia.com/compute/cuda/9.1/Prod/patches/2/cuda_9.1.85.2_linux
      - 
https://developer.nvidia.com/compute/cuda/9.1/Prod/patches/3/cuda_9.1.85.3_linux

- cuda_9_2:
    cuda_ver: 9.2.148
    min_driver_ver: 396.37
    installer_url: 
https://developer.nvidia.com/compute/cuda/9.2/Prod2/local_installers/cuda_9.2.148_396.37_linux
    patchset_url_list:
      - 
https://developer.nvidia.com/compute/cuda/9.2/Prod2/patches/1/cuda_9.2.148.1_linux

- cuda_10_0:
    cuda_ver: 10.0.130
    min_driver_ver: 410.48
    installer_url: 
https://developer.nvidia.com/compute/cuda/10.0/Prod/local_installers/cuda_10.0.130_410.48_linux
    patchset_url_list:


Which when turned into an Ansible var via include_vars: ./cuda_versions.yml 
has the structure:
"cuda_versions": [
    {
        "cuda_8_0": {
            "cuda_ver": "8.0.61",
            "installer_url": 
"https://developer.nvidia.com/compute/cuda/8.0/Prod2/local_installers/cuda_8.0.61_375.26_linux-run";,
            "min_driver_ver": 375.26,
            "patchset_url_list": [
                
"https://developer.nvidia.com/compute/cuda/8.0/Prod2/patches/2/cuda_8.0.61.2_linux-run";
            ]
        }
    },
    {
        "cuda_9_0": {
            "cuda_ver": "9.0.176",
            "installer_url": 
"https://developer.nvidia.com/compute/cuda/9.0/Prod/local_installers/cuda_9.0.176_384.81_linux-run";,
            "min_driver_ver": 384.81,
            "patchset_url_list": [
                
"https://developer.nvidia.com/compute/cuda/9.0/Prod/patches/1/cuda_9.0.176.1_linux-run";,
                
"https://developer.nvidia.com/compute/cuda/9.0/Prod/patches/2/cuda_9.0.176.2_linux-run";,
                
"https://developer.nvidia.com/compute/cuda/9.0/Prod/patches/3/cuda_9.0.176.3_linux-run";,
                
"https://developer.nvidia.com/compute/cuda/9.0/Prod/patches/4/cuda_9.0.176.4_linux-run";
            ]
        }
    },
    {
        "cuda_9_1": {
            "cuda_ver": "9.1.85",
            "installer_url": 
"https://developer.nvidia.com/compute/cuda/9.1/Prod/local_installers/cuda_9.1.85_387.26_linux";,
            "min_driver_ver": 387.26,
            "patchset_url_list": [
                
"https://developer.nvidia.com/compute/cuda/9.1/Prod/patches/1/cuda_9.1.85.1_linux";,
                
"https://developer.nvidia.com/compute/cuda/9.1/Prod/patches/2/cuda_9.1.85.2_linux";,
                
"https://developer.nvidia.com/compute/cuda/9.1/Prod/patches/3/cuda_9.1.85.3_linux";
            ]
        }
    },
    {
        "cuda_9_2": {
            "cuda_ver": "9.2.148",
            "installer_url": 
"https://developer.nvidia.com/compute/cuda/9.2/Prod2/local_installers/cuda_9.2.148_396.37_linux";,
            "min_driver_ver": 396.37,
            "patchset_url_list": [
                
"https://developer.nvidia.com/compute/cuda/9.2/Prod2/patches/1/cuda_9.2.148.1_linux";
            ]
        }
    },
    {
        "cuda_10_0": {
            "cuda_ver": "10.0.130",
            "installer_url": 
"https://developer.nvidia.com/compute/cuda/10.0/Prod/local_installers/cuda_10.0.130_410.48_linux";,
            "min_driver_ver": 410.48,
            "patchset_url_list": null
        }
    }
]

Now I am stuck trying to get a value from a given key for a given item key 
in Ansible. For example, how would one get the "installer_url" value for 
the "cuda_9_0" item key from this var in Ansible? I tried a few things, but 
none of them have worked, and this is the most complicated var list that 
I've yet worked with :)

Or, is there a better way to structure my YAML so that it produces a better 
(more Ansible-friendly, easier to work with) data structure?

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/55405b6c-dc61-4128-9b56-d177df458856%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to