linux – 基于匹配属性构建列表(ansible)
发布时间:2020-12-14 00:32:26 所属栏目:Linux 来源:网络整理
导读:尝试构建与属性匹配的服务器列表(在本例中为ec2_tag),以便为特定任务调度特定服务器. 我正在尝试与selectattr匹配: servers: "{{ hostvars[inventory_hostname]|selectattr('ec2_tag_Role','match','cassandra_db_seed_node') | map(attribute='inventory_h
尝试构建与属性匹配的服务器列表(在本例中为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... (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |