Ansible - actions BEFORE gathering facts

silverdr picture silverdr · Jun 25, 2015 · Viewed 19.5k times · Source

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?

Answer

udondan picture udondan · Jun 25, 2015

Gathering facts is equivalent to running the setup module. You can manually gather facts by running it. It's not documented, but simply add a task like this:

- name: Gathering facts
  setup:

In combination with gather_facts: no on playbook level the facts will only be fetched when above task is executed.

Both in an example playbook:

- hosts: all
  gather_facts: no
  tasks:

    - name: Some task executed before gathering facts
      # whatever task you want to run

    - name: Gathering facts
      setup: