50

Does anyone know how to do something (like wait for port / boot of the managed node) BEFORE gathering facts? I know I can turn gathering facts off

gather_facts: no

and THEN wait for port but what if I need the facts while also still need to wait until the node boots up?

4

3 回答 3

68

收集事实相当于运行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:
于 2015-06-25T19:32:58.870 回答
22

像这样的东西应该工作:

- 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 模块将执行事实收集,之后你可以做任何你需要做的事情。

于 2015-06-25T20:34:19.447 回答
2

我试图弄清楚如何从 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 组)上运行

于 2015-11-12T20:08:49.433 回答