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
1diff --git a/doc/rtd/topics/merging.rst b/doc/rtd/topics/merging.rst
2index c75ca59..5f7ca18 100644
3--- a/doc/rtd/topics/merging.rst
4+++ b/doc/rtd/topics/merging.rst
5@@ -21,12 +21,12 @@ For example.
6 .. code-block:: yaml
7
8 #cloud-config (1)
9- run_cmd:
10+ runcmd:
11 - bash1
12 - bash2
13
14 #cloud-config (2)
15- run_cmd:
16+ runcmd:
17 - bash3
18 - bash4
19
20@@ -36,7 +36,7 @@ cloud-config object that contains the following.
21 .. code-block:: yaml
22
23 #cloud-config (merged)
24- run_cmd:
25+ runcmd:
26 - bash3
27 - bash4
28
29@@ -45,7 +45,7 @@ Typically this is not what users want; instead they would likely prefer:
30 .. code-block:: yaml
31
32 #cloud-config (merged)
33- run_cmd:
34+ runcmd:
35 - bash1
36 - bash2
37 - bash3
38@@ -55,6 +55,45 @@ This way makes it easier to combine the various cloud-config objects you have
39 into a more useful list, thus reducing duplication necessary to accomplish the
40 same result with the previous method.
41
42+
43+Built-in Mergers
44+================
45+
46+Cloud-init provides merging for the following built-in types:
47+
48+- Dict
49+- List
50+- String
51+
52+The ``Dict`` merger has the following options which control what is done with
53+values contained within the config.
54+
55+- ``allow_delete``: Existing values not present in the new value can be deleted, defaults to False
56+- ``no_replace``: Do not replace an existing value if one is already present, enabled by default.
57+- ``replace``: Overwrite existing values with new ones.
58+
59+The ``List`` merger has the following options which control what is done with
60+the values contained within the config.
61+
62+- ``append``: Add new value to the end of the list, defaults to False.
63+- ``prepend``: Add new values to the start of the list, defaults to False.
64+- ``no_replace``: Do not replace an existing value if one is already present, enabled by default.
65+- ``replace``: Overwrite existing values with new ones.
66+
67+The ``Str`` merger has the following options which control what is done with
68+the values contained within the config.
69+
70+- ``append``: Add new value to the end of the string, defaults to False.
71+
72+Common options for all merge types which control how recursive merging is
73+done on other types.
74+
75+- ``recurse_dict``: If True merge the new values of the dictionary, defaults to True.
76+- ``recurse_list``: If True merge the new values of the list, defaults to False.
77+- ``recurse_array``: Alias for ``recurse_list``.
78+- ``recurse_str``: If True merge the new values of the string, defaults to False.
79+
80+
81 Customizability
82 ===============
83
84@@ -164,8 +203,8 @@ string format (i.e. the second option above), for example:
85
86 .. code-block:: python
87
88- {'merge_how': [{'name': 'list', 'settings': ['extend']},
89- {'name': 'dict', 'settings': []},
90+ {'merge_how': [{'name': 'list', 'settings': ['append']},
91+ {'name': 'dict', 'settings': ['no_replace', 'recurse_list']},
92 {'name': 'str', 'settings': ['append']}]}
93
94 This would be the equivalent format for default string format but in dictionary
95@@ -201,4 +240,43 @@ Note, however, that merge algorithms are not used *across* types of
96 configuration. As was the case before merging was implemented,
97 user-data will overwrite conf.d configuration without merging.
98
99+Example cloud-config
100+====================
101+
102+A common request is to include multiple ``runcmd`` directives in different
103+files and merge all of the commands together. To achieve this, we must modify
104+the default merging to allow for dictionaries to join list values.
105+
106+
107+The first config
108+
109+.. code-block:: yaml
110+
111+ #cloud-config
112+ merge_how:
113+ - name: list
114+ settings: [append]
115+ - name: dict
116+ settings: [no_replace, recurse_list]
117+
118+ runcmd:
119+ - bash1
120+ - bash2
121+
122+The second config
123+
124+.. code-block:: yaml
125+
126+ #cloud-config
127+ merge_how:
128+ - name: list
129+ settings: [append]
130+ - name: dict
131+ settings: [no_replace, recurse_list]
132+
133+ runcmd:
134+ - bash3
135+ - bash4
136+
137+
138 .. vi: textwidth=78

Subscribers

People subscribed via source and target branches