Skip to content

Commit 39e1e29

Browse files
authored
Clarify documentation about empty collections vs collection skeletons (#1180)
* Clarify documentation about empty collections vs collection skeletons * Update docs/docsite/rst/dev_guide/developing_collections_creating.rst
1 parent f570902 commit 39e1e29

File tree

1 file changed

+38
-6
lines changed

1 file changed

+38
-6
lines changed

docs/docsite/rst/dev_guide/developing_collections_creating.rst

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Creating collections
66

77
To create a collection:
88

9-
#. Create a :ref:`collection skeleton<creating_collections_skeleton>` with the ``ansible-galaxy collection init`` command.
9+
#. Create a :ref:`new collection<creating_new_collections>`, optionally using a custom :ref:`collection template<creating_collection_skeletons>`, with the ``ansible-galaxy collection init`` command.
1010
#. Add modules and other content to the collection.
1111
#. Build the collection into a collection artifact with :ref:`ansible-galaxy collection build<building_collections>`.
1212
#. Publish the collection artifact to Galaxy with :ref:`ansible-galaxy collection publish<publishing_collections>`.
@@ -44,10 +44,10 @@ There are a few special namespaces:
4444

4545
The `local namespace <https://galaxy.ansible.com/ui/namespaces/local/>`__ does not contain any collection on Ansible Galaxy, and the intention is that this will never change. You can use the ``local`` namespace for collections that are locally on your machine or locally in your git repositories, without having to fear collisions with actually existing collections on Ansible Galaxy.
4646

47-
.. _creating_collections_skeleton:
47+
.. _creating_new_collections:
4848

49-
Creating a collection skeleton
50-
==============================
49+
Creating a new collection
50+
=========================
5151

5252
Create your collection skeleton in a path that includes ``ansible_collections``, for example `collections/ansible_collections/`.
5353

@@ -66,19 +66,51 @@ It will create the structure ``[my_namespace]/[my_collection]/[collection skelet
6666

6767
.. hint:: If Git is used for version control, the corresponding repository should be initialized in the collection directory.
6868

69-
Once the skeleton exists, you can populate the directories with the content you want inside the collection. See `ansible-collections <https://github.com/ansible-collections/>`_ GitHub Org to get a better idea of what you can place inside a collection.
69+
Once the collection exists, you can populate the directories with the content you want inside the collection. See `ansible-collections <https://github.com/ansible-collections/>`_ GitHub Org to get a better idea of what you can place inside a collection.
7070

7171
Reference: the ``ansible-galaxy collection`` command
7272

7373
Currently the ``ansible-galaxy collection`` command implements the following sub commands:
7474

75-
* ``init``: Create a basic collection skeleton based on the default template included with Ansible or your own template.
75+
* ``init``: Create a basic collection based on the default template included with Ansible or your own template.
7676
* ``build``: Create a collection artifact that can be uploaded to Galaxy or your own repository.
7777
* ``publish``: Publish a built collection artifact to Galaxy.
7878
* ``install``: Install one or more collections.
7979

8080
To learn more about the ``ansible-galaxy`` command-line tool, see the :ref:`ansible-galaxy` man page.
8181

82+
.. _creating_collection_skeletons:
83+
84+
Creating a collection from a custom template
85+
============================================
86+
87+
The built-in collection template is a simple example of a collection that works with ``ansible-core``, but if you want to simplify your development process you may want to create a custom collection template to pass to ``ansible-galaxy collection init``.
88+
89+
A collection skeleton is a directory that looks like a collection directory but any ``.j2`` files (excluding those in ``templates/`` and ``roles/*/templates/``) will be templated by ``ansible-galaxy collection init``. The skeleton's ``galaxy.yml.j2`` file should use the variables ``namespace`` and ``collection_name`` which are derived from ``ansible-galaxy init namespace.collection_name``, and will populate the metadata in the initialized collection's ``galaxy.yml`` file. There are a few additional variables available by default (for example, ``version`` is ``1.0.0``), and these can be supplemented/overridden using ``--extra-vars``.
90+
91+
An example ``galaxy.yml.j2`` file that accepts an optional dictionary variable ``dependencies`` could look like this:
92+
93+
.. code-block:: yaml
94+
95+
namespace: {{ namespace }}
96+
name: {{ collection_name }}
97+
version: "{{ (version|quote) is version("0.0.0", operator="gt", version_type="semver")|ternary(version, undef("version must be a valid semantic version greater than 0.0.0")) }}"
98+
dependencies: {{ dependencies|default({}, true) }}
99+
100+
To initialize a collection using the new template, pass the path to the skeleton with ``ansible-galaxy collection init``:
101+
102+
.. code-block:: bash
103+
104+
ansible_collections#> ansible-galaxy collection init --collection-skeleton /path/to/my/namespace/skeleton --extra-vars "@my_vars_file.json" my_namespace.my_collection
105+
106+
.. note::
107+
108+
Before ``ansible-core`` 2.17, collection skeleton templating is limited to the few hardcoded variables including ``namespace``, ``collection_name``, and ``version``.
109+
110+
.. note::
111+
112+
The default collection skeleton uses an internal filter ``comment_ify`` that isn't accessibly to ``--collection-skeleton``. Use ``ansible-doc -t filter|test --list`` to see available plugins.
113+
82114
.. seealso::
83115

84116
:ref:`collections`

0 commit comments

Comments
 (0)