Merge ~raharper/cloud-init:fix/merge-how-docs into cloud-init:master

Proposed by Ryan Harper
Status: Merged
Approved by: Dan Watkins
Approved revision: 8b5381195ce394c0a6b99121207816e29ee6bb72
Merge reported by: Server Team CI bot
Merged at revision: not available
Proposed branch: ~raharper/cloud-init:fix/merge-how-docs
Merge into: cloud-init:master
Diff against target: 138 lines (+84/-6)
1 file modified
doc/rtd/topics/merging.rst (+84/-6)
Reviewer Review Type Date Requested Status
Dan Watkins Approve
Server Team CI bot continuous-integration Approve
Review via email: mp+362083@code.launchpad.net

Commit message

doc: update merging doc with fixes and some additional details/examples

Update config merging documentation with cloud-config syntax fix. Add an
example showing how to merge two files with runcmd.

To post a comment you must log in.
Revision history for this message
Scott Moser (smoser) wrote :

A doc reference to the tools/ccfg-merge-debug might be useful (probably that could use some improvements too)

Revision history for this message
Ryan Harper (raharper) wrote :

I'll look at the tool/ccfg-merge-debug; but it didn't look immediately helpful, so I ended up launching an lxd container with two files in /etc/cloud/cloud.cfg.d/ and using cloud-init clean --logs --reboot instead.

I'll take a second look at the tool.

Revision history for this message
Server Team CI bot (server-team-bot) wrote :

PASSED: Continuous integration, rev:8429b81e62c2fce1bd9dfae1420e261c02e6f9e5
https://jenkins.ubuntu.com/server/job/cloud-init-ci/528/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Unit & Style Tests
    SUCCESS: Ubuntu LTS: Build
    SUCCESS: Ubuntu LTS: Integration
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/528/rebuild

review: Approve (continuous-integration)
8b53811... by Ryan Harper

doc: add docs on built-in mergers and their options.

Revision history for this message
Ryan Harper (raharper) wrote :

% PYTHONPATH=`pwd` ./tools/ccfg-merge-debug wark/10-runcmd.cfg wark/20-runcmd.cfg --verbose -o merged.cfg
2019-01-22 19:00:48,677 - helpers.py[WARNING]: No per instance data available, is there an datasource/iid set?
2019-01-22 19:00:48,677 - __init__.py[WARNING]: Unhandled non-multipart (text/x-not-multipart) userdata: 'runcmd:...'
2019-01-22 19:00:48,677 - __init__.py[WARNING]: Unhandled non-multipart (text/x-not-multipart) userdata: 'runcmd:...'
2019-01-22 19:00:48,677 - util.py[WARNING]: Failed calling handler CloudConfigPartHandler: [['text/cloud-config', 'text/cloud-config-jsonp']] (__end__, None, 3) with frequency once-per-instance

It needs some fixing.

Revision history for this message
Server Team CI bot (server-team-bot) wrote :

PASSED: Continuous integration, rev:8b5381195ce394c0a6b99121207816e29ee6bb72
https://jenkins.ubuntu.com/server/job/cloud-init-ci/529/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Unit & Style Tests
    SUCCESS: Ubuntu LTS: Build
    SUCCESS: Ubuntu LTS: Integration
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/529/rebuild

review: Approve (continuous-integration)
Revision history for this message
Dan Watkins (oddbloke) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/doc/rtd/topics/merging.rst b/doc/rtd/topics/merging.rst
index c75ca59..5f7ca18 100644
--- a/doc/rtd/topics/merging.rst
+++ b/doc/rtd/topics/merging.rst
@@ -21,12 +21,12 @@ For example.
21.. code-block:: yaml21.. code-block:: yaml
2222
23 #cloud-config (1)23 #cloud-config (1)
24 run_cmd:24 runcmd:
25 - bash125 - bash1
26 - bash226 - bash2
2727
28 #cloud-config (2)28 #cloud-config (2)
29 run_cmd:29 runcmd:
30 - bash330 - bash3
31 - bash431 - bash4
3232
@@ -36,7 +36,7 @@ cloud-config object that contains the following.
36.. code-block:: yaml36.. code-block:: yaml
3737
38 #cloud-config (merged)38 #cloud-config (merged)
39 run_cmd:39 runcmd:
40 - bash340 - bash3
41 - bash441 - bash4
4242
@@ -45,7 +45,7 @@ Typically this is not what users want; instead they would likely prefer:
45.. code-block:: yaml45.. code-block:: yaml
4646
47 #cloud-config (merged)47 #cloud-config (merged)
48 run_cmd:48 runcmd:
49 - bash149 - bash1
50 - bash250 - bash2
51 - bash351 - bash3
@@ -55,6 +55,45 @@ This way makes it easier to combine the various cloud-config objects you have
55into a more useful list, thus reducing duplication necessary to accomplish the55into a more useful list, thus reducing duplication necessary to accomplish the
56same result with the previous method.56same result with the previous method.
5757
58
59Built-in Mergers
60================
61
62Cloud-init provides merging for the following built-in types:
63
64- Dict
65- List
66- String
67
68The ``Dict`` merger has the following options which control what is done with
69values contained within the config.
70
71- ``allow_delete``: Existing values not present in the new value can be deleted, defaults to False
72- ``no_replace``: Do not replace an existing value if one is already present, enabled by default.
73- ``replace``: Overwrite existing values with new ones.
74
75The ``List`` merger has the following options which control what is done with
76the values contained within the config.
77
78- ``append``: Add new value to the end of the list, defaults to False.
79- ``prepend``: Add new values to the start of the list, defaults to False.
80- ``no_replace``: Do not replace an existing value if one is already present, enabled by default.
81- ``replace``: Overwrite existing values with new ones.
82
83The ``Str`` merger has the following options which control what is done with
84the values contained within the config.
85
86- ``append``: Add new value to the end of the string, defaults to False.
87
88Common options for all merge types which control how recursive merging is
89done on other types.
90
91- ``recurse_dict``: If True merge the new values of the dictionary, defaults to True.
92- ``recurse_list``: If True merge the new values of the list, defaults to False.
93- ``recurse_array``: Alias for ``recurse_list``.
94- ``recurse_str``: If True merge the new values of the string, defaults to False.
95
96
58Customizability97Customizability
59===============98===============
6099
@@ -164,8 +203,8 @@ string format (i.e. the second option above), for example:
164203
165.. code-block:: python204.. code-block:: python
166205
167 {'merge_how': [{'name': 'list', 'settings': ['extend']},206 {'merge_how': [{'name': 'list', 'settings': ['append']},
168 {'name': 'dict', 'settings': []},207 {'name': 'dict', 'settings': ['no_replace', 'recurse_list']},
169 {'name': 'str', 'settings': ['append']}]}208 {'name': 'str', 'settings': ['append']}]}
170209
171This would be the equivalent format for default string format but in dictionary210This would be the equivalent format for default string format but in dictionary
@@ -201,4 +240,43 @@ Note, however, that merge algorithms are not used *across* types of
201configuration. As was the case before merging was implemented,240configuration. As was the case before merging was implemented,
202user-data will overwrite conf.d configuration without merging.241user-data will overwrite conf.d configuration without merging.
203242
243Example cloud-config
244====================
245
246A common request is to include multiple ``runcmd`` directives in different
247files and merge all of the commands together. To achieve this, we must modify
248the default merging to allow for dictionaries to join list values.
249
250
251The first config
252
253.. code-block:: yaml
254
255 #cloud-config
256 merge_how:
257 - name: list
258 settings: [append]
259 - name: dict
260 settings: [no_replace, recurse_list]
261
262 runcmd:
263 - bash1
264 - bash2
265
266The second config
267
268.. code-block:: yaml
269
270 #cloud-config
271 merge_how:
272 - name: list
273 settings: [append]
274 - name: dict
275 settings: [no_replace, recurse_list]
276
277 runcmd:
278 - bash3
279 - bash4
280
281
204.. vi: textwidth=78282.. vi: textwidth=78

Subscribers

People subscribed via source and target branches