我正在尝试使用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"
]
}
}发布于 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文档,所以我知道这对外面的人很有用):
---
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发布于 2021-06-27 16:29:19
我从来没有使用过这个清单模块,但是根据module页面,过滤器应该是这样的:
filters:
- labels = ansiblehttps://stackoverflow.com/questions/68149185
复制相似问题