Set module metadata.json default values

You can set metadata.json values for each module you create when you run the pdk new module command. You can also configure PDK to set metadata.json default values for all modules you create. This is helpful for values that are the same for all modules, commonly template-url, author, and license.

About module default metadata.json values

The files that store metadata.json defaults are created when you set metadata.json default values set using available metadata.json keys or custom metadata.json keys.

PDK uses two scopes for metadata.json settings: user scope and system scope. User scope applies to a single user, and system scope applies to every user on the system where PDK is installed. User scope takes precedence over system scope.

The values are stored in the following files:

  • user.module_defaults.* are in ~/.pdk/cache/answers.json

  • system.module_defaults.* are in /opt/puppetlabs/pdk/config/answers.json

Examples

  • A user-scoped template-url value:

    Copy
    {
      "template-url": "https://github.com/puppetlabs/pdk-templates",
      "author": "William Joe Bloggs"
    }
  • A system-scoped author value:

    Copy
    {
      "author": "Joe Blogs"
    }

View module metadata.json values

To view metadata.json values, you can either directly open and view values in files or run the pdk get config command. Viewing files directly is easier if you're checking many values. Using the command is easier if you don't want to look up the location of the files where values are set.

View values for user scope in ~/.pdk/cache/answers.json and system scope in opt/puppetlabs/pdk/config/answers.json.

Example pdk get config output

Copy
system.module_defaults.author=Joe Blogs            # <== system scoped "author"
user.module_defaults.author=William Joe Bloggs     # <== user scoped "author"
user.module_defaults.template-url=https://github.com/puppetlabs/pdk-templates

In this example, running pdk new module uses William Joe Bloggs as the metadata.json default, because user scope takes precedence over system scope. However, if you remove the user.module_defaults.author setting, PDK uses the system default, Joe Bloggs.

Set module metadata.json default values

To set metadata.json values, you can either open and directly edit files or run the pdk set config command. You can set available metadata.json keys or custom metadata.json keys with either method. Editing files directly is easier if you're updating many values, and using the command is easier if you don't want to look up the location of the files where values are set.

Set values for user scope in ~/.pdk/cache/answers.json and system scope in opt/puppetlabs/pdk/config/answers.json.

Examples: Common values set with pdk set config

The following examples are user-scoped values. To set system-scoped values, replace user with system.

Template configuration - determining module structure and files

  • Copy
    pdk set config user.module_defaults.template-url "https://github.com/your-org/pdk-template"
  • Copy
    pdk set config user.module_defaults.template-ref "main"

Author and contact information

  • Copy
    pdk set config user.module_defaults.author "Your Full Name"
  • Copy
    pdk set config user.module_defaults.forge_username "your-puppet-forge-username"

Legal and source information

  • Copy
    pdk set config user.module_defaults.license "Apache-2.0"
  • Copy
    pdk set config user.module_defaults.source "https://github.com/your-org/puppet-modulename"
  • Copy
    pdk set config user.module_defaults.project_page "https://github.com/your-org/puppet-modulename"
  • Copy
    pdk set config user.module_defaults.issues_url https://github.com/your-org/puppet-modulename/issues

Description defaults

  • Copy
    pdk set config user.module_defaults.summary "A Puppet module for managing something"
  • Copy
    pdk set config user.module_defaults.version "0.1.0"

Example: Value set directly in the file

System-scoped value set in /opt/puppetlabs/pdk/config/answers.json:

Copy
{
  "template-url": "https://github.com/your-org/pdk-template",
  "template-ref": "main",
  "author": "Your Full Name",
  "license": "Apache-2.0",
  "forge_username": "your-puppet-forge-username"
}

Create custom metadata.json keys

In most cases, existing available metadata.json keys are sufficient. However, if needed, you can also create and custom metadata.json keys using the pdk set config command and set default metadata.json values using steps in Set module metadata.json default values.

Custom metadata.json keys and values are stored in the following locations:

  • Custom user scope values: ~/.config/pdk/user_config.json

  • Custom system scope values: /opt/puppetlabs/pdk/config/system_config.json

Example custom metadata.json commands

  • Copy
    pdk set config user.my_custom "my_value"
  • Copy
    pdk set config system.my_custom "my_value"