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?
The gather_facts module from the Ansible playbook runs the setup module by default at the start of each playbook to gather the facts about remote hosts. Fetch the Ansible facts and display them using a playbook. Fetching the Ansible facts, filtering them, and displaying them using a playbook.
You can use gather_facts: no keyword in your playbook. It will disable this task automatically.
Playbook execution. A playbook runs in order from top to bottom. Within each play, tasks also run in order from top to bottom.
As ansible delegate_to is a directive, not an individual module, It integrates with other modules and it controls the task execution by deciding which host should run the task at runtime.
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:
Something like this should work:
- 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...
The wait_for will execute locally on your ansible host, waiting for the servers to respond on port 22, then the setup module will perform fact gathering, after which you can do whatever else you need to do.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With