5
- servers: "ands_storage_servers"
6
clients: "ands_servers"
8
provision: { type: "cfg", mount: "{{ ands_paths.provision }}" }
9
- servers: "storage_nodes"
12
openshift: { type: "cfg", mount: "{{ ands_paths.openshift }}" }
13
temporary: { type: "tmp", mount: "{{ ands_paths.temporary }}" }
18
ands_openshift_volumes:
19
etc: { volume: "openshift", path: "/etc" }
20
src: { volume: "openshift", path: "/src" }
21
log: { volume: "temporary", path: "/log", write: true}
22
tmp: { volume: "temporary", path: "/tmp", write: true}
26
===> There is no easy way to convert between list and dirctionaries and re-structure either.
27
- Sub-arrays can be flatten with 'sum' filter
28
list_of_lists | sum(start=[])
30
- There is no way to merge list of dictionaries (or also ictionary of dictionaries) other than regexping yaml
31
The following gets plain hash of volumes from the list of hashes.
32
gfs_volumes: "{{ ands_storage_domains | json_query('[*].volumes') | to_yaml | regex_replace('(^|\\n)(-|\\s)\\s(\\w)', '\\1\\3') | from_yaml }}"
33
Another option to keep it as list (but a single hash per list)
34
gfs_volumes: "{{ ands_storage_domains | json_query('[*].volumes') | to_yaml | regex_replace('(^|\\n)(-|\\s)\\s([\\w\\d]+):\\s*{', '\\1- { name: \\3, ') | from_yaml }}"
35
And more complex way to achieve this
36
gfs_volumes: "{{ ands_storage_domains | json_query('[*].volumes') | map('to_yaml') | map('regex_replace', '(^|\\n)(\\s*)([\\w\\d]+):\\s*{', '\\1\\2- { name: \\3, ') | map('from_yaml') | list }}"
38
- Combining is also pretty limited. The following will extract the proper mount points.
39
kaas_path: "{{ ands_openshift_volumes | json_query('*.volume') | map('extract', gfs_volumes, 'mount') | list }}"
40
But how just to replace 'volume' key with mount point?
43
- It is slightly easier in tasks. The following snippet will generate 'kaas_*_path' variables with full path.
44
- name: Get KaaS volume paths
45
set_fact: "kaas_{{item.key}}_path={{ mntpath[0] ~ (item.value.path | default('')) }}"
46
with_dict: "{{ ands_openshift_volumes }}"
48
query: "[*].volumes.{{item.value.volume}}.mount"
49
mntpath: "{{ (ands_storage_domains | json_query(query)) }}"
50
when: ( mntpath | length ) > 0
55
- Generally array are easier to handle. The hashes are mostly used when we know keys, not then we plan to iterate.
b'\\ No newline at end of file'