On Tuesday, January 14, 2014 5:20:55 PM UTC-6, James Ellis wrote: > > Hi, chanced across this discussion when I noticed an ENC was being called > twice. I understand I may not be using the ENC terminus exactly as it's > been designed, but it's unexpected that it was called twice. Also worth > noting that I can't see a note about the ENC being called twice here: > http://docs.puppetlabs.com/guides/external_nodes.html<http://www.google.com/url?q=http%3A%2F%2Fdocs.puppetlabs.com%2Fguides%2Fexternal_nodes.html&sa=D&sntz=1&usg=AFQjCNFK7HQpajIuPvlZjm7asakMiSwElg> > >
True, but the docs also don't say it's called only once. If you read between the lines, you might infer that it can be called multiple times. In particular, consider this excerpt from the doc: "In Puppet 3 and later, ENCs can set an environment for a node, overriding whatever environment the node requested. However, previous versions of Puppet use ENC-set and node-set environments inconsistently, with the ENC’s used during catalog compilation and the node’s used when downloading files." The reason for the inconsistency in Puppet 2 is that file downloads occur in separate request contexts, and that version of Puppet did not re-run the ENC for each of those as it would have needed to do to compute the appropriate environment correctly. To be sure, the docs could be clearer on the point. Feel free to file an RFE. > In my case, I'm using an ENC to push virtual host changes to an agent > running a web server, the YAML returned by the ENC uses create_resources to > dynamically add resources to the catalogue. > I observed via logging in the ENC script that on the first run, the ENC > was excecuted but the catalogue was not applied, on the second run the > catalogue was applied on the agent. > By default, the agent issues at least two web requests to the master on every run because it first synchronizes plugins, then requests a catalog. It may make other requests as well, to retrieve plugin contents when it determines those are needed, or to retrieve 'source'd files. All of those requests require the master to determine the node's environment to provide correct service, and determining the environment requires running the ENC, if there is one. > This causes problems where we use an API to dynamically apply resources to > a catalogue (1st run gets the catalogue resources, returns 'OK' to the API, > 2nd run then tries to get resources but gets nothing as the 'OK' sent to > the API has effectively modified the resources to be applied). > > I've worked around this, for now, by using a lock file, so that the 'OK' > API call is only run once but this still applies two calls to the API to > dynamically get resources for the catalogue, where only one is required. I > double checked the master and the agent configs, and the master only shows > the ENC being referenced once and there is one agent being run, only. > > Based on this, is there any way the agent can be set to call the ENC once > only ? The only argument to the script is the agent hostname and there is > no apparent difference in the environment of the first and second ENC calls. > > If you disable pluginsync at the agent and avoid declaring any 'source'd File resources pointing back to the master, then I think the agent will make only one request to the master per catalog run. In that case, the master should run the ENC only once for that catalog run. Disabling pluginsync may make it difficult to insert certain new modules into your Puppet infrastructure or to update such modules, and avoiding 'source'd Files will require great discipline and vigilance. I would think twice before going that route. Instead, if you want to stick with your current ENC concept then you should consider how your ENC might recognize multiple calls associated with the same catalog run. I think node facts are updated only once per catalog run, after pluginsync and just prior to running the ENC to kick off catalog compilation. Perhaps, then, you could watch each node's 'uptime_seconds' fact, and perform your once-per-catalog-run work only if the value of that fact is different from what it was during the previous run of the ENC for the given node. The doc you referred to has a bit of information about how the ENC can access node facts. John -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/b49829d1-e452-41b6-9fa2-9dd0fc4e1fd8%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.