What do the &,<<, * mean in this database.yml file?

Viewed 55629

Up until now I have only used database.yml with each parameter called out explicitly, in the file below it uses some characters I do not understand. What does each line and symbol(&, *, <<) mean? How do I read this file?

development: &default
  adapter: postgresql
  database: dev_development

test: &test
  <<: *default
  database: test_test


cucumber:
  <<: *test

production:
  <<: *default
  database: test_production
5 Answers

In simple words, this notion resembles with the base and derived class.

In base class template, you mention all the common details with '&', which means it can be used to expand the other yaml section that needs these fields. Now when you create another section that is superset of config values of this 'base class' type structure, you use the '*' along with the base class anchor (i.e. the one started with '&'). You use '<<:' as yaml notion for actually placing the 'base class' section, that you can override later.

vsm:
  stub_nsx_mgr: &MGR_CTRL_STUB
    username: ADMIN
    password: $DEFAULT_PASSWORD
    deployment: ovf
    build: $PR_BUILD
    vmnics:
      - network: $MANAGEMENT_NETWORK_0
    vc: vc_0
    ovf_options:
      - --diskMode=$DISKMODE
      - --deploymentOption=$DEPLOYMENT_OPTION
$MGR_0:
    <<: *MGR_CTRL_STUB
    ovf_path_regex: 'appliance.*\.ovf'
    ovf_options:
      - --diskMode=$DISKMODE
      - --deploymentOption=$DEPLOYMENT_OPTION
$CTRL_0:
    <<: *MGR_CTRL_STUB
    ovf_options:
      - --diskMode=$DISKMODE
      - --allowExtraConfig
$CTRL_1:
    *MGR_CTRL_STUB

But, if you do not want to override the extended fields, you can skip '<<:'

Related