filter - Ansible/Jinja2 - Map nested key in list -


when map'ing attribute in list of nested variables, not able retrieve key.

i want retrieve key of "tls_cert_file" followingemphasized text variables:

vault_config_listener:   - tcp:     - address: "0.0.0.0:8200"     - tls_cert_file: "/etc/ssl/wildcard.crt"     - tls_key_file: "/etc/ssl/private/wildcard.key"     - tls_require_and_verify_client_cert: "false"   - tcp:     - address: "127.0.0.1:8200"     - tls_disable: true 

the debug task:

- debug:     msg: "{{ (vault_config_listener | selectattr('tcp', 'defined') | map(attribute='tcp')) | selectattr('tls_cert_file','defined') | map(attribute='tls_cert_file') | join('') | dirname }}" 

the output:

ok: [test] => {     "msg": "" } 

i got map'ing working until "tcp", no further... wrong @ logic?

to list of tls_cert_file can use

vault_config_listener | selectattr('tcp', 'defined') | map(attribute='tcp') | sum(start=[]) | selectattr('tls_cert_file','defined') | map(attribute='tls_cert_file') | list 

note sum(start=[]) – used flatten list of lists.

p.s. why join possible(?) multiple paths string?

p.p.s data structure seems rather weird. why define tcp properties list, , not just:

tcp:   address: 0.0.0.0:8200   tls_cert_file: /etc/ssl/wildcard.crt   tls_key_file: /etc/ssl/private/wildcard.key   tls_require_and_verify_client_cert: false 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -