Puppet uses ENC to report 'could not load external node results'

Source: Internet
Author: User

Puppet uses ENC to report 'could not load external node results'

This problem has occurred for a while. At the beginning, there were more than 10 alarm emails from about 3-5 times a day to the last day...

Because the Puppet synchronization adopts two policies: Active triggering and timed synchronization, almost every error occurs during timed synchronization...

The Puppet Server adopts a dual-master structure and the Web ui uses Foreman. To confirm that the error is reported on that Server, by adding host tags to the source code log, the error is located only on a server ..., it appears by accident, but it is used in all error marks ....

Level Resource message

Err Puppet cocould not retrieve catalog from remote server: Error 400 on SERVER: Failed when searching for node xxx: 001 ., Cocould not load external node results for xxx: undefined method 'inobject' for false: FalseClass: --- false

Notice Puppet Using cached catalog

Err Puppet cocould not retrieve catalog; skipping run

The last one is: --- false where: Is the decomposition operator appended to the log for easy differentiation. --- false is the returned output information ..

In Puppet source code, you can see that the find method accepts a request parameter through the indirector find method related to enc.

Indirector/node/exec. rb

Def find (request)

Output = super or return nil

 

# Translate the output to ruby.

Result = translate (request. key, output)

 

Create_node (request. key, result)

End


Output is the find that calls the parent method.

The find of the parent method calls the enc script to obtain the returned value. If the call fails or fails, it is Nil ..

At this time, the yaml output will be converted into ruby objects through the translate method.

If the output is nil, yaml will throw an exception when reading the data. The exception is the content of the Puppet email alert.
 

Def translate (name, output)

YAML. load (output). inject ({}) do | hash, data |

Case data [0]

When String

Hash [data [0]. intern] = data [1]

When Symbol

Hash [data [0] = data [1]

Else

Raise Puppet: Error, "key is a # {data [0]. class}, not a string or symbol"

End

Hash

End

Rescue => detail

Raise Puppet: Error, "001, cocould not load external node results for # {name }:#{ detail }:#{ output }"

End

A lot of errors are caused by the fact that the node. rb script does not get 200 when taking parameters through the api.

By pointing to an incorrect WEB server address, you can see the beginning --- false ....

[Root @ test puppet] # ruby node1.rb test

--- False

Error retrieving node test: Net: HTTPNotFound

Analyze node. rb

Def enc (certname)

Foreman_url = "# {url}/node/# {certname }? Format = yml"

Uri = URI. parse (foreman_url)

Req = Net: HTTP: Get. new (uri. request_uri)

Http = Net: HTTP. new (uri. host, uri. port)

Http. use_ssl = uri. scheme = 'https'

If http. use_ssl?

If SETTINGS [: ssl_ca] &! SETTINGS [: ssl_ca]. empty?

Http. ca_file = SETTINGS [: ssl_ca]

Http. verify_mode = OpenSSL: SSL: VERIFY_PEER

Else

Http. verify_mode = OpenSSL: SSL: VERIFY_NONE

End

If SETTINGS [: ssl_cert] &! SETTINGS [: ssl_cert]. empty? & SETTINGS [: ssl_key] &! SETTINGS [: ssl_key]. empty?

Http. cert = OpenSSL: X509: Certificate. new (File. read (SETTINGS [: ssl_cert])

Http. key = OpenSSL: PKey: RSA. new (File. read (SETTINGS [: ssl_key]), nil)

End

End

Res = http. start {| http. request (req )}

 

Raise "Error retrieving node # {certname }:# {res. class}" unless res. code = "200"

Res. body

End


The first part of the script is to construct an http object... and directly look at the last three lines.

You can clearly see a judgment and then throw an exception. There is no Retry Mechanism ...., for this reason, I am very confident that my web, if it can have a retry opportunity, will be able to get the return value normally next time, and then I will give it many chances...
 

# Raise "Error retrieving node # {certname }:# {res. class}" unless res. code = "200"

While res. code! = "200"

Res = http. start {| http. request (req )}

Puts "Error retrieving node # {certname }:#{ res. class}" sleep 3

End


At this time, some people may think, while loop, add 3 seconds to retry, what if it has not been successful?

Timeout is configured at the beginning of the script. When timeout is reached, the http connection is closed and the cache is read.
 

# Query External node

Begin

Result = ""

Timeout (tsecs) do

Result = enc (certname)

Cache (certname, result)

End

Rescue TimeoutError, SocketError, Errno: EHOSTUNREACH, Errno: ECONNREFUSED

# Read from cache, we got some sort of an error.

Result = read_cache (certname)


This Code clearly shows that the enc method will be called to return results when the timeout is not too large, and then the cache method will be called to write data to the cache file.

If a timeout or http Error occurs, the cache is read, but the exceptions do not include ..., HTTP ..., if the error is 4XX, the read cache exception is not triggered ..

Puppet Learning Series:

Puppet Learning 1: Installation and simple instance applications

Puppet 2: simple module configuration and application

Research on three Backup Recovery solutions for Puppet agent
Register your Puppet node in a safer way
Deep understanding of Puppet syntax and working mechanism through SSH Configuration
Puppet uses Nginx multiple ports for Load Balancing
C/S mode instance of Puppet in CentOS (5 and 6)

For more information about Puppet, click here.
Puppet: click here

This article permanently updates the link address:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.