【问题标题】:Ansible: --limit on groups created with group_by?Ansible:--限制使用 group_by 创建的组?
【发布时间】:2018-04-19 00:15:53
【问题描述】:

我正在使用 ansible 来管理 GKE(Google Kubernetes Engine)上的主机。我使用 gce.py 让动态库存工作得很好。然后我使用 group_by 为每个集群创建组:

- group_by:
    key: "{{gce_metadata['cluster-name']}}"

但我不能将这些动态创建的组与--limit 一起使用这一事实严重阻碍了我的风格:

 $ ansible-playbook -l mycluster playbook.yaml
 ERROR! Specified hosts and/or --limit does not match any hosts

更酷的是能够使用带有 ansible ad-hoc 命令的 group_by 组...

【问题讨论】:

    标签: ansible ansible-inventory


    【解决方案1】:

    作为一种解决方法,我正在修改 gce.py#group_instances,添加以下子句:

            for entry in node.extra['metadata']['items']:
                if entry['key'] == 'cluster-name':
                    clusters.add(entry['value'])
                    if entry['value'] in groups:
                        groups[entry['value']].append(name)
                    else:
                        groups[entry['value']] = [name]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多