On demand gather_facts?

Hi,

I was wondering if there are any plans to add an on demand gather_facts-like meta task (similar to “- meta: flush_handlers”)?

Use case:

  • during the bootstrapping of a system the play must have “gather_facts: off” (else: invalid output was: /bin/sh: 1: /usr/bin/python: not found)
  • but after python and python-apt or similar minimum has been installed, one could trigger gathering of facts and the rest would work
  • now bootstrapping has to be done as a separate play, but it could be part of pre_tasks

Greetings,
gw

Use setup module in task, it is the one that does it

Brian Coca

If you use gather_facts: False in one play, I thought setup would run on a subsequent play where that’s not set false?

Hi,

I don’t exactly understand what you thought, but it works exactly as Brian said (thanks!).

Inside one play with “gather_facts: no” this three tasks work as expected:

TASK: [debug msg=“aa {{ansible_hostname}}”] ***********************************
ok: [xxx.lan] => {“msg”: “aa {{ansible_hostname}}”}
TASK: [setup] *******************************************
ok: [xxx.lan]
TASK: [debug msg=“aa {{ansible_hostname}}”] ***********************************
ok: [xxx.lan] => {“msg”: “aa main”}

Greetings,
gw

@Serge, yes, but you might want it to run for tasks in the first play.

​Then by default they will, in the next separate play, unless you specifiy
gather_facts: false​ there.
If I learnt one thing in ansible, it is to not be afraid to spawn a
separate play.

But of course, issuing the setup module as a separate task in the first
play, will also work.

Serge