Ansible EC2 dynamic inventory - tag containing a hyphen

时间:2016-12-09 12:56:21

标签: amazon-web-services amazon-ec2 ansible ansible-inventory

I'm trying to run an ad-hoc ansible command on hosts that have been tagged as Name = foo-bar (notice the hyphen). When I run:

ansible tag_Name_foo_bar -i ec2.py -m ping

I get: No hosts matched

However, there is such a host. If I run the same command against a host that is tagged with a name not containing a hyphen, it works fine, e.g for a host that is tagged Name = foobar, the following works:

ansible tag_Name_foobar -i ec2.py -m ping

H

1 个答案:

答案 0 :(得分:1)

你的ansible版本是什么?这个对我有用。根据{{​​3}}

<强>代码

  

每个实例都可以有多种与之关联的键/值对   叫做标签。最常见的标记键是“名称”,但任何东西都是   可能。每个键/值对都是它自己的一组实例   特殊字符转换为下划线,格式   tag_KEY_VALUE例如tag_Name_Web可以按原样使用   tag_Name_redis-master-001变为tag_Name_redis_master_001   tag_aws_cloudformation_logical-id_WebServerGroup成为   tag_aws_cloudformation_logical_id_WebServerGroup

有可能ansible的ec2缓存没有刷新。尝试:

ec2.py --refresh-cache

然后再次运行你的ansible命令。当我将实例标记名称更改为foo_bar时,ot工作正常。