Populating Config Values with Commands


Commands are an important part of the
Replicated ecosystem for bootstrapping a configuration screen to help streamline the
installation of your application on-premise.

Important concepts to understand when using cmds:

  • cmds ONLY RUNS AT YAML IMPORT TIME (during app installation & during app updates).
  • cmds are computed, meaning they can not be templated with the {{repl }} template functions.
  • cmds need to be “defined” in your yaml to be used by configuration options.
  • cmds are called in a configuration option in one of 3 ways:
    • value_cmd
    • default_cmd
    • data_cmd
  • If called via value_cmd or data_cmd the initial value/data will persist through updates, restarts etc (just as it would be if the customer input that value into the settings screen themselves).
  • If called from default_cmd this value will be recalculated every time the app is updated or installed.

Example App:

  • I want a user to be able to specify a hostname but would like it to default to its public ip address.
  • I want to generate a default random admin password for my application.

Step 1: Define my cmds.

  - name: host_ip
    cmd: get_my_public_ip_address
    args: []
  - name: generate_random_password_32_char
    cmd: random
      - "32"

Step 2: Call my commands from config section.

- name: App
  title: App Configuration
  description: Set default values for my App to Use
  - name: hostname
    title: Hostname
    type: text
      name: get_my_public_ip_address
      value_at: 0
    required: true
  - name: admin_pw
    title: Admin User Password
    type: text
      name: generate_random_password_32_char
      value_at: 0
    required: true

Download Full Replicated YAML Example.

Kubernetes: Optional embedded Database
Docker Swarm: Optional Embedded Database
Persisting command-generated config values across application versions