重新加载Ansible的动态广告资源 [英] Reload Ansible's dynamic inventory
问题描述
我正在使用Ansible设置EC2实例并部署应用程序.有一个主机脚本,该脚本收集与标签相关的服务器和组信息.我想将这些操作作为一个剧本运行,所以
I'm using Ansible to setup EC2 instances and deploy an app. There's a hosts script which gathers tags related servers and groups info. I'd like to run these actions as a single playbook, so
- 根据需要创建新实例
- 主机脚本加载清单(包括服务器的事实)
- 部署手册有效
但是,库存是预先加载的,因此如果在播放过程中创建/更新服务器,则没有服务器/组数据.我可以1)分开配置和部署手册,2)在服务器更新时使用add_host技巧来模拟动态清单,但是这些方法存在缺点.
However, inventory loaded in advance so there is no servers/groups data if servers created/updated during the play. I can 1) separate provision and deployment playbooks 2) use add_host trick to emulate dynamic inventory when servers are updated, but there are drawbacks in those approaches.
我可以强迫Ansible重新加载库存吗?我的测试文件是:
hosts
脚本:
Can I force Ansible to reload inventory? My test files are:
hosts
script:
#!/bin/sh
echo `date` >> log.log
echo "{\"standalone\":[\"localhost\"]}"
示例playbook.yml
:
---
- hosts: all
tasks:
- name: show inventory_hostname
command: echo {{ inventory_hostname }}
我运行它ansible-playbook -i hosts playbook.yml -v
并看到两次运行:
$> cat log.log
Thu Mar 12 09:43:16 SAMT 2015
Thu Mar 12 09:43:16 SAMT 2015
但是我还没有找到将它加倍的命令.
but I haven't found a command to double it.
推荐答案
With Ansible 2.0+, you can refresh your inventory mid-play by running the task:
- meta: refresh_inventory
这篇关于重新加载Ansible的动态广告资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!