linux – 基于匹配属性构建列表(ansible)

linux – 基于匹配属性构建列表(ansible),第1张

概述尝试构建属性匹配的服务器列表(在本例中为ec2_tag),以便为特定任务调度特定服务器. 我正在尝试与selectattr匹配: servers: "{{ hostvars[inventory_hostname]|selectattr('ec2_tag_Role', 'match', 'cassandra_db_seed_node') | map(attribute='inventory_hos 尝试构建与属性匹配的服务器列表(在本例中为ec2_tag),以便为特定任务调度特定服务器.

我正在尝试与selectattr匹配:

servers: "{{ hostvars[inventory_hostname]|selectattr('ec2_tag_Role','match','cassandra_db_seed_node') | map(attribute='inventory_hostname') |List}}"

虽然我从Ansible得到了类似错误:

fatal: [X.X.X.X]: Failed! => {"Failed": true,"msg": "Unexpected templating type error occurred on ({{ hostvars[inventory_hostname]|selectattr('ec2_tag_Role','cassandra_db_seed_node') | map(attribute='inventory_hostname') |List}}): expected string or buffer"}

我在这里错过了什么?

解决方法 您可以使用 group_by模块根据hostvar创建ad-hoc组:

- group_by:    key: 'ec2_tag_role_{{ ec2_tag_Role }}'

这将创建名为ec2_tag_role_ *的组,这意味着稍后您可以使用以下任何组创建游戏:

- hosts: ec2_tag_role_cassandra_db_seed_node  tasks:    - name: Your tasks...
总结

以上是内存溢出为你收集整理的linux – 基于匹配属性构建列表(ansible)全部内容,希望文章能够帮你解决linux – 基于匹配属性构建列表(ansible)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/1023693.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存