You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/docsite/rst/dev_guide/developing_collections_creating.rst
+38-6Lines changed: 38 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ Creating collections
6
6
7
7
To create a collection:
8
8
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.
10
10
#. Add modules and other content to the collection.
11
11
#. Build the collection into a collection artifact with :ref:`ansible-galaxy collection build<building_collections>`.
12
12
#. Publish the collection artifact to Galaxy with :ref:`ansible-galaxy collection publish<publishing_collections>`.
@@ -44,10 +44,10 @@ There are a few special namespaces:
44
44
45
45
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.
46
46
47
-
.. _creating_collections_skeleton:
47
+
.. _creating_new_collections:
48
48
49
-
Creating a collection skeleton
50
-
==============================
49
+
Creating a new collection
50
+
=========================
51
51
52
52
Create your collection skeleton in a path that includes ``ansible_collections``, for example `collections/ansible_collections/`.
53
53
@@ -66,19 +66,51 @@ It will create the structure ``[my_namespace]/[my_collection]/[collection skelet
66
66
67
67
.. hint:: If Git is used for version control, the corresponding repository should be initialized in the collection directory.
68
68
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.
70
70
71
71
Reference: the ``ansible-galaxy collection`` command
72
72
73
73
Currently the ``ansible-galaxy collection`` command implements the following sub commands:
74
74
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.
76
76
* ``build``: Create a collection artifact that can be uploaded to Galaxy or your own repository.
77
77
* ``publish``: Publish a built collection artifact to Galaxy.
78
78
* ``install``: Install one or more collections.
79
79
80
80
To learn more about the ``ansible-galaxy`` command-line tool, see the :ref:`ansible-galaxy` man page.
81
81
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")) }}"
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.
0 commit comments