0

There are a useful ansible command that gathing the facts and store them, like this,

ansible -m setup --tree out/ all

But how could do it by ansible-playbook -i inventory.ini ? just store the facts but not actually run the playbook and only for diagnosis.

Thanks James.

James.Y
  • 1,427
  • 1
  • 11
  • 16

1 Answers1

0

Very strange request, but...

To execute only fact-gathering part of your playbook you can execute it with a tag that doesn't exist:

ansible-playbook -i inventory.ini -vv -t zzzz myplaybook.yml

This will dump gathered facts to stdout.

If you want to store it into file, you should do something like this:

ANSIBLE_STDOUT_CALLBACK=json \
  ansible-playbook -i inventory.ini -t zzzz myplaybook.yml 2>/dev/null \
  | jq '.plays[].tasks[].hosts[]' > tmp_hosts_facts
Konstantin Suvorov
  • 65,183
  • 9
  • 162
  • 193
  • Thank you, actually I want to use the ansible-cmdb, https://github.com/fboender/ansible-cmdb, to output something. – James.Y Sep 29 '17 at 09:19