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

尝试构建与属性匹配的服务器列表(在本例中为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系统中,设置ARP防火墙可以通过多种方法实现,包括使...
在Linux环境下,使用Jack2进行编译时,可以采取以下策略来提...
`getid`命令在Linux系统中用于获取当前进程的有效用户ID(EU...
在Linux环境下,codesign工具用于对代码进行签名,以确保其完...
Linux中的`tr`命令,其英文全称是“transform”,即转换的意...
Linux中的ARP防火墙是一种用于防止ARP欺骗攻击的安全措施,它...