Skip to content

Instantly share code, notes, and snippets.

@beechtom
Last active January 22, 2020 23:07
Show Gist options
  • Save beechtom/f7b758893796d61a23c8ab868cf8b062 to your computer and use it in GitHub Desktop.
Save beechtom/f7b758893796d61a23c8ab868cf8b062 to your computer and use it in GitHub Desktop.
Bolt Config merging

plugin_hooks

Method

Shallow merge

Reason

Bolt already shallow merges plugin_hooks in a few locations. [1, 2, 3, 4]

Example

Global config:

plugin_hooks:
  foo:
    key1: value1
   bar:
    key1: value1

Local config:

plugin_hooks:
  foo:
    key2: value2

Resolved config:

plugin_hooks:
  foo:
    key2: value2
  bar:
    key1: value1

puppetfile

Method

Overwrite

Reason

The puppetfile config option is a hash that points to proxy servers and a Forge host. I'm not sure there would be an instance where only one of these would need to be changed on a per-user or per-project basis.

puppetfile:
  proxy: <proxy>
  forge:
    proxy: <proxy>
    baseurl: <baseurl>

log

Method

Shallow merge

Reason

It makes sense to preserve log configuration set at a global or user-level while allowing for further configuration at the user or project-level. Since the hash for this option only has the level and append keys, I don't think there's any reason to do a deep merge.

Example

Global config:

log:
  console:
    level: info

Local config:

log:
  ~/.puppetlabs/bolt/logfile.log:
    level: debug
    append: false

Project config:

log:
  ~/.puppetlabs/bolt/logfile.log:
    level: warn

Resolved config:

log:
  console:
    level: notice
  ~/.puppetlabs/bolt/logfile.log:
    level: warn

plugins

Method

Shallow merge individual plugins

Reason

Deep merging would be inappropriate, as plugin config can have hash values that shouldn't be merged. For example, the Vault plugin has an auth field that has different fields depending on which auth method is used.

Global config:

vault:
  auth:
    method: userpass
    user: <user>
    pass: <password>

Local config:

vault:
  auth:
    method: token
    token: <token>

Resolved config:

vault:
  auth:
    method: token
    user: <user>
    pass: <password>
    token: <token>

In this instance, a deep merge is undesirable. However, doing a shallow merge for each plugin's config would allow for setting certain values (such as a Vault server URL) at the global level, while allowing a user to add onto their config (such as setting their Vault credentials) at the local level.

Example

Global config:

plugins:
  vault:
    server_url: <server_url>
    cacert: <path_to_cert>

Local config:

plugins:
  vault:
    auth:
      method: userpass
      user: <user>
      pass: <password>

Resolved config:

plugins:
  vault:
    server_url: <server_url>
    cacert: <path_to_cert>
    auth:
      method: userpass
      user: <user>
      pass: <password>

Transport config

Method

Deep merge

Reason

Bolt already performs a deep merge on transport config. [1, 2]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment