[英]How to get a custom list from yaml file using ansible?
使用這個 yaml 我正在嘗試獲取“機器”屬性的列表。
domainInfo:
AdminUserName: '--FIX ME--'
AdminPassword: '--FIX ME--'
topology:
Name: 'wld-pil-10'
ConfigBackupEnabled: true
AdminServerName: 'wls-pil-10-sa-adm-n0'
DomainVersion: 12.2.1.4.0
ProductionModeEnabled: true
ArchiveConfigurationCount: 20
Cluster:
'test-bruno-jee-r01a-c01':
ClientCertProxyEnabled: true
WeblogicPluginEnabled: true
Server:
'wls-pil-10-sa-adm-n0':
ListenPort: 11030
WeblogicPluginEnabled: true
ClientCertProxyEnabled: true
Machine: 'wlm-pil-10-n0'
'test-bruno-jee-r01a-it-c01-m1-n1':
ListenPort: 10022
WeblogicPluginEnabled: true
ClientCertProxyEnabled: true
NMSocketCreateTimeoutInMillis: 30000
Machine: 'wlm-pil-10-n1'
'test-bruno-jee-r02a-it-c01-m1-n1':
ListenPort: 10025
WeblogicPluginEnabled: true
ClientCertProxyEnabled: true
NMSocketCreateTimeoutInMillis: 30000
Machine: 'wlm-pil-10-n2'
我可以通過將 yaml 放入名為“yaml_domain_file”的變量中來獲取服務器列表,並且此代碼:
我得到:
好的:[wls-pil-10-sa-adm-n0] => {“味精”:[“wls-pil-10-sa-adm-n0”,“test-bruno-jee-r01a-it-c01- m1-n1”,“test-bruno-jee-r01a-it-c01-m1-n2”] }
我正在嘗試使用以下代碼獲取機器列表:
但不可能。 如何獲取這些信息?
謝謝大家 !
試試 json_query
- debug:
msg: "{{ yaml_domain_file.topology.Server|json_query('*.Machine') }}"
問: “如果我想將每台服務器放在一個陣列中怎么辦? ”
答:最簡單的選項是dict2items過濾器。 例如
- set_fact:
servers: "{{ yaml_domain_file.topology.Server|dict2items }}"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.