Collections are a distribution format for Ansible content. They can be used to
Collections are a distribution format for Ansible content. They can be used to
package and distribute playbooks, roles, modules, and plugins.
package and distribute playbooks, roles, modules, and plugins.
You will be able to publish and use collections through `Ansible's Galaxy repository <https://galaxy.ansible.com>`_.
You can publish and use collections through `Ansible Galaxy <https://galaxy.ansible.com>`_.
..important::
..important::
This feature is available in Ansible 2.8 as a *Technology Preview* and therefore is not fully supported. It should only be used for testing and should not be deployed in a production environment.
This feature is available in Ansible 2.8 as a *Technology Preview* and therefore is not fully supported. It should only be used for testing and should not be deployed in a production environment.
Future Galaxy or Ansible releases may introduce breaking changes.
Future Galaxy or Ansible releases may introduce breaking changes.
..contents::
..contents::
:local:
:local:
:depth:2
Collection structure
Collection structure
====================
====================
Collections follow a simple data structure. None of the directories are required unless you have specific content that belongs in one of them. They do require a ``galaxy.yml`` file at the root level of the collection. This file contains all of the metadata that Galaxy
Collections follow a simple data structure. None of the directories are required unless you have specific content that belongs in one of them. A collection does require a ``galaxy.yml`` file at the root level of the collection. This file contains all of the metadata that Galaxy
and other tools need in order to package, build and publish the collection.::
and other tools need in order to package, build and publish the collection.::
collection/
collection/
@ -47,8 +48,8 @@ and other tools need in order to package, build and publish the collection.::
..note::
..note::
* We will only accept``.yml`` extensions for galaxy.yml.
* Ansible only accepts``.yml`` extensions for galaxy.yml.
* A full structure can be found at `Draft collection <https://github.com/bcoca/collection>`_
* See the `draft collection <https://github.com/bcoca/collection>`_ for an example of a full collection structure.
* Not all directories are currently in use. Those are placeholders for future features.
* Not all directories are currently in use. Those are placeholders for future features.
@ -56,15 +57,17 @@ galaxy.yml
----------
----------
A collection must have a ``galaxy.yml`` file that contains the necessary information to build a collection artifact.
A collection must have a ``galaxy.yml`` file that contains the necessary information to build a collection artifact.
See :ref:`collections_galaxy_meta` for details on how this file is structured.
See :ref:`collections_galaxy_meta` for details.
docs directory
docs directory
---------------
---------------
Keep general documentation for the collection here. Plugins and modules will still keep their specific documentation embedded as Python docstrings. Use the ``docs`` folder to describe how to use the roles and plugins the collection provides, role requirements, and so on. Currently we are looking at Markdown as the standard format for documentation files, but this is subject to change.
Keep general documentation for the collection here. Plugins and modules still keep their specific documentation embedded as Python docstrings. Use the ``docs`` folder to describe how to use the roles and plugins the collection provides, role requirements, and so on. Currently we are looking at Markdown as the standard format for documentation files, but this is subject to change.
We are `updating ansible-doc <https://github.com/ansible/ansible/pull/57764>`_ to allow showing documentation for plugins inside a collection::
Use ``ansible-doc`` to view documentation for plugins inside a collection:
..code-block:: bash
ansible-doc -t lookup mycol.myname.lookup1
ansible-doc -t lookup mycol.myname.lookup1
@ -74,7 +77,7 @@ The ``ansible-doc`` command requires the fully qualified collection name (FQCN)
plugins directory
plugins directory
------------------
------------------
Add a 'per plugin type' specific subdirectory here, including ``module_utils`` which is usable not only by modules, but by any other plugin by using their FQCN. This is a way to distribute modules, lookups, filters, and so on, without having to import a role in every play.
Add a 'per plugin type' specific subdirectory here, including ``module_utils`` which is usable not only by modules, but by any other plugin by using their FQCN. This is a way to distribute modules, lookups, filters, and so on, without having to import a role in every play.
roles directory
roles directory
@ -83,7 +86,7 @@ roles directory
Collection roles are mostly the same as existing roles, but with a couple of limitations:
Collection roles are mostly the same as existing roles, but with a couple of limitations:
- Role names are now limited to contain only lowercase alphanumeric characters, plus ``_`` and start with an alpha character.
- Role names are now limited to contain only lowercase alphanumeric characters, plus ``_`` and start with an alpha character.
- Roles cannot have their own plugins any more. The plugins must live in the collection ``plugins`` directory and will be accessible to the collection roles.
- Roles in a collection cannot contain plugins any more. Plugins must live in the collection ``plugins`` directory tree. Each plugin is accessible to all roles in the collection.
The directory name of the role is used as the role name. Therefore, the directory name must comply with the
The directory name of the role is used as the role name. Therefore, the directory name must comply with the
above role name rules.
above role name rules.
@ -111,10 +114,16 @@ TBD. Expect tests for the collection itself to reside here.
.._creating_collections:
.._creating_collections:
Creating collections
Creating collections
====================
======================
This is currently a work in progress with some basic commands being integrated into the existing ``ansible-galaxy``
To create a collection:
command line tool that is included with Ansible.
#. Initialize a collection with :ref:`ansible-galaxy collection init<creating_collections_skeleton>` to create the skeleton directory structure.
#. Add your content to the collection.
#. Build the collection into a collection artifact with :ref:`ansible-galaxy collection build<building_collections>`.
#. Publish the collection artifact to Galaxy with :ref:`ansible-galaxy collection publish<publishing_collections>`.
A user can then install your collection on their systems.
..note::
..note::
Any references to ``ansible-galaxy`` below will be of a 'working version' that is in development for the 2.9
Any references to ``ansible-galaxy`` below will be of a 'working version' that is in development for the 2.9
@ -122,35 +131,46 @@ command line tool that is included with Ansible.
Currently the ``ansible-galaxy collection`` command implements the following sub commands:
Currently the ``ansible-galaxy collection`` command implements the following sub commands:
* ``init``: Create a basic collection skeleton based on the default template included with Ansible or your own.
* ``init``: Create a basic collection skeleton based on the default template included with Ansible or your own template.
* ``build``: Create a collection artifact that can be uploaded to Galaxy or your own repository.
* ``build``: Create a collection artifact that can be uploaded to Galaxy or your own repository.
* ``publish``: Publish a built collection artifact to Galaxy.
* ``publish``: Publish a built collection artifact to Galaxy.
* ``install``: Install one or multiple collections.
* ``install``: Install one or more collections.
To learn more about the ``ansible-galaxy`` cli tool, see the :ref:`ansible-galaxy` man page.
.._creating_collections_skeleton:
To learn more about the ``ansible-galaxy`` cli tool, read the :ref:`ansible-galaxy` man page.
Creating a collection skeleton
------------------------------
In the end, to get started with authoring a new collection it should be as simple as:
Go to the `My Content <https://galaxy.ansible.com/my-content/namespaces>`_ page, and click the **Add Content** button on one of your namespaces. From
To upload your collection artifact directly on Galaxy:
the **Add Content** dialogue, click **Upload New Collection**, and select the collection archive file from your local
filesystem.
#. Go to the `My Content <https://galaxy.ansible.com/my-content/namespaces>`_ page, and click the **Add Content** button on one of your namespaces.
#. From the **Add Content** dialogue, click **Upload New Collection**, and select the collection archive file from your local filesystem.
When uploading collections it doesn't matter which namespace you select. The collection will be uploaded to the
When uploading collections it doesn't matter which namespace you select. The collection will be uploaded to the
namespace specified in the collection metadata in the ``galaxy.yml`` file. If you're not an owner of the
namespace specified in the collection metadata in the ``galaxy.yml`` file. If you're not an owner of the
@ -206,30 +232,29 @@ will be the version displayed everywhere in Galaxy; however, users will still be
Installing collections
Installing collections
======================
----------------------
The recommended way to install a collection is:
You can use the ``ansible-galaxy collection install`` command to install a collection on your system. The collection by default is installed at ``/path/ansible_collections/my_namespace/my_collection``. You can optionally add the ``-p`` option to specify an alternate location.
To install a collection hosted in Galaxy:
..code-block:: bash
..code-block:: bash
# Will install the collection to /path/ansible_collections/mynamespace/mycollection
The install command will automatically append the path ``ansible_collections`` to the one specified unless the
The install command automatically appends the path ``ansible_collections`` to the one specified with the ``-p`` option unless the
parent directory is already in a folder called ``ansible_collections``.
parent directory is already in a folder called ``ansible_collections``.
As a path you should use one of the values configured in :ref:`COLLECTIONS_PATHS`. This is also where Ansible itself will expect to find collections when attempting to use them.
You should use one of the values configured in :ref:`COLLECTIONS_PATHS` for your path. This is also where Ansible itself will expect to find collections when attempting to use them.
You can also keep a collection adjacent to the current playbook, under a ``collections/ansible_collections/`` directory structure.
You can also keep a collection adjacent to the current playbook, under a ``collections/ansible_collections/`` directory structure.
@ -238,23 +263,33 @@ You can also keep a collection adjacent to the current playbook, under a ``colle