如何使用ansible从yaml文件中获取自定义列表?

如何使用ansible从yaml文件中获取自定义列表?,ansible,yaml,jinja2,Ansible,Yaml,Jinja2,使用这个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 Prod

使用这个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”的变量中,我可以获得服务器列表,代码如下:

  • 设定事实: 服务器:{{yaml_domain_file.topology.Server | list}”
我得到:

确定:[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” ] }

我正在尝试获取具有以下代码的计算机列表:

  • 调试: msg:{{yaml_domain_file.topology.Server.*.Machine | list}}”
但这是不可能的。如何获得这些信息

谢谢大家

尝试json\u查询

-调试:
msg:{{yaml_domain_file.topology.Server}json_查询('*.Machine')}


问:“如果我想将每个服务器放在一个阵列中,该怎么办?”

答:最简单的选择是过滤器。比如说

-设置事实:
服务器:{{yaml_domain_file.topology.Server|dict2items}”

谢谢您的帮助!是否可以将“topology”的yaml分支放入变量中?
-set_fact:my_var=“{{yaml_domain_file.topology}”
prehaps?很有意义,谢谢!如果我想将每个服务器放在一个阵列中,该怎么办?