我刚刚开始使用ansible并且已成功配置ansible以从GCP获取动态库存。
我能够针对所有实例成功运行ping模块:
ansible -i ~/git/ansible/inventory all -m ping
我也能够针对基于主机名的单个实例成功运行ping模块:
ansible -i ~/git/ansible/inventory instance-2 -m ping
我现在想利用标签来分组实例。例如,我有一组标记为'env:dev'https://www.evernote.com/l/AfcLWLkermxMyIK7GvGpQXjXdIDFVAiT_z0的实例
我尝试了以下命令的多种变体而没有运气
ansible -i ~/git/ansible/inventory tag_env:dev -m ping
如何在GCP上过滤和分组动态广告资源?
所以你需要在实例设置中添加网络标签而不是标签我不知道为什么但是gce.py没有返回GCP标签,因此你只能使用有限的网络标签(我的意思是不是key = value而只是值)示例添加网络标记只是'dev'然后运行ansible -i ~/git/ansible/inventory tag_dev -m ping
如果你需要过滤几个标签只有我发现它的方式
- name: test stuff
hosts: tag_api:&tag_{{ environment }}
var_files:
vars/{{ environment }}
vars/api
tasks:
- name: test
command: echo "test"
像这个ansible-playbook -i inventory/ -u user playbook/test.yml -e environment=dev
一样运行剧本
也许有人知道更好的方式,与aws ec2.py
我可以在ec2.ini
配置过滤但gce.py
非常有限也我注意到有时你需要清除缓存gce.py --refresh-cache