[英]How to get a custom list from yaml file using ansible?
Using this yaml I'm trying to get a list of the 'Machine' attribute.使用这个 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'
I can get a list of the servers by putting the yaml in a variable named "yaml_domain_file" and this code:我可以通过将 yaml 放入名为“yaml_domain_file”的变量中来获取服务器列表,并且此代码:
I get:我得到:
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-m1-n2" ] }好的:[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”] }
I'm trying to get the list of machines with this code:我正在尝试使用以下代码获取机器列表:
but is not possible.但不可能。 How to get that information?如何获取这些信息?
Thanks to everyone !谢谢大家 !
Try json_query试试 json_query
- debug:
msg: "{{ yaml_domain_file.topology.Server|json_query('*.Machine') }}"
Q: " what If I want to put each of the servers in an array? "问: “如果我想将每台服务器放在一个阵列中怎么办? ”
A: The simplest option is dict2items filter.答:最简单的选项是dict2items过滤器。 For example例如
- set_fact:
servers: "{{ yaml_domain_file.topology.Server|dict2items }}"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.