Puppet - RESTful API



Puppet 使用 RESTful API 作为 Puppet master 和 Puppet agent 之间的通信通道。以下是访问此 RESTful API 的基本 URL。

https://brcleprod001:8140/{environment}/{resource}/{key} 
https://brcleprod001:8139/{environment}/{resource}/{key}

REST API 安全性

Puppet 通常负责安全性以及 SSL 证书管理。但是,如果希望在集群外部使用 RESTful API,则需要自行管理证书,以便尝试连接到机器。Puppet 的安全策略可以通过 rest authconfig 文件进行配置。

测试 REST API

Curl 实用程序可以用作测试 RESTful API 连接的基本工具。以下是如何使用 REST API curl 命令检索节点目录的示例。

curl --cert /etc/puppet/ssl/certs/brcleprod001.pem --key 
   /etc/puppet/ssl/private_keys/brcleprod001.pem

在以下命令集中,我们只是设置 SSL 证书,这将根据 SSL 目录的位置和所用节点的名称而有所不同。例如,让我们看看以下命令。

curl --insecure -H 'Accept: yaml' 
https://brcleprod002:8140/production/catalog/brcleprod001 

在上例命令中,我们只发送一个标头,指定我们想要返回的格式,以及用于生成生产环境中 **brcleprod001** 目录的 RESTful URL,将生成以下输出。

--- &id001 !ruby/object:Puppet::Resource::Catalog 
aliases: {} 
applying: false 
classes: [] 
...

让我们假设另一个示例,我们想要从 Puppet master 获取 CA 证书。它不需要使用自己的签名 SSL 证书进行身份验证,因为这是在身份验证之前所需的操作。

curl --insecure -H 'Accept: s' https://brcleprod001:8140/production/certificate/ca  

-----BEGIN CERTIFICATE----- 
MIICHTCCAYagAwIBAgIBATANBgkqhkiG9w0BAQUFADAXMRUwEwYDVQQDDAxwdXBw

Puppet Master 和 Agent 共享 API 参考

GET /certificate/{ca, other}  

curl -k -H "Accept: s" https://brcelprod001:8140/production/certificate/ca 
curl -k -H "Accept: s" https://brcleprod002:8139/production/certificate/brcleprod002 

Puppet Master API 参考

已认证资源(需要有效的签名证书)。

目录

GET /{environment}/catalog/{node certificate name} 

curl -k -H "Accept: pson" https://brcelprod001:8140/production/catalog/myclient

证书吊销列表

GET /certificate_revocation_list/ca 

curl -k -H "Accept: s" https://brcleprod001:8140/production/certificate/ca 

证书请求

GET /{environment}/certificate_requests/{anything} GET 
/{environment}/certificate_request/{node certificate name}  

curl -k -H "Accept: yaml" https://brcelprod001:8140/production/certificate_requests/all 
curl -k -H "Accept: yaml" https://brcleprod001:8140/production/certificate_request/puppetclient 

报告 - 提交报告

PUT /{environment}/report/{node certificate name}  
curl -k -X PUT -H "Content-Type: text/yaml" -d "{key:value}" https://brcleprod002:8139/production

节点 - 关于特定节点的事实

GET /{environment}/node/{node certificate name}  

curl -k -H "Accept: yaml" https://brcleprod002:8140/production/node/puppetclient 

状态 - 用于测试

GET /{environment}/status/{anything}  

curl -k -H "Accept: pson" https://brcleprod002:8140/production/certificate_request/puppetclient

Explore our latest online courses and learn new skills at your own pace. Enroll and become a certified expert to boost your career.

Puppet Agent API 参考

在任何机器上设置新的 agent 时,默认情况下 Puppet agent 不会侦听 HTTP 请求。需要在 Puppet 中通过在 puppet.conf 文件中添加“listen=true”来启用它。这将使 Puppet agent 在启动时侦听 HTTP 请求。

事实

GET /{environment}/facts/{anything}  

curl -k -H "Accept: yaml" https://brcelprod002:8139/production/facts/{anything}

**运行** - 导致客户端像 puppetturn 或 puppet kick 一样更新。

PUT  /{environment}/run/{node certificate name}  

curl -k -X PUT -H "Content-Type: text/pson" -d "{}" 
https://brcleprod002:8139/production/run/{anything}
广告