首页 > 解决方案 > 标签/标签的 Ansible 动态库存过滤器

问题描述

我正在尝试使用 Ansible 运行动态库存列表

ansible-inventory --list -i gcp.yaml
---
plugin: gcp_compute
projects:
  - <project name>
auth_kind: serviceaccount
service_account_file: /opt/ansible/inventory/peak-equator-SA.json
filters:
        - labels|list = "ansible"

收到以下错误

[WARNING]:  * Failed to parse /opt/ansible/inventory/gcp.yaml with auto plugin: [{'message': 'Invalid value for field \'filter\': \'labels|list = "ansible"\'. Invalid
list filter expression.', 'domain': 'global', 'reason': 'invalid'}]
[WARNING]:  * Failed to parse /opt/ansible/inventory/gcp.yaml with yaml plugin: Plugin configuration YAML file, not YAML inventory
[WARNING]:  * Failed to parse /opt/ansible/inventory/gcp.yaml with ini plugin: Invalid host pattern '---' supplied, '---' is normally a sign this is a YAML file.
[WARNING]: Unable to parse /opt/ansible/inventory/gcp.yaml as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
{
    "_meta": {
        "hostvars": {}
    },
    "all": {
        "children": [
            "ungrouped"
        ]
    }
}

标签: ansibleyaml

解决方案


我从不使用这个库存模块,但根据模块页面,过滤器应该是这样的:

filters:
    - labels = ansible

推荐阅读