Add an example of how to reload local facts.

This commit is contained in:
Michael DeHaan 2014-04-29 15:46:47 -04:00
parent cff4b5d412
commit ef3c9c6026

View file

@ -608,6 +608,7 @@ Local Facts (Facts.d)
.. versionadded:: 1.3 .. versionadded:: 1.3
As discussed in the playbooks chapter, Ansible facts are a way of getting data about remote systems for use in playbook variables. As discussed in the playbooks chapter, Ansible facts are a way of getting data about remote systems for use in playbook variables.
Usually these are discovered automatically by the 'setup' module in Ansible. Users can also write custom facts modules, as described Usually these are discovered automatically by the 'setup' module in Ansible. Users can also write custom facts modules, as described
in the API guide. However, what if you want to have a simple way to provide system or user in the API guide. However, what if you want to have a simple way to provide system or user
provided data for use in Ansible variables, without writing a fact module? provided data for use in Ansible variables, without writing a fact module?
@ -648,6 +649,21 @@ And this data can be accessed in a template/playbook as::
The local namespace prevents any user supplied fact from overriding system facts The local namespace prevents any user supplied fact from overriding system facts
or variables defined elsewhere in the playbook. or variables defined elsewhere in the playbook.
If you have a playbook that is copying over a custom fact and then running it, making an explicit call to re-run the setup module
can allow that fact to be used during that particular play. Otherwise, it will be available in the next play that gathers fact information.
Here is an example of what that might look like::
- hosts: webservers
tasks:
- name: create directory for ansible custom facts
file: state=directory recurse=yes path=/etc/ansible/facts.d
- name: install custom impi fact
copy: src=ipmi.fact dest=/etc/ansible/facts.d
- name: re-read facts after adding custom fact
setup: filter=ansible_local
In this pattern however, you could also write a fact module as well, and may wish to consider this as an option.
.. _registered_variables: .. _registered_variables:
Registered Variables Registered Variables