Puppet [SOLVED]: Puppet reference enviornment name from .pp file?

Puppet [SOLVED]: Puppet reference enviornment name from .pp file?

Home Forums Automation Tools Puppet Puppet [SOLVED]: Puppet reference enviornment name from .pp file?

Tagged: ,

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #233206

    Cloudy Point
    Keymaster

    QuestionQuestion

    I have external node classifier that manages the environment for each device in my puppet fleet.

    When a device checks-in I’m updating it’s configuration file so it knows what environment it’s in:

    ini_setting { 'set local enviornment':
      ensure  => present,
      path    => '/etc/puppetlabs/puppet/puppet.conf',
      section => 'agent',
      setting => 'environment',
      value   => 'environment_name',
    }
    

    I currently have each r10k branch hard-coding the name.

    Instead I’d like to be able to use the same code block on all environments, something like:

    ini_setting { 'set local enviornment':
      ...
      value   => $environment_name,
    }
    

    #233207

    Cloudy Point
    Keymaster

    Accepted AnswerAnswer

    When a device checks-in I’m updating it’s configuration file so it knows what environment it’s in:

    You do know that you don’t need to do that for Puppet’s sake, right? If you are (properly; see below) using an ENC to control nodes’ environments then that overrides anything the nodes self-report, so you could do without nodes being locally configured to know their own environments at all.

    Instead I’d like to be able to use the same code block on all
    environments, something like:

    ini_setting { 'set local enviornment':
      ...
      value   => $environment_name,
    }
    

    The correct way for an ENC to specify a node’s environment to Puppet is by setting the environment key in its output for that node. This is how an ENC directly puts the node into the specified environment. Like any other top-level parameter emitted by the ENC, however, you can reference its value as a top-scope variable. Thus, if you want to update node’s Puppet configuration to explicitly specify (after the fact) the environment that the ENC assigns to the node, then you can use that, much as you propose:

    ini_setting { 'set local enviornment':
      ...
      value   => $::environment,
    }
    

    Source: https://stackoverflow.com/questions/47598021/puppet-reference-enviornment-name-from-pp-file
    Author: John Bollinger
    Creative Commons License
    This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.