首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >适用于标签/标签的动态库存过滤器

适用于标签/标签的动态库存过滤器
EN

Stack Overflow用户
提问于 2021-06-27 16:09:05
回答 2查看 253关注 0票数 1

我正在尝试使用Ansible运行动态清单

ansible-inventory --list -i gcp.yaml

代码语言:javascript
运行
复制
---
plugin: gcp_compute
projects:
  - <project name>
auth_kind: serviceaccount
service_account_file: /opt/ansible/inventory/peak-equator-SA.json
filters:
        - labels|list = "ansible"

获取以下错误

代码语言:javascript
运行
复制
[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"
        ]
    }
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-06-29 06:11:09

在我刚刚遇到这个之后,“过滤器”不是Ansible过滤器,而是特定于Google Cloud API的过滤器:https://cloud.google.com/compute/docs/reference/rest/v1/instances/aggregatedList (注意:没有in运算符)。

我能够使用labels.ansible != ""作为变通方法。完整的动态清单配置以供参考(GCP有最糟糕的Ansible文档,所以我知道这对外面的人很有用):

代码语言:javascript
运行
复制
---
plugin: gcp_compute
projects: PROJECT_NAME_HERE

# auth using "gcloud auth application-default login"...
# you don't need a service account this way
auth_kind: application

keyed_groups:
  - key: labels
    prefix: label
  - key: zone
    prefix: zone
      
# drop any servers without an "ansible" label
# (ie. gke managed nodes)
filters:
  - labels.ansible != ""

# hostname shown in inventory
hostnames:
  - name

# ssh to hosts using private IP address
compose:
  ansible_host: networkInterfaces[0].networkIP
票数 0
EN

Stack Overflow用户

发布于 2021-06-27 16:29:19

我从来没有使用过这个清单模块,但是根据module页面,过滤器应该是这样的:

代码语言:javascript
运行
复制
filters:
    - labels = ansible
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68149185

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档