我正在使用 Ansible EC2 动态清单脚本来访问我在 EC2 中的主机。我正在寻找的主机有一个名为 的标签sisyphus_environment
和development
另一个名为sisyphus_project
的标签reddot
,所以我需要这些标签的交集。
但是,我什至无法过滤一个标签与 EC2 库存正常工作。
我可以使用 AWS CLI 清楚地找到有问题的实例:
$ aws ec2 describe-instances --filters \
Name=tag:sisyphus_environment,Values=development \
Name=tag:sisyphus_project,Values=reddot \
Name=tag:sisyphus_role,Values=nginx | \
jq '.Reservations[].Instances[] | { InstanceId: .InstanceId }'
{
"InstanceId": "i-deadbeef"
}
{
"InstanceId": "i-cafebabe"
}
我试图用 Ansible 做同样的事情,表示为由这些标签过滤的动态成员组成的静态组。
我的 ansible.cfg:
[defaults]
retry_files_enabled = false
roles_path = roles:galaxy_roles
inventory = inventory/
[ssh_connection]
ssh_args = -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no
我的库存目录如下所示:
$ tree inventory/
inventory/
├── ec2.ini
├── ec2.py
└── inventory.ini
0 directories, 3 files
我必须inventory
使用.ini
扩展名来命名,否则 Ansible 会尝试将其加载为 YAML 并失败。
我的inventory/inventory.ini
文件如下所示:
[tag_sisyphus_project_reddot]
# blank
[reddot:children]
tag_sisyphus_project_reddot
这与 Ansible 关于此事的文档类似。不幸的是,这个简单的事情失败了:
$ inventory/ec2.py --refresh-cache
...
$ ansible reddot -m command -a 'echo true'
[WARNING]: No hosts matched, nothing to do
如果我按标签查询,我会得到结果:
$ ansible tag_sisyphus_project_reddot -m command -a 'echo true'
10.0.0.1 | SUCCESS | rc=0 >>
true
...
有没有我错过的步骤?
我的 Ansible 版本:
$ ansible --version
ansible 2.2.0.0
config file = /home/naftuli/Documents/Development/ansible-reddot/ansible.cfg
configured module search path = Default w/o overrides