Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible - actions BEFORE gathering facts

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?

like image 306
silverdr Avatar asked Jun 25 '15 15:06

silverdr


People also ask

How do you gather ansible facts?

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.

How do you stop ansible gathering facts?

You can use gather_facts: no keyword in your playbook. It will disable this task automatically.

What's the ansible playbook execution order?

Playbook execution. A playbook runs in order from top to bottom. Within each play, tasks also run in order from top to bottom.

What does Delegate_to do in ansible?

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.


2 Answers

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: 
like image 156
udondan Avatar answered Nov 09 '22 23:11

udondan


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.

like image 31
Bruce P Avatar answered Nov 09 '22 22:11

Bruce P