尝试构建与属性匹配的服务器列表(在本例中为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', 'match', '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...
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。