2019-09-19 22:09:19 +02:00
|
|
|
|
|
|
|
.. _collections:
|
|
|
|
|
|
|
|
*****************
|
|
|
|
Using collections
|
|
|
|
*****************
|
|
|
|
|
|
|
|
Collections are a distribution format for Ansible content that can include playbooks, roles, modules, and plugins.
|
|
|
|
You can install and use collections through `Ansible Galaxy <https://galaxy.ansible.com>`_.
|
|
|
|
|
|
|
|
.. contents::
|
|
|
|
:local:
|
|
|
|
:depth: 2
|
|
|
|
|
2019-09-25 14:32:44 +02:00
|
|
|
.. _collections_installing:
|
|
|
|
|
2019-09-19 22:09:19 +02:00
|
|
|
Installing collections
|
|
|
|
======================
|
|
|
|
|
2019-11-15 16:49:51 +01:00
|
|
|
|
|
|
|
Installing collections with ``ansible-galaxy``
|
|
|
|
----------------------------------------------
|
|
|
|
|
2019-10-11 20:19:44 +02:00
|
|
|
.. include:: ../shared_snippets/installing_collections.txt
|
2019-09-25 14:32:44 +02:00
|
|
|
|
|
|
|
.. _collections_older_version:
|
|
|
|
|
2019-09-19 22:09:19 +02:00
|
|
|
Installing an older version of a collection
|
|
|
|
-------------------------------------------
|
|
|
|
|
2019-10-11 20:19:44 +02:00
|
|
|
.. include:: ../shared_snippets/installing_older_collection.txt
|
2019-09-19 22:09:19 +02:00
|
|
|
|
|
|
|
.. _collection_requirements_file:
|
|
|
|
|
|
|
|
Install multiple collections with a requirements file
|
|
|
|
-----------------------------------------------------
|
|
|
|
|
2019-10-11 20:19:44 +02:00
|
|
|
.. include:: ../shared_snippets/installing_multiple_collections.txt
|
2019-09-19 22:09:19 +02:00
|
|
|
|
|
|
|
.. _galaxy_server_config:
|
|
|
|
|
2019-11-15 16:49:51 +01:00
|
|
|
Configuring the ``ansible-galaxy`` client
|
|
|
|
------------------------------------------
|
2019-09-19 22:09:19 +02:00
|
|
|
|
2019-10-11 20:19:44 +02:00
|
|
|
.. include:: ../shared_snippets/galaxy_server_list.txt
|
2019-09-19 22:09:19 +02:00
|
|
|
|
|
|
|
|
|
|
|
.. _using_collections:
|
|
|
|
|
|
|
|
Using collections in a Playbook
|
|
|
|
===============================
|
|
|
|
|
|
|
|
Once installed, you can reference a collection content by its fully qualified collection name (FQCN):
|
|
|
|
|
|
|
|
.. code-block:: yaml
|
|
|
|
|
|
|
|
- hosts: all
|
|
|
|
tasks:
|
|
|
|
- my_namespace.my_collection.mymodule:
|
|
|
|
option1: value
|
|
|
|
|
|
|
|
This works for roles or any type of plugin distributed within the collection:
|
|
|
|
|
|
|
|
.. code-block:: yaml
|
|
|
|
|
|
|
|
- hosts: all
|
|
|
|
tasks:
|
|
|
|
- import_role:
|
|
|
|
name: my_namespace.my_collection.role1
|
|
|
|
|
|
|
|
- my_namespace.mycollection.mymodule:
|
|
|
|
option1: value
|
|
|
|
|
|
|
|
- debug:
|
|
|
|
msg: '{{ lookup("my_namespace.my_collection.lookup1", 'param1')| my_namespace.my_collection.filter1 }}'
|
|
|
|
|
|
|
|
|
|
|
|
To avoid a lot of typing, you can use the ``collections`` keyword added in Ansible 2.8:
|
|
|
|
|
|
|
|
|
|
|
|
.. code-block:: yaml
|
|
|
|
|
|
|
|
- hosts: all
|
|
|
|
collections:
|
|
|
|
- my_namespace.my_collection
|
|
|
|
tasks:
|
|
|
|
- import_role:
|
|
|
|
name: role1
|
|
|
|
|
|
|
|
- mymodule:
|
|
|
|
option1: value
|
|
|
|
|
|
|
|
- debug:
|
|
|
|
msg: '{{ lookup("my_namespace.my_collection.lookup1", 'param1')| my_namespace.my_collection.filter1 }}'
|
|
|
|
|
|
|
|
This keyword creates a 'search path' for non namespaced plugin references. It does not import roles or anything else.
|
|
|
|
Notice that you still need the FQCN for non-action or module plugins.
|
|
|
|
|
|
|
|
.. seealso::
|
|
|
|
|
|
|
|
:ref:`developing_collections`
|
|
|
|
Develop or modify a collection.
|
|
|
|
:ref:`collections_galaxy_meta`
|
|
|
|
Understand the collections metadata structure.
|
|
|
|
`Mailing List <https://groups.google.com/group/ansible-devel>`_
|
|
|
|
The development mailing list
|
|
|
|
`irc.freenode.net <http://irc.freenode.net>`_
|
|
|
|
#ansible IRC chat channel
|