Browse code

[2.10] Docs Backportapalooza 7 (#71261)

* Fixes due to branch being renamed (#71115)
The ansible collection repository correctly renamed their default branch from `master` to `main`, which has caused a number for broken urls. This PR fixes those urls.

(cherry picked from commit fb9c9570d50792f66f47d4d8d3e9beba8a4a7780)

* Docs: Fix typo (#71119)

(cherry picked from commit cb9336ab6d3ec15a509c328ee89c7361104c59f3)

* remove network for 2.10 base porting guide (#71158)

(cherry picked from commit 56748a80609c5d402a8cf72c0a4396f87282957f)

* Updating Getting Started with Resources section #68962 (#71102)

* Updating Getting Started with Resources section #68962
* Add links, including Workshops URL #68962

(cherry picked from commit 5f8b45a70e8e4e378cdafde6cc6c39f32af39e65)

* start of 'data manipulation' examples (#46979)

Co-authored-by: Klaus Frank <agowa338@users.noreply.github.com>
Co-authored-by: Felix Fontein <felix@fontein.de>
Co-authored-by: Abhijeet Kasurde <akasurde@redhat.com>
(cherry picked from commit f46b124d656baa515455cd077595d1b1dfc93b38)

* toml: Clarify about inventory examples (#71180)

Add a note in toml inventory plugin about three different
inventory examples. Fixes: #67003

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
(cherry picked from commit edac065bd2ad3c613413c125cad3eee45e5f0835)

* filters: minor doc fix (#71178)

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
(cherry picked from commit 0a7ab396c7595d9a2ace341395e50e5116a0dd15)

* docs: 'ansible_play_hosts' lists active hosts, not limited by serial (#71116)

ansible_play_batch lists the currently targeted host(s) in the serial/batch, while
ansible_play_hosts lists all the hosts which will be targeted by the play.

(cherry picked from commit e72e12aa2747b9fb747775365588b67ec17832a9)

* Fix references to Ansible Collections Overview (#71227)

(cherry picked from commit 19589db10cdaf400bf7a2e214043c2c94a92cf9e)

* add another resource module example (#71162)

* Update docs/docsite/rst/network/user_guide/network_resource_modules.rst
Co-authored-by: Nilashish Chakraborty <nilashishchakraborty8@gmail.com>

(cherry picked from commit f4388de14dbdd422480c8bc4eb60b2cbf1889f92)

* Adds fest link (#71241)

(cherry picked from commit ae3b8eec1277f1cb75f131314d1eedc9ea059820)

* Update release page for ansible and ansible-base (#71229)

* [docs] 2.7 is EOL, add 2.10 which is almost out
- Remove 2.7 support from the maintenance schedule
- Add 2.10 which is in RC and will be out soon enough.
Signed-off-by: Rick Elrod <rick@elrod.me>

* Update docs/docsite/rst/reference_appendices/release_and_maintenance.rst, fix table and separate ansible-base from ansible, fix rstcheck errors, clean up sections, explain the two packages
Co-authored-by: Sandra McCann <samccann@redhat.com>
Co-authored-by: Rick Elrod <rick@elrod.me>

(cherry picked from commit 553ccedcd3a2292c2665768e5dc97f5e0ff0bb87)

Co-authored-by: Daniel Finneran <dan@thebsdbox.co.uk>
Co-authored-by: Liviu Chircu <liviu@opensips.org>
Co-authored-by: kshitijcode <ikshitijsharma@gmail.com>
Co-authored-by: Brian Coca <bcoca@users.noreply.github.com>
Co-authored-by: Abhijeet Kasurde <akasurde@redhat.com>
Co-authored-by: Håkon Solbjørg <hakon@solbj.org>
Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>
Co-authored-by: Alicia Cozine <879121+acozine@users.noreply.github.com>

Sandra McCann authored on 2020/08/14 02:23:46
Showing 17 changed files
... ...
@@ -12,13 +12,13 @@ Ansible's main goals are simplicity and ease-of-use. It also has a strong focus
12 12
 
13 13
 We believe simplicity is relevant to all sizes of environments, so we design for busy users of all types: developers, sysadmins, release engineers, IT managers, and everyone in between. Ansible is appropriate for managing all environments, from small setups with a handful of instances to enterprise environments with many thousands of instances.
14 14
 
15
-Ansible manages machines in an agent-less manner. There is never a question of how to
16
-upgrade remote daemons or the problem of not being able to manage systems because daemons are uninstalled.  Because OpenSSH is one of the most peer-reviewed open source components, security exposure is greatly reduced. Ansible is decentralized--it relies on your existing OS credentials to control access to remote machines. If needed, Ansible can easily connect with Kerberos, LDAP, and other centralized authentication management systems.
15
+You can learn more at `AnsibleFest <https://www.ansible.com/ansiblefest>`_, the annual event for all Ansible contributors, users, and customers hosted by Red Hat. AnsibleFest is the place to connect with others, learn new skills, and find a new friend to automate with.
17 16
 
18
-This documentation covers the version of Ansible noted in the upper left corner of this page. We maintain multiple versions of Ansible and of the documentation, so please be sure you are using the version of the documentation that covers the version of Ansible you're using. For recent features, we note the version of Ansible where the feature was added.
17
+Ansible manages machines in an agent-less manner. There is never a question of how to upgrade remote daemons or the problem of not being able to manage systems because daemons are uninstalled.  Because OpenSSH is one of the most peer-reviewed open source components, security exposure is greatly reduced. Ansible is decentralized--it relies on your existing OS credentials to control access to remote machines. If needed, Ansible can easily connect with Kerberos, LDAP, and other centralized authentication management systems.
19 18
 
20
-Ansible releases a new major release of Ansible approximately three to four times per year. The core application evolves somewhat conservatively, valuing simplicity in language design and setup. However, the community around new modules and plugins being developed and contributed moves very quickly, adding many new modules in each release.
19
+This documentation covers the version of Ansible noted in the upper left corner of this page. We maintain multiple versions of Ansible and of the documentation, so please be sure you are using the version of the documentation that covers the version of Ansible you're using. For recent features, we note the version of Ansible where the feature was added.
21 20
 
21
+Ansible releases a new major release of Ansible approximately three to four times per year. The core application evolves somewhat conservatively, valuing simplicity in language design and setup. Contributors develop and change modules and plugins, hosted in collections since version 2.10, much more quickly.
22 22
 
23 23
 .. toctree::
24 24
    :maxdepth: 2
... ...
@@ -150,6 +150,50 @@ The following playbook uses the :ref:`eos_l3_interfaces <eos_l3_interfaces_modul
150 150
     assert:
151 151
       that: not result.changed
152 152
 
153
+Example: Acquiring and updating VLANs on a network device
154
+==========================================================
155
+
156
+This example shows how you can use resource modules to:
157
+
158
+#. Retrieve the current configuration on a network device.
159
+#. Save that configuration locally.
160
+#. Update that configuration and apply it to the network device.
161
+
162
+This example uses the ``cisco.ios.ios_vlans`` resource module to retrieve and update the VLANs on an IOS device.
163
+
164
+1. Retrieve the current IOS VLAN configuration:
165
+
166
+.. code-block:: yaml
167
+
168
+  - name: Gather VLAN information as structured data
169
+    cisco.ios.ios_facts:
170
+       gather_subset:
171
+        - '!all'
172
+        - '!min'
173
+       gather_network_resources:
174
+       - 'vlans'
175
+
176
+2. Store the VLAN configuration locally:
177
+
178
+.. code-block:: yaml
179
+
180
+  - name: Store VLAN facts to host_vars
181
+    copy:
182
+      content: "{{ ansible_network_resources | to_nice_yaml }}"
183
+      dest: "{{ playbook_dir }}/host_vars/{{ inventory_hostname }}"
184
+
185
+3. Modify the stored file to update the VLAN configuration locally.
186
+
187
+4. Merge the updated VLAN configuration with the existing configuration on the device:
188
+
189
+.. code-block:: yaml
190
+
191
+  - name: Make VLAN config changes by updating stored facts on the controller.
192
+    cisco.ios.ios_vlans:
193
+      config: "{{ vlans }}"
194
+      state: merged
195
+    tags: update_config
196
+
153 197
 .. seealso::
154 198
 
155 199
   `Network Features in Ansible 2.9 <https://www.ansible.com/blog/network-features-coming-soon-in-ansible-engine-2.9>`_
... ...
@@ -9,7 +9,7 @@ Cliconf Plugins
9 9
 
10 10
 .. warning::
11 11
 
12
-	Links on this page may not point to the most recent versions of plugins. In preparation for the release of 2.10, many plugins and modules have migrated to Collections on  `Ansible Galaxy <https://galaxy.ansible.com>`_. For the current development status of Collections and FAQ see `Ansible Collections Community Guide <https://github.com/ansible-collections/general/blob/master/README.rst>`_.
12
+	Links on this page may not point to the most recent versions of plugins. In preparation for the release of 2.10, many plugins and modules have migrated to Collections on  `Ansible Galaxy <https://galaxy.ansible.com>`_. For the current development status of Collections and FAQ see `Ansible Collections Community Guide <https://github.com/ansible-collections/overview/blob/master/README.rst>`_.
13 13
 
14 14
 Cliconf plugins are abstractions over the CLI interface to network devices. They provide a standard interface
15 15
 for Ansible to execute tasks on those network devices.
... ...
@@ -9,7 +9,7 @@ Httpapi Plugins
9 9
 
10 10
 .. warning::
11 11
 
12
-	Links on this page may not point to the most recent versions of plugins. In preparation for the release of 2.10, many plugins and modules have migrated to Collections on  `Ansible Galaxy <https://galaxy.ansible.com>`_. For the current development status of Collections and FAQ see `Ansible Collections Community Guide <https://github.com/ansible-collections/general/blob/master/README.rst>`_.
12
+	Links on this page may not point to the most recent versions of plugins. In preparation for the release of 2.10, many plugins and modules have migrated to Collections on  `Ansible Galaxy <https://galaxy.ansible.com>`_. For the current development status of Collections and FAQ see `Ansible Collections Community Guide <https://github.com/ansible-collections/overview/blob/master/README.rst>`_.
13 13
 
14 14
 Httpapi plugins tell Ansible how to interact with a remote device's HTTP-based API and execute tasks on the
15 15
 device.
... ...
@@ -9,7 +9,7 @@ Netconf Plugins
9 9
 
10 10
 .. warning::
11 11
 
12
-	Links on this page may not point to the most recent versions of plugins. In preparation for the release of 2.10, many plugins and modules have migrated to Collections on  `Ansible Galaxy <https://galaxy.ansible.com>`_. For the current development status of Collections and FAQ see `Ansible Collections Community Guide <https://github.com/ansible-collections/general/blob/master/README.rst>`_.
12
+	Links on this page may not point to the most recent versions of plugins. In preparation for the release of 2.10, many plugins and modules have migrated to Collections on  `Ansible Galaxy <https://galaxy.ansible.com>`_. For the current development status of Collections and FAQ see `Ansible Collections Community Guide <https://github.com/ansible-collections/overview/blob/master/README.rst>`_.
13 13
 
14 14
 Netconf plugins are abstractions over the Netconf interface to network devices. They provide a standard interface for Ansible to execute tasks on those network devices.
15 15
 
... ...
@@ -152,9 +152,3 @@ Porting custom scripts
152 152
 ======================
153 153
 
154 154
 No notable changes
155
-
156
-
157
-Networking
158
-==========
159
-
160
-No notable changes
... ...
@@ -3,21 +3,21 @@
3 3
 Release and maintenance
4 4
 =======================
5 5
 
6
+This section describes the Ansible and ``ansible-base`` releases. Ansible is the package that most users install. ``ansible-base`` is primarily for developers.
7
+
6 8
 .. contents::
7 9
    :local:
8 10
 
9 11
 .. _release_cycle:
10 12
 
11
-Release cycle
12
-`````````````
13
+Ansible release cycle
14
+-----------------------
13 15
 
14
-Ansible is developed and released on a flexible six month release cycle.
16
+Ansible is developed and released on a flexible release cycle.
15 17
 This cycle can be extended in order to allow for larger changes to be properly
16
-implemented and tested before a new release is made available.
18
+implemented and tested before a new release is made available. See :ref:`roadmaps` for upcoming release details.
17 19
 
18
-Ansible has a graduated maintenance structure that extends to three major releases.
19
-For more information, read about the :ref:`development_and_stable_version_maintenance_workflow` or
20
-see the chart in :ref:`release_schedule` for the degrees to which current releases are maintained.
20
+For Ansible version 2.10 or later, the major release is maintained for one release cycle. When the next release comes out (for example, 2.11), the older release (2.10 in this example) is no longer maintained.
21 21
 
22 22
 If you are using a release of Ansible that is no longer maintained, we strongly
23 23
 encourage you to upgrade as soon as possible in order to benefit from the
... ...
@@ -27,34 +27,29 @@ Older, unmaintained versions of Ansible can contain unfixed security
27 27
 vulnerabilities (*CVE*).
28 28
 
29 29
 You can refer to the :ref:`porting guides<porting_guides>` for tips on updating your Ansible
30
-playbooks to run on newer versions.
30
+playbooks to run on newer versions. You can download the Ansible release from `<https://releases.ansible.com/ansible/>`_.
31 31
 
32
-.. _release_schedule:
33 32
 
34
-Release status
35
-``````````````
36
-This table links to the release notes for each major release. These release notes (changelogs) contain the dates and significant changes in each minor release.
37
-
38
-==============================      =================================================
39
-Ansible Release                     Status
40
-==============================      =================================================
41
-devel                               In development (2.10 unreleased, trunk)
42
-`2.9 Release Notes`_                Maintained (security **and** general bug fixes)
43
-`2.8 Release Notes`_                Maintained (security **and** critical bug fixes)
44
-`2.7 Release Notes`_                Maintained (security fixes)
45
-`2.6 Release Notes`_                Unmaintained (end of life)
46
-`2.5 Release Notes`_                Unmaintained (end of life)
47
-<2.5                                Unmaintained (end of life)
48
-==============================      =================================================
49
-
50
-You can download the releases from `<https://releases.ansible.com/ansible/>`_.
51
-
52
-.. note:: Ansible maintenance continues for 3 releases.  Thus the latest Ansible release receives
53
-    security and general bug fixes when it is first released, security and critical bug fixes when
54
-    the next Ansible version is released, and **only** security fixes once the follow on to that version is released.
33
+This table links to the release notes for each major Ansible release. These release notes (changelogs) contain the dates and significant changes in each minor release.
34
+
35
+==================================      =================================================
36
+Ansible Release                         Status
37
+==================================      =================================================
38
+devel                                   In development (2.11 unreleased, trunk)
39
+`2.10 Release Notes`_                   In development (2.10 alpha/beta)
40
+`2.9 Release Notes`_                    Maintained (security **and** general bug fixes)
41
+`2.8 Release Notes`_                    Maintained (security fixes)
42
+`2.7 Release Notes`_                    Unmaintained (end of life)
43
+`2.6 Release Notes`_                    Unmaintained (end of life)
44
+`2.5 Release Notes`_                    Unmaintained (end of life)
45
+<2.5                                    Unmaintained (end of life)
46
+==================================      =================================================
47
+
55 48
 
56 49
 .. Comment: devel used to point here but we're currently revamping our changelog process and have no
57 50
    link to a static changelog for devel _2.6: https://github.com/ansible/ansible/blob/devel/CHANGELOG.md
51
+.. _2.10 Release Notes:
52
+.. _2.10: https://github.com/ansible-community/ansible-build-data/blob/main/2.10/CHANGELOG-v2.10.rst
58 53
 .. _2.9 Release Notes:
59 54
 .. _2.9: https://github.com/ansible/ansible/blob/stable-2.9/changelogs/CHANGELOG-v2.9.rst
60 55
 .. _2.8 Release Notes:
... ...
@@ -64,28 +59,71 @@ You can download the releases from `<https://releases.ansible.com/ansible/>`_.
64 64
 .. _2.6: https://github.com/ansible/ansible/blob/stable-2.6/changelogs/CHANGELOG-v2.6.rst
65 65
 .. _2.5 Release Notes: https://github.com/ansible/ansible/blob/stable-2.5/changelogs/CHANGELOG-v2.5.rst
66 66
 
67
+
68
+ansible-base release cycle
69
+-------------------------------
70
+
71
+``ansible-base`` is developed and released on a flexible release cycle.
72
+This cycle can be extended in order to allow for larger changes to be properly
73
+implemented and tested before a new release is made available. See :ref:`roadmaps` for upcoming release details.
74
+
75
+``ansible-base`` has a graduated maintenance structure that extends to three major releases.
76
+For more information, read about the :ref:`development_and_stable_version_maintenance_workflow` or
77
+see the chart in :ref:`release_schedule` for the degrees to which current releases are maintained.
78
+
79
+If you are using a release of ``ansible-base`` that is no longer maintained, we strongly
80
+encourage you to upgrade as soon as possible in order to benefit from the
81
+latest features and security fixes.
82
+
83
+Older, unmaintained versions of ``ansible-base`` can contain unfixed security
84
+vulnerabilities (*CVE*).
85
+
86
+You can refer to the :ref:`porting guides<porting_guides>` for tips on updating your Ansible
87
+playbooks to run on newer versions.
88
+
89
+You can download the ``ansible-base`` release from `<https://releases.ansible.com/ansible/>`_.
90
+
91
+.. note:: ``ansible-base`` maintenance continues for 3 releases.  Thus the latest release receives
92
+    security and general bug fixes when it is first released, security and critical bug fixes when
93
+    the next ``ansible-base`` version is released, and **only** security fixes once the follow on to that version is released.
94
+
95
+
96
+.. _release_schedule:
97
+
98
+
99
+This table links to the release notes for each major ``ansible-base`` release. These release notes (changelogs) contain the dates and significant changes in each minor release.
100
+
101
+==================================      =================================================
102
+    ``ansible-base`` Release                         Status
103
+==================================      =================================================
104
+devel                                   In development (2.11 unreleased, trunk)
105
+`2.10 ansible-base Release Notes`_      Maintained (security **and** general bug fixes)
106
+==================================      =================================================
107
+
108
+
109
+.. _2.10 ansible-base Release Notes:
110
+.. _2.10-base: https://github.com/ansible/ansible/blob/stable-2.10/changelogs/CHANGELOG-v2.10.rst
67 111
 .. _support_life:
68 112
 .. _methods:
69 113
 
70 114
 .. _development_and_stable_version_maintenance_workflow:
71 115
 
72 116
 Development and stable version maintenance workflow
73
-```````````````````````````````````````````````````
117
+-----------------------------------------------------
74 118
 
75
-The Ansible community develops and maintains Ansible on GitHub_.
119
+The Ansible community develops and maintains Ansible and ``ansible-base`` on GitHub_.
76 120
 
77
-New modules, plugins, features and bugfixes will always be integrated in what will become the next
78
-major version of Ansible. This work is tracked on the ``devel`` git branch.
121
+Collection updates (new modules, plugins, features and bugfixes) will always be integrated in what will become the next version of Ansible. This work is tracked within the individual collection repositories.
79 122
 
80
-Ansible provides bugfixes and security improvements for the most recent major release. The previous
81
-major release will only receive fixes for security issues and critical bugs. Ansible only applies
123
+Ansible and ``ansible-base`` provide bugfixes and security improvements for the most recent major release. The previous
124
+major release of ``ansible-base`` will only receive fixes for security issues and critical bugs.``ansible-base`` only applies
82 125
 security fixes to releases which are two releases old. This work is tracked on the
83 126
 ``stable-<version>`` git branches.
84 127
 
85 128
 The fixes that land in maintained stable branches will eventually be released
86 129
 as a new version when necessary.
87 130
 
88
-Note that while there are no guarantees for providing fixes for Unmaintained
131
+Note that while there are no guarantees for providing fixes for unmaintained
89 132
 releases of Ansible, there can sometimes be exceptions for critical issues.
90 133
 
91 134
 .. _GitHub: https://github.com/ansible/ansible
... ...
@@ -93,25 +131,23 @@ releases of Ansible, there can sometimes be exceptions for critical issues.
93 93
 .. _release_changelogs:
94 94
 
95 95
 Changelogs
96
-~~~~~~~~~~
96
+^^^^^^^^^^^^
97 97
 
98
-Since Ansible 2.5, we have generated changelogs based on fragments. Here is the generated changelog for 2.9_ as an example. When creating new features or fixing bugs, create a changelog fragment describing the change. A changelog entry is not needed for new modules or plugins. Details for those items will be generated from the module documentation.
98
+We generate changelogs based on fragments. Here is the generated changelog for 2.9_ as an example. When creating new features or fixing bugs, create a changelog fragment describing the change. A changelog entry is not needed for new modules or plugins. Details for those items will be generated from the module documentation.
99 99
 
100 100
 We've got :ref:`examples and instructions on creating changelog fragments <changelogs_how_to>` in the Community Guide.
101 101
 
102
-Older versions logged changes in ``stable-<version>`` branches at ``stable-<version>/CHANGELOG.md``. For example, here is the changelog for `2.4 <https://github.com/ansible/ansible/blob/stable-2.4/CHANGELOG.md>`_ on GitHub.
103
-
104 102
 
105 103
 Release candidates
106
-~~~~~~~~~~~~~~~~~~
104
+^^^^^^^^^^^^^^^^^^^
107 105
 
108
-Before a new release or version of Ansible can be done, it will typically go
106
+Before a new release or version of Ansible or ``ansible-base`` can be done, it will typically go
109 107
 through a release candidate process.
110 108
 
111
-This provides the Ansible community the opportunity to test Ansible and report
109
+This provides the Ansible community the opportunity to test these releases and report
112 110
 bugs or issues they might come across.
113 111
 
114
-Ansible tags the first release candidate (``RC1``) which is usually scheduled
112
+Ansible and ``ansible-base`` tag the first release candidate (``RC1``) which is usually scheduled
115 113
 to last five business days. The final release is done if no major bugs or
116 114
 issues are identified during this period.
117 115
 
... ...
@@ -122,13 +158,13 @@ If no problems have been reported after two business days, the final release is
122 122
 done.
123 123
 
124 124
 More release candidates can be tagged as required, so long as there are
125
-bugs that the Ansible core maintainers consider should be fixed before the
125
+bugs that the Ansible  or ``ansible-base`` core maintainers consider should be fixed before the
126 126
 final release.
127 127
 
128 128
 .. _release_freezing:
129 129
 
130 130
 Feature freeze
131
-~~~~~~~~~~~~~~
131
+^^^^^^^^^^^^^^^
132 132
 
133 133
 While there is a pending release candidate, the focus of core developers and
134 134
 maintainers will on fixes towards the release candidate.
... ...
@@ -138,13 +174,21 @@ be delayed in order to allow the new release to be shipped as soon as possible.
138 138
 
139 139
 
140 140
 Deprecation Cycle
141
-`````````````````
141
+------------------
142 142
 
143 143
 Sometimes we need to remove a feature, normally in favor of a reimplementation that we hope does a better job.
144 144
 To do this we have a deprecation cycle. First we mark a feature as 'deprecated'. This is normally accompanied with warnings
145 145
 to the user as to why we deprecated it, what alternatives they should switch to and when (which version) we are scheduled
146 146
 to remove the feature permanently.
147 147
 
148
+Ansible deprecation cycle
149
+^^^^^^^^^^^^^^^^^^^^^^^^^
150
+
151
+Since Ansible is a package of individual collections, the deprecation cycle depends on the collection maintainers. We recommend the collection maintainers deprecate a feature in one Ansible major version and do not remove that feature for one year, or at least until the next major Ansible version. For example, deprecate the feature in 2.10.2, and do not remove the feature until 2.12.0.  Collections should use semantic versioning, such that the major collection version cannot be changed within an Ansible major version. Thus the removal should not happen before the next major Ansible release. This is up to each collection maintainer and cannot be guaranteed.
152
+
153
+ansible-base deprecation cycle
154
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
155
+
148 156
 The cycle is normally across 4 feature releases (2.x.y, where the x marks a feature release and the y a bugfix release),
149 157
 so the feature is normally removed in the 4th release after we announce the deprecation.
150 158
 For example, something deprecated in 2.7 will be removed in 2.11, assuming we don't jump to 3.x before that point.
... ...
@@ -51,7 +51,7 @@ ansible_play_batch
51 51
     List of active hosts in the current play run limited by the serial, aka 'batch'. Failed/Unreachable hosts are not considered 'active'.
52 52
 
53 53
 ansible_play_hosts
54
-    The same as ansible_play_batch
54
+    List of hosts in the current play run, not limited by the serial. Failed/Unreachable hosts are included in this list.
55 55
 
56 56
 ansible_play_hosts_all
57 57
     List of all the hosts that were targeted by the play
... ...
@@ -208,9 +208,9 @@ Dynamic Inventory Script
208 208
 
209 209
 The dynamic inventory script queries the Packet API for a list of hosts, and exposes it to Ansible so you can easily identify and act on Packet devices.
210 210
 
211
-You can find it in Ansible Community General Collection's git repo at `scripts/inventory/packet_net.py <https://raw.githubusercontent.com/ansible-collections/community.general/master/scripts/inventory/packet_net.py>`_.
211
+You can find it in Ansible Community General Collection's git repo at `scripts/inventory/packet_net.py <https://raw.githubusercontent.com/ansible-collections/community.general/main/scripts/inventory/packet_net.py>`_.
212 212
 
213
-The inventory script is configurable via a `ini file <https://raw.githubusercontent.com/ansible-collections/community.general/master/scripts/inventory/packet_net.ini>`_.
213
+The inventory script is configurable via a `ini file <https://raw.githubusercontent.com/ansible-collections/community.general/main/scripts/inventory/packet_net.ini>`_.
214 214
 
215 215
 If you want to use the inventory script, you must first export your Packet API token to a PACKET_API_TOKEN environment variable.
216 216
 
... ...
@@ -218,9 +218,9 @@ You can either copy the inventory and ini config out from the cloned git repo, o
218 218
 
219 219
 .. code-block:: bash
220 220
 
221
-    $ wget https://raw.githubusercontent.com/ansible-collections/community.general/master/scripts/inventory/packet_net.py
221
+    $ wget https://raw.githubusercontent.com/ansible-collections/community.general/main/scripts/inventory/packet_net.py
222 222
     $ chmod +x packet_net.py
223
-    $ wget https://raw.githubusercontent.com/ansible-collections/community.general/master/scripts/inventory/packet_net.ini
223
+    $ wget https://raw.githubusercontent.com/ansible-collections/community.general/main/scripts/inventory/packet_net.ini
224 224
 
225 225
 In order to understand what the inventory script gives to Ansible you can run:
226 226
 
... ...
@@ -10,7 +10,7 @@ Collections are a distribution format for Ansible content that can include playb
10 10
 You can install and use collections through `Ansible Galaxy <https://galaxy.ansible.com>`_.
11 11
 
12 12
 * For details on how to *develop* collections see :ref:`developing_collections`.
13
-* For the current development status of Collections and FAQ see `Ansible Collections Community Guide <https://github.com/ansible-collections/general/blob/master/README.rst>`_.
13
+* For the current development status of Collections and FAQ see `Ansible Collections Community Guide <https://github.com/ansible-collections/overview/blob/master/README.rst>`_.
14 14
 
15 15
 .. contents::
16 16
    :local:
17 17
new file mode 100644
... ...
@@ -0,0 +1,243 @@
0
+.. _complex_data_manipulation:
1
+
2
+Data manipulation
3
+#########################
4
+
5
+In many cases, you need to do some complex operation with your variables, while Ansible is not recommended as a data processing/manipulation tool, you can use the existing Jinja2 templating in conjunction with the many added Ansible filters, lookups and tests to do some very complex transformations.
6
+
7
+Let's start with a quick definition of each type of plugin:
8
+  - lookups: Mainly used to query 'external data', in Ansible these were the primary part of loops using the ``with_<lookup>`` construct, but they can be used independently to return data for processing. They normally return a list due to their primary function in loops as mentioned previously. Used with the ``lookup`` or ``query`` Jinja2 operators.
9
+  - filters: used to change/transform data, used with the ``|`` Jinja2 operator.
10
+  - tests: used to validate data, used with the ``is`` Jinja2 operator.
11
+
12
+.. _note:
13
+   * Some tests and filters are provided directly by Jinja2, so their availability depends on the Jinja2 version, not Ansible.
14
+
15
+.. _for_loops_or_list_comprehensions:
16
+
17
+Loops and list comprehensions
18
+=============================
19
+
20
+Most programming languages have loops (``for``, ``while``, etc.) and list comprehensions to do transformations on lists including lists of objects. Jinja2 has a few filters that provide this functionality: ``map``, ``select``, ``reject``, ``selectattr``, ``rejectattr``.
21
+
22
+- map: this is a basic for loop that just allows you to change every item in a list, using the 'attribute' keyword you can do the transformation based on attributes of the list elements.
23
+- select/reject: this is a for loop with a condition, that allows you to create a subset of a list that matches (or not) based on the result of the condition.
24
+- selectattr/rejectattr: very similar to the above but it uses a specific attribute of the list elements for the conditional statement.
25
+
26
+
27
+.. _keys_from_dict_matching_list:
28
+
29
+Extract keys from a dictionary matching elements from a list
30
+------------------------------------------------------------
31
+
32
+The Python equivalent code would be:
33
+
34
+.. code-block:: python
35
+
36
+    chains = [1, 2]
37
+    for chain in chains:
38
+        for config in chains_config[chain]['configs']:
39
+            print(config['type'])
40
+
41
+There are several ways to do it in Ansible, this is just one example:
42
+
43
+.. code-block:: YAML+Jinja
44
+ :emphasize-lines: 3
45
+ :caption: Way to extract matching keys from a list of dictionaries
46
+
47
+  tasks:
48
+    - name: Show extracted list of keys from a list of dictionaries
49
+      debug: msg="{{ chains | map('extract', chains_config) | map(attribute='configs') | flatten | map(attribute='type') | flatten }}"
50
+      vars:
51
+        chains: [1, 2]
52
+        chains_config:
53
+            1:
54
+                foo: bar
55
+                configs:
56
+                    - type: routed
57
+                      version: 0.1
58
+                    - type: bridged
59
+                      version: 0.2
60
+            2:
61
+                foo: baz
62
+                configs:
63
+                    - type: routed
64
+                      version: 1.0
65
+                    - type: bridged
66
+                      version: 1.1
67
+
68
+
69
+.. code-block:: ansible-output
70
+ :caption: Results of debug task, a list with the extracted keys
71
+
72
+    ok: [localhost] => {
73
+        "msg": [
74
+            "routed",
75
+            "bridged",
76
+            "routed",
77
+            "bridged"
78
+        ]
79
+    }
80
+
81
+
82
+.. _find_mount_point:
83
+
84
+Find mount point
85
+----------------
86
+
87
+In this case, we want to find the mount point for a given path across our machines, since we already collect mount facts, we can use the following:
88
+
89
+.. code-block:: YAML+Jinja
90
+ :caption: Use selectattr to filter mounts into list I can then sort and select the last from
91
+ :emphasize-lines: 7
92
+
93
+   - hosts: all
94
+     gather_facts: True
95
+     vars:
96
+        path: /var/lib/cache
97
+     tasks:
98
+     - name: The mount point for {{path}}, found using the Ansible mount facts, [-1] is the same as the 'last' filter
99
+       debug: msg="{{(ansible_facts.mounts | selectattr('mount', 'in', path) | list | sort(attribute='mount'))[-1]['mount']}}"
100
+
101
+
102
+
103
+Omit elements from a list
104
+-------------------------
105
+
106
+The special ``omit`` variable ONLY works with module options, but we can still use it in other ways as an identifier to tailor a list of elements:
107
+
108
+.. code-block:: YAML+Jinja
109
+ :caption: Inline list filtering when feeding a module option
110
+ :emphasize-lines: 3, 7
111
+
112
+    - name: enable a list of Windows features, by name
113
+      set_fact:
114
+        win_feature_list: "{{ namestuff | reject('equalto', omit) | list }}"
115
+      vars:
116
+        namestuff:
117
+          - "{{ (fs_installed_smb_v1 | default(False)) | ternary(omit, 'FS-SMB1') }}"
118
+          - "foo"
119
+          - "bar"
120
+
121
+
122
+Another way is to avoid adding elements to the list in the first place, so you can just use it directly:
123
+
124
+.. code-block:: YAML+Jinja
125
+ :caption: Using set_fact in a loop to increment a list conditionally
126
+ :emphasize-lines: 3, 4, 6
127
+
128
+    - name: build unique list with some items conditionally omittted
129
+      set_fact:
130
+         namestuff: ' {{ (namestuff | default([])) | union([item]) }}'
131
+      when: item != omit
132
+      loop:
133
+          - "{{ (fs_installed_smb_v1 | default(False)) | ternary(omit, 'FS-SMB1') }}"
134
+          - "foo"
135
+          - "bar"
136
+
137
+
138
+.. _complex_type_transfomations:
139
+
140
+Complex Type transformations
141
+=============================
142
+
143
+Jinja provides filters for simple data type transformations (``int``, ``bool``, etc), but when you want to transform data structures things are not as easy.
144
+You can use loops and list comprehensions as shown above to help, also other filters and lookups can be chained and leveraged to achieve more complex transformations.
145
+
146
+
147
+.. _create_dictionary_from_list:
148
+
149
+Create dictionary from list
150
+---------------------------
151
+
152
+In most languages it is easy to create a dictionary (a.k.a. map/associative array/hash etc.) from a list of pairs, in Ansible there are a couple of ways to do it and the best one for you might depend on the source of your data.
153
+
154
+
155
+These example produces ``{"a": "b", "c": "d"}``
156
+
157
+.. code-block:: YAML+Jinja
158
+ :caption: Simple list to dict by assuming the list is [key, value , key, value, ...]
159
+
160
+  vars:
161
+      single_list: [ 'a', 'b', 'c', 'd' ]
162
+      mydict: "{{ dict(single_list) | slice(2) | list }}"
163
+
164
+
165
+.. code-block:: YAML+Jinja
166
+ :caption: It is simpler when we have a list of pairs:
167
+
168
+  vars:
169
+      list_of_pairs: [ ['a', 'b'], ['c', 'd'] ]
170
+      mydict: "{{ dict(list_of_pairs) }}"
171
+
172
+Both end up being the same thing, with the ``slice(2) | list`` transforming ``single_list`` to the same structure as ``list_of_pairs``.
173
+
174
+
175
+
176
+A bit more complex, using ``set_fact`` and a ``loop`` to create/update a dictionary with key value pairs from 2 lists:
177
+
178
+.. code-block:: YAML+Jinja
179
+ :caption: Using set_fact to create a dictionary from a set of lists
180
+ :emphasize-lines: 3, 4
181
+
182
+     - name: Uses 'combine' to update the dictionary and 'zip' to make pairs of both lists
183
+       set_fact:
184
+         mydict: "{{ mydict | default({}) | combine({item[0]: item[1]}) }}"
185
+       loop: "{{ (keys | zip(values)) | list }}"
186
+       vars:
187
+         keys:
188
+           - foo
189
+           - var
190
+           - bar
191
+         values:
192
+           - a
193
+           - b
194
+           - c
195
+
196
+This results in ``{"foo": "a", "var": "b", "bar": "c"}``.
197
+
198
+
199
+You can even combine these simple examples with other filters and lookups to create a dictionary dynamically by matching patterns to variable names:
200
+
201
+.. code-block:: YAML+Jinja
202
+ :caption: Using 'vars' to define dictionary from a set of lists without needing a task
203
+
204
+    vars:
205
+        myvarnames: "{{ q('varnames', '^my') }}"
206
+        mydict: "{{ dict(myvarnames | zip(q('vars', *myvarnames))) }}"
207
+
208
+A quick explanation, since there is a lot to unpack from these two lines:
209
+
210
+ - The ``varnames`` lookup returns a list of variables that match "begin with ``my``".
211
+ - Then feeding the list from the previous step into the ``vars`` lookup to get the list of values.
212
+   The ``*`` is used to 'dereference the list' (a pythonism that works in Jinja), otherwise it would take the list as a single argument.
213
+ - Both lists get passed to the ``zip`` filter to pair them off into a unified list (key, value, key2, value2, ...).
214
+ - The dict function then takes this 'list of pairs' to create the dictionary.
215
+
216
+
217
+An example on how to use facts to find a host's data that meets condition X:
218
+
219
+
220
+.. code-block:: YAML+Jinja
221
+
222
+  vars:
223
+    uptime_of_host_most_recently_rebooted: "{{ansible_play_hosts_all | map('extract', hostvars, 'ansible_uptime_seconds') | sort | first}}"
224
+
225
+
226
+Using an example from @zoradache on reddit, to show the 'uptime in days/hours/minutes' (assumes facts where gathered).
227
+https://www.reddit.com/r/ansible/comments/gj5a93/trying_to_get_uptime_from_seconds/fqj2qr3/
228
+
229
+.. code-block:: YAML+Jinja
230
+
231
+ - debug:
232
+    msg: Timedelta {{ now() - now().fromtimestamp(now(fmt='%s') | int - ansible_uptime_seconds) }}
233
+
234
+
235
+.. seealso::
236
+
237
+   :doc:`playbooks_filters`
238
+       Jinja2 filters included with Ansible
239
+   :doc:`playbooks_tests`
240
+       Jinja2 tests included with Ansible
241
+   `Jinja2 Docs <http://jinja.pocoo.org/docs/>`_
242
+      Jinja2 documentation, includes lists for core filters and tests
... ...
@@ -109,6 +109,14 @@ You can read more about privilege escalation in :ref:`become`.
109 109
 
110 110
 Congratulations! You have contacted your nodes using Ansible. You used a basic inventory file and an ad-hoc command to direct Ansible to connect to specific remote nodes, copy a module file there and execute it, and return output. You have a fully working infrastructure.
111 111
 
112
+Resources
113
+=================================
114
+- `Product Demos <https://github.com/ansible/product-demos>`_
115
+- `Katakoda <https://katacoda.com/rhel-labs>`_
116
+- `Workshops <https://github.com/ansible/workshops>`_
117
+- `Ansible Examples <https://github.com/ansible/ansible-examples>`_
118
+- `Ansible Baseline <https://github.com/ansible/ansible-baseline>`_
119
+
112 120
 Next steps
113 121
 ==========
114 122
 Next you can read about more real-world cases in :ref:`intro_adhoc`,
... ...
@@ -104,6 +104,8 @@ You've anchored the value of ``version`` with the ``&my_version`` anchor, and re
104 104
 
105 105
    :ref:`playbooks_variables`
106 106
        All about variables
107
+   :doc:`complex_data_manipulation`
108
+       Doing complex data manipulation in Ansible
107 109
    `User Mailing List <https://groups.google.com/group/ansible-project>`_
108 110
        Have a question?  Stop by the google group!
109 111
    `irc.freenode.net <http://irc.freenode.net>`_
... ...
@@ -146,7 +146,7 @@ Transforming lists into dictionaries
146 146
 
147 147
 .. versionadded:: 2.7
148 148
 
149
-Use the ``items2dict``filter to transform a list into a dictionary, mapping the content into ``key: value`` pairs::
149
+Use the ``items2dict`` filter to transform a list into a dictionary, mapping the content into ``key: value`` pairs::
150 150
 
151 151
     {{ tags | items2dict }}
152 152
 
... ...
@@ -1532,7 +1532,7 @@ To get the root and extension of a path or file name (new in version 2.0)::
1532 1532
 The ``splitext`` filter returns a string. The individual components can be accessed by using the ``first`` and ``last`` filters::
1533 1533
 
1534 1534
     # with path == 'nginx.conf' the return would be 'nginx'
1535
-    {{ path | splitext | first }} 
1535
+    {{ path | splitext | first }}
1536 1536
 
1537 1537
     # with path == 'nginx.conf' the return would be 'conf'
1538 1538
     {{ path | splitext | last }}
... ...
@@ -130,7 +130,7 @@ When you use the ``roles`` option at the play level, Ansible treats the roles as
130 130
 
131 131
 - Any ``pre_tasks`` defined in the play.
132 132
 - Any handlers triggered by pre_tasks.
133
-- Each role listed in ``roles:``, in the order listed. Any role dependencies defined in the roles ``meta/main.yml`` run first, subject to tag filtering and conditionals. See :ref:`role_dependencies` for more details.
133
+- Each role listed in ``roles:``, in the order listed. Any role dependencies defined in the role's ``meta/main.yml`` run first, subject to tag filtering and conditionals. See :ref:`role_dependencies` for more details.
134 134
 - Any ``tasks`` defined in the play.
135 135
 - Any handlers triggered by the roles or tasks.
136 136
 - Any ``post_tasks`` defined in the play.
... ...
@@ -16,6 +16,7 @@ As you write more playbooks and roles, you might have some special use cases. Fo
16 16
    playbooks_environment
17 17
    playbooks_error_handling
18 18
    playbooks_advanced_syntax
19
+   complex_data_manipulation
19 20
    ../plugins/plugins
20 21
    playbooks_prompts
21 22
    playbooks_tags
... ...
@@ -4,7 +4,7 @@
4 4
 from __future__ import (absolute_import, division, print_function)
5 5
 __metaclass__ = type
6 6
 
7
-DOCUMENTATION = '''
7
+DOCUMENTATION = r'''
8 8
     inventory: toml
9 9
     version_added: "2.8"
10 10
     short_description: Uses a specific TOML file as an inventory source.
... ...
@@ -15,7 +15,8 @@ DOCUMENTATION = '''
15 15
         - Requires the 'toml' python library
16 16
 '''
17 17
 
18
-EXAMPLES = '''
18
+EXAMPLES = r'''
19
+# Following are examples of 3 different inventories in TOML format
19 20
 example1: |
20 21
     [all.vars]
21 22
     has_java = false