Ansible-收集事实前的行动
是否有人知道在收集事实之前如何做一些事情(比如等待托管节点的端口/引导)?我知道我可以关掉收集事实的工作Ansible-收集事实前的行动,ansible,ansible-facts,Ansible,Ansible Facts,是否有人知道在收集事实之前如何做一些事情(比如等待托管节点的端口/引导)?我知道我可以关掉收集事实的工作 gather_facts: no 然后等待端口,但如果我需要事实,同时还需要等待节点启动,该怎么办?收集事实相当于运行。您可以通过运行它来手动收集事实。没有文档记录,只需添加如下任务: - name: Gathering facts setup: 与playbook级别的collect\u facts:no相结合,只有在执行上述任务时才会获取事实 在示例剧本中: - hosts: a
gather_facts: no
然后等待端口,但如果我需要事实,同时还需要等待节点启动,该怎么办?收集事实相当于运行。您可以通过运行它来手动收集事实。没有文档记录,只需添加如下任务:
- name: Gathering facts
setup:
与playbook级别的collect\u 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...
等待将在您的ansible主机上本地执行,等待服务器在端口22上响应,然后安装模块将执行事实收集,之后您可以执行任何其他需要执行的操作。我试图找出如何从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----
我认为ansible术语是,我在一个剧本中有两个剧本,每个剧本都在不同的主机组(localhost和appServer组)上运行