[英]Ansible - actions BEFORE gathering facts
有谁知道在收集事实之前如何做某事(比如等待托管节点的端口/启动)? 我知道我可以关闭收集事实
gather_facts: no
然后等待端口,但是如果我需要事实同时还需要等到节点启动怎么办?
收集事实相当于运行setup
模块。 您可以通过运行它来手动收集事实。 它没有记录,但只需添加这样的任务:
- name: Gathering facts
setup:
结合gather_facts: no
在剧本级别,只有在执行上述任务时才会获取事实。
两者都在示例剧本中:
- hosts: all
gather_facts: no
tasks:
- name: Some task executed before gathering facts
# whatever task you want to run
- name: Gathering facts
setup:
像这样的东西应该工作:
- hosts: my_hosts
gather_facts: no
tasks:
- name: wait for SSH to respond on all hosts
local_action: wait_for port=22
- name: gather facts
setup:
- continue with my tasks...
wait_for 将在你的 ansible 主机上本地执行,等待服务器在端口 22 上响应,然后 setup 模块将执行事实收集,之后你可以做任何你需要做的事情。
我试图弄清楚如何从 ec2 配置主机,等待 ssh 启动,然后针对它运行我的剧本。 这与您的用例基本相同。 我最终得到以下结果:
- name: Provision App Server from Amazon
hosts: localhost
gather_facts: False
tasks:
# #### call ec2 provisioning tasks here ####
- name: Add new instance to host group
add_host: hostname="{{item.private_ip}}" groupname="appServer"
with_items: ec2.instances
- name: Configure App Server
hosts: appServer
remote_user: ubuntu
gather_facts: True
tasks: ----configuration tasks here----
我认为 ansible 术语是我在剧本中有两个剧本,每个剧本都在不同的主机组(localhost 和 appServer 组)上运行
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.