在收集事实信息之前,有人知道如何执行某些操作(例如等待受控节点的端口/引导)吗?我知道我可以关闭收集事实信息。
gather_facts: no
那么如果我在等待节点启动的同时也需要了解相关信息怎么办呢?
在收集事实信息之前,有人知道如何执行某些操作(例如等待受控节点的端口/引导)吗?我知道我可以关闭收集事实信息。
gather_facts: no
那么如果我在等待节点启动的同时也需要了解相关信息怎么办呢?
收集事实相当于运行setup
模块。您可以通过手动运行它来收集信息。这并没有记录在文档中,但只需添加如下任务:
- name: Gathering facts
setup:
gather_facts: no
与playbook的组合将在执行以上任务时仅获取事实(facts)。
在示例playbook中两者皆可:- 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启动,然后运行我的Playbook。这与您的使用情况基本相同。最终我得出了以下结论:
- 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----