Ubuntu – How to change single variable in Puppet between environments

puppetUbuntu

Specifically, if I'm in staging, I want directory A, and in QA, directory B:

file{'/etc/appenv':
  ensure => file,
  owner  => 'root',
  group  => 'root',
  mode   => 0644,
  source => "file:///puppet/modules/myapp/appenv-${env}",
}

I have only 1 machine that needs this specific env for now. I have read Puppet: variable overriding best practices, but I thought stages were supposed to be used for this purpose.

Best Answer

Instead of ${env}, try using ${environment} as per the official documentation.

If you want to change another variable based on the environment, you can do it in a conditional/case statement/selector:

$dir = ${environment} ? {
   'staging' =>'A',
    'QA' => 'B',
    default => 'unknown',
}

file{'/etc/appenv':
  ensure => file,
  owner  => 'root',
  group  => 'root',
  mode   => 0644,
  source => "file:///puppet/modules/myapp/${dir}/appenv",
}
Related Topic