You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ansible/docs/docsite/rst/plugins/cache.rst

141 lines
4.1 KiB
ReStructuredText

.. _cache_plugins:
Cache Plugins
=============
.. contents::
:local:
:depth: 2
Cache plugin implement a backend caching mechanism that allows Ansible to store gathered facts or inventory source data
without the performance hit of retrieving them from source.
The default cache plugin is the :ref:`memory <memory_cache>` plugin, which only caches the data for the current execution of Ansible. Other plugins with persistent storage are available to allow caching the data across runs.
You can use a separate cache plugin for inventory and facts. If an inventory-specific cache plugin is not provided and inventory caching is enabled, the fact cache plugin is used for inventory.
.. _enabling_cache:
Enabling Fact Cache Plugins
---------------------------
Only one fact cache plugin can be active at a time.
You can enable a cache plugin in the Ansible configuration, either via environment variable:
.. code-block:: shell
export ANSIBLE_CACHE_PLUGIN=jsonfile
or in the ``ansible.cfg`` file:
.. code-block:: ini
[defaults]
fact_caching=redis
Backport/2.9/docs (#63247) * add more anchors to collections docs (#62827) (cherry picked from commit 7e01de96d741c6fb8a1ce04f92873ffb57c9b1b5) * add anchors to support galaxy links (#62808) (cherry picked from commit 1b3bf33bdf2530adb3a7cbf8055007acb09b3bb2) * doc: fix typos (#62852) (cherry picked from commit b33ae1494936cd04fa89bce51e6068829fc89a91) * Add some documentation about using plugins in collections (#62465) - FQCN requirements - Sharing code in collections - Limitations with inventory caching (cherry picked from commit d41050b28b2d3e8d4a97ce13344b04fc87f703a2) * Remove Latin phrases from the docs (#62419) * add styleguide about avoiding use of latin words (cherry picked from commit e7436e278f8945dd73b066c47280c1a17bc18ebe) * ovirt: Fixing typo in ovirt_disk examples (#62962) (cherry picked from commit 50dc41cca2e6d75a05e933c5286f41bde235b65f) * vmware guidlines: adjust the location of cloud-config-vcenter.ini.template (#62970) Update the location of the cloud-config-vcenter.ini.template template. The file has been moved by: 2e7d36a3f969b31570d7ee34e3f1f971c5c586a9. (cherry picked from commit 7ecfa4a471ae17ee15aa51f684bf7d340805d432) * Prefer https:// links in the docs site (#62939) This is a follow-up of last year's 1a11cec. It deals with links which at that point either were not present or did not support https://. (cherry picked from commit c8315bfd6097f680ae79de5e4d4ee23d0c1068c0) * fix minor typos (#62950) (cherry picked from commit ad580a71c475b570cdbd4c79aaf0082ecccdf5fc) * Modernize Vagrant documentation (#62923) * By requiring a slightly newer Vagrant version (from 2015) we get the same generated Ansible inventory format is still used by today's version of Vagrant. That extended inventory format also has the benefit of allowing for simpler Ansible examples. * Switching to a current and supported Ubuntu LTS version. (cherry picked from commit 0d79013f51ca67eddcb1a3f6ff0f4453b659ee81) * add ios/iosxr deprecated modules (#62908) (cherry picked from commit 6bbd9c9eca5992d9fc53dd8fd8814205afaf508d)
5 years ago
If the cache plugin is in a collection use the fully qualified name:
.. code-block:: ini
[defaults]
fact_caching = namespace.collection_name.cache_plugin_name
You will also need to configure other settings specific to each plugin. Consult the individual plugin documentation
or the Ansible :ref:`configuration <ansible_configuration_settings>` for more details.
A custom cache plugin is enabled by dropping it into a ``cache_plugins`` directory adjacent to your play, inside a role, or by putting it in one of the directory sources configured in :ref:`ansible.cfg <ansible_configuration_settings>`.
Enabling Inventory Cache Plugins
--------------------------------
Backport/2.9/docs (#63247) * add more anchors to collections docs (#62827) (cherry picked from commit 7e01de96d741c6fb8a1ce04f92873ffb57c9b1b5) * add anchors to support galaxy links (#62808) (cherry picked from commit 1b3bf33bdf2530adb3a7cbf8055007acb09b3bb2) * doc: fix typos (#62852) (cherry picked from commit b33ae1494936cd04fa89bce51e6068829fc89a91) * Add some documentation about using plugins in collections (#62465) - FQCN requirements - Sharing code in collections - Limitations with inventory caching (cherry picked from commit d41050b28b2d3e8d4a97ce13344b04fc87f703a2) * Remove Latin phrases from the docs (#62419) * add styleguide about avoiding use of latin words (cherry picked from commit e7436e278f8945dd73b066c47280c1a17bc18ebe) * ovirt: Fixing typo in ovirt_disk examples (#62962) (cherry picked from commit 50dc41cca2e6d75a05e933c5286f41bde235b65f) * vmware guidlines: adjust the location of cloud-config-vcenter.ini.template (#62970) Update the location of the cloud-config-vcenter.ini.template template. The file has been moved by: 2e7d36a3f969b31570d7ee34e3f1f971c5c586a9. (cherry picked from commit 7ecfa4a471ae17ee15aa51f684bf7d340805d432) * Prefer https:// links in the docs site (#62939) This is a follow-up of last year's 1a11cec. It deals with links which at that point either were not present or did not support https://. (cherry picked from commit c8315bfd6097f680ae79de5e4d4ee23d0c1068c0) * fix minor typos (#62950) (cherry picked from commit ad580a71c475b570cdbd4c79aaf0082ecccdf5fc) * Modernize Vagrant documentation (#62923) * By requiring a slightly newer Vagrant version (from 2015) we get the same generated Ansible inventory format is still used by today's version of Vagrant. That extended inventory format also has the benefit of allowing for simpler Ansible examples. * Switching to a current and supported Ubuntu LTS version. (cherry picked from commit 0d79013f51ca67eddcb1a3f6ff0f4453b659ee81) * add ios/iosxr deprecated modules (#62908) (cherry picked from commit 6bbd9c9eca5992d9fc53dd8fd8814205afaf508d)
5 years ago
Inventory may be cached using a file-based cache plugin (like jsonfile). Check the specific inventory plugin to see if it supports caching. Cache plugins inside a collection are not supported for caching inventory.
If an inventory-specific cache plugin is not specified Ansible will fall back to caching inventory with the fact cache plugin options.
The inventory cache is disabled by default. You may enable it via environment variable:
.. code-block:: shell
export ANSIBLE_INVENTORY_CACHE=True
or in the ``ansible.cfg`` file:
.. code-block:: ini
[inventory]
cache=True
or if the inventory plugin accepts a YAML configuration source, in the configuration file:
.. code-block:: yaml
# dev.aws_ec2.yaml
plugin: aws_ec2
cache: True
Similarly with fact cache plugins, only one inventory cache plugin can be active at a time and may be set via environment variable:
.. code-block:: shell
export ANSIBLE_INVENTORY_CACHE_PLUGIN=jsonfile
or in the ansible.cfg file:
.. code-block:: ini
[inventory]
cache_plugin=jsonfile
or if the inventory plugin accepts a YAML configuration source, in the configuration file:
.. code-block:: yaml
# dev.aws_ec2.yaml
plugin: aws_ec2
cache_plugin: jsonfile
Consult the individual inventory plugin documentation or the Ansible :ref:`configuration <ansible_configuration_settings>` for more details.
.. _using_cache:
Using Cache Plugins
-------------------
Cache plugins are used automatically once they are enabled.
.. _cache_plugin_list:
Plugin List
-----------
You can use ``ansible-doc -t cache -l`` to see the list of available plugins.
Use ``ansible-doc -t cache <plugin name>`` to see specific documentation and examples.
.. toctree:: :maxdepth: 1
:glob:
cache/*
.. seealso::
:ref:`action_plugins`
Ansible Action plugins
:ref:`callback_plugins`
Ansible callback plugins
:ref:`connection_plugins`
Ansible connection plugins
:ref:`inventory_plugins`
Ansible inventory plugins
:ref:`shell_plugins`
Ansible Shell plugins
:ref:`strategy_plugins`
Ansible Strategy plugins
:ref:`vars_plugins`
Ansible Vars plugins
`User Mailing List <https://groups.google.com/forum/#!forum/ansible-devel>`_
Have a question? Stop by the google group!
`webchat.freenode.net <https://webchat.freenode.net>`_
#ansible IRC chat channel