/docs/MyDocs

To get this branch, use:
bzr branch http://darksoft.org/webbzr/docs/MyDocs

« back to all changes in this revision

Viewing changes to Administration/Server/Provisioning/ansible/structures.txt

  • Committer: Suren A. Chilingaryan
  • Date: 2017-04-03 02:45:17 UTC
  • Revision ID: csa@suren.me-20170403024517-dwzj0z0k1cmhxm7u
Restructuring, OpenShift, Ansible, Git

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
Lists vs Dicts
 
2
==============
 
3
 
 
4
ands_storage_domains:
 
5
  - servers: "ands_storage_servers"
 
6
    clients: "ands_servers"
 
7
    volumes:
 
8
      provision: { type: "cfg", mount: "{{ ands_paths.provision }}" }
 
9
  - servers: "storage_nodes"
 
10
    clients: "nodes"
 
11
    volumes: 
 
12
      openshift: { type: "cfg", mount: "{{ ands_paths.openshift }}" }
 
13
      temporary: { type: "tmp", mount: "{{ ands_paths.temporary }}" }
 
14
#  - ovirt:
 
15
#  - pdv:
 
16
 
 
17
# Passed
 
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}
 
23
 
 
24
 
 
25
 
 
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=[])
 
29
    
 
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  }}"
 
37
 
 
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?
 
41
 
 
42
 
 
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 }}"
 
47
        vars:
 
48
          query: "[*].volumes.{{item.value.volume}}.mount"
 
49
          mntpath: "{{ (ands_storage_domains | json_query(query)) }}"
 
50
        when: ( mntpath | length ) > 0
 
51
        no_log: true
 
52
 
 
53
Recommendations
 
54
===============
 
55
 - Generally array are easier to handle. The hashes are mostly used when we know keys, not then we plan to iterate.
 
56
    
 
 
b'\\ No newline at end of file'