Uploaded image for project: 'Puppet'
  1. Puppet
  2. PUP-4521

Pass agent-requested environment to external node classifiers

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Normal
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: PUP 4.2.0
    • Component/s: None
    • Labels:
      None
    • Release Notes:
      New Feature

      Description

      Updated

      This feature modifies the agent to include a `configured_environment` query parameter when making node and catalog requests. The `configured_enviroment` is the environment as specified in the agent's configuration, e.g. puppet.conf or command line. It is often the same as the `environment` query parameter that the agent currently sends. However, there are cases where an ENC or custom fact can switch the agent's current environment. When this happens, the agent will make a catalog request with an `environment` query parameter set to the new value, while the `configured_environment` query parameter will be set to the original value as configured on the agent.

      Original

      There is currently no way to write an external node classifier (which is authoritative) that allows some agents - based on Facts - to override the node classifier with its own requested environment. A simple Fact-based classifier might be

      require 'puppet/node'
       
      class Puppet::Node::FactClassifier < Puppet::Indirector::Code
        desc "Simple facts-based classification"
       
        # Look for external node definitions.
        def find(request)
          name = request.key
          facts = Puppet::Node::Facts.indirection.find(name, :environment => request.environment)
          fact_values = if facts.nil?
                          {}
                        else
                          facts.sanitize
                          facts.to_data_hash['values']
                        end
       
          node = Puppet::Node.new(name)
          if fact_values['test']
            Puppet.info("Use agent-specified environment")
            node.environment = request.environment
          else
            Puppet.info("Use production environment")
            node.environment = 'production'
          end
       
          node.fact_merge
          node
        end
      end
      

      The first request from the agent will not use the correct Facts (that might need to include custom facts), which may end up classifying it as production, and subsequent requests will send request.environment as production, losing the agent's configured environment.

      The simplest way to handle this is to add the configured environment as a new option of the request, so the classifier can use that information.

        Attachments

          Issue Links

            Activity

              jsd-sla-details-panel

                People

                • Assignee:
                  Unassigned
                  Reporter:
                  michael.smith Michael Smith
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  9 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: