summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Harper <ryan.harper@canonical.com>2019-02-22 09:56:03 +0000
committerServer Team CI Bot <josh.powers+server-team-bot@canonical.com>2019-02-22 09:56:03 +0000
commit79d40e6b7bce33af69572c6054b3398b8d8077c7 (patch)
tree56ba6593aa99a0d6d0b00616f65889a3dcc8771a
parente7a8f81e6eee390ce6920df053bf7467b5e4dbd7 (diff)
downloadvyos-cloud-init-79d40e6b7bce33af69572c6054b3398b8d8077c7.tar.gz
vyos-cloud-init-79d40e6b7bce33af69572c6054b3398b8d8077c7.zip
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.
-rw-r--r--doc/rtd/topics/merging.rst90
1 files changed, 84 insertions, 6 deletions
diff --git a/doc/rtd/topics/merging.rst b/doc/rtd/topics/merging.rst
index c75ca59c..5f7ca18d 100644
--- a/doc/rtd/topics/merging.rst
+++ b/doc/rtd/topics/merging.rst
@@ -21,12 +21,12 @@ For example.
.. code-block:: yaml
#cloud-config (1)
- run_cmd:
+ runcmd:
- bash1
- bash2
#cloud-config (2)
- run_cmd:
+ runcmd:
- bash3
- bash4
@@ -36,7 +36,7 @@ cloud-config object that contains the following.
.. code-block:: yaml
#cloud-config (merged)
- run_cmd:
+ runcmd:
- bash3
- bash4
@@ -45,7 +45,7 @@ Typically this is not what users want; instead they would likely prefer:
.. code-block:: yaml
#cloud-config (merged)
- run_cmd:
+ runcmd:
- bash1
- bash2
- bash3
@@ -55,6 +55,45 @@ This way makes it easier to combine the various cloud-config objects you have
into a more useful list, thus reducing duplication necessary to accomplish the
same result with the previous method.
+
+Built-in Mergers
+================
+
+Cloud-init provides merging for the following built-in types:
+
+- Dict
+- List
+- String
+
+The ``Dict`` merger has the following options which control what is done with
+values contained within the config.
+
+- ``allow_delete``: Existing values not present in the new value can be deleted, defaults to False
+- ``no_replace``: Do not replace an existing value if one is already present, enabled by default.
+- ``replace``: Overwrite existing values with new ones.
+
+The ``List`` merger has the following options which control what is done with
+the values contained within the config.
+
+- ``append``: Add new value to the end of the list, defaults to False.
+- ``prepend``: Add new values to the start of the list, defaults to False.
+- ``no_replace``: Do not replace an existing value if one is already present, enabled by default.
+- ``replace``: Overwrite existing values with new ones.
+
+The ``Str`` merger has the following options which control what is done with
+the values contained within the config.
+
+- ``append``: Add new value to the end of the string, defaults to False.
+
+Common options for all merge types which control how recursive merging is
+done on other types.
+
+- ``recurse_dict``: If True merge the new values of the dictionary, defaults to True.
+- ``recurse_list``: If True merge the new values of the list, defaults to False.
+- ``recurse_array``: Alias for ``recurse_list``.
+- ``recurse_str``: If True merge the new values of the string, defaults to False.
+
+
Customizability
===============
@@ -164,8 +203,8 @@ string format (i.e. the second option above), for example:
.. code-block:: python
- {'merge_how': [{'name': 'list', 'settings': ['extend']},
- {'name': 'dict', 'settings': []},
+ {'merge_how': [{'name': 'list', 'settings': ['append']},
+ {'name': 'dict', 'settings': ['no_replace', 'recurse_list']},
{'name': 'str', 'settings': ['append']}]}
This 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
configuration. As was the case before merging was implemented,
user-data will overwrite conf.d configuration without merging.
+Example cloud-config
+====================
+
+A common request is to include multiple ``runcmd`` directives in different
+files and merge all of the commands together. To achieve this, we must modify
+the default merging to allow for dictionaries to join list values.
+
+
+The first config
+
+.. code-block:: yaml
+
+ #cloud-config
+ merge_how:
+ - name: list
+ settings: [append]
+ - name: dict
+ settings: [no_replace, recurse_list]
+
+ runcmd:
+ - bash1
+ - bash2
+
+The second config
+
+.. code-block:: yaml
+
+ #cloud-config
+ merge_how:
+ - name: list
+ settings: [append]
+ - name: dict
+ settings: [no_replace, recurse_list]
+
+ runcmd:
+ - bash3
+ - bash4
+
+
.. vi: textwidth=78