使用这个yaml,我试图获得一个'Machine‘属性的列表。
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“的变量中,我可以获得服务器的列表,下面的代码如下:
我得到:
ok: wls-pil-10-sa-adm-n0 => { "msg":"wls-pil-10-sa-adm-n0","test-bruno-jee-r01a-it-c01-m1-n1",“test-bruno-jee-r01a-it-c01-m2”}
我试图用以下代码获取机器列表:
但不可能。怎样才能得到这些信息?
感谢大家!
发布于 2020-12-21 12:58:50
试试json_query
- debug:
msg: "{{ yaml_domain_file.topology.Server|json_query('*.Machine') }}"问:"what如果我想把每台服务器放在一个array?"中
答:最简单的选择是dict2items过滤器。例如
- set_fact:
servers: "{{ yaml_domain_file.topology.Server|dict2items }}"https://stackoverflow.com/questions/65392949
复制相似问题