2

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.

1 Answers1

0

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",
}
рüффп
  • 620
  • 1
  • 11
  • 25
pwan
  • 257
  • 3
  • 14
  • I actually run puppet through cron jobs on my machines. Can I specify the environment without a puppet master or agent? I see `puppet agent --environment dev`, but what about `puppet apply --environment ... PATH/TO/MANIFEST.pp`? Can't see it on the manual page. – François Beausoleil Jul 20 '12 at 16:07
  • `puppet apply --environment=production` works fine. You can use any --option that you can put in the config file. – vaughan Aug 13 '12 at 11:23
  • I also needed to remove the surround braces `${environment}` -> `$environment` – vaughan Aug 13 '12 at 11:28