6.8. 使用外部文件修改智能类参数
您可以使用外部文件修改 Puppet 智能类参数。
使用外部文件简化了使用 JSON 数据的过程。您可以使用带有语法高亮显示的编辑器来避免并查找错误。
使用外部文件修改智能类参数
本例使用 MOTD Puppet 清单。
本例中为
motd
,按名称搜索 Puppet 类。请求示例:
$ curl --header "Accept:application/json" \ --header "Content-Type:application/json" \ --request GET --user My_User_Name:My_Password \ https://satellite.example.com/api/smart_class_parameters?search=puppetclass_name=motd \ | python3 -m json.tool
检查以下输出。每个智能类参数都有一个 ID,对于同一 Satellite 实例是全局的。
motd
类的content
参数具有id=3
。不要将其与 Puppet 类名称前面显示的 Puppet 类 ID 混淆。响应示例:
{ "avoid_duplicates": false, "created_at": "2017-02-06 12:37:48 UTC", # Remove this line. "default_value": "", # Add a new value here. "description": "", "hidden_value": "", "hidden_value?": false, "id": 3, "merge_default": false, "merge_overrides": false, "override": false, # Set the override value to
true
. "override_value_order": "fqdn\nhostgroup\nos\ndomain", "override_values": [], # Remove this line. "override_values_count": 0, "parameter": "content", "parameter_type": "string", "puppetclass_id": 3, "puppetclass_name": "motd", "required": false, "updated_at": "2017-02-07 11:56:55 UTC", # Remove this line. "use_puppet_default": false, "validator_rule": null, "validator_type": "" }使用参数 ID
3
获取特定于motd
参数的信息,并将输出重定向到文件,如 output_file.json。请求示例:
$ curl --header "Accept:application/json" \ --header "Content-Type:application/json" --request GET \ --user My_User_Name:My_Password \ https://satellite.example.com/api/smart_class_parameters/3 \ | python3 -m json.tool > output_file.json
将上一步中创建的文件复制到新文件以进行编辑,例如
changed_file.json
:$ cp output_file.json changed_file.json
修改 文件中所需的值。在本例中,更改
motd
模块的 content 参数,该参数需要将覆盖选项
从false
改为true
:{ "avoid_duplicates": false, "created_at": "2017-02-06 12:37:48 UTC", # Remove this line. "default_value": "", # Add a new value here. "description": "", "hidden_value": "", "hidden_value?": false, "id": 3, "merge_default": false, "merge_overrides": false, "override": false, # Set the override value to
true
. "override_value_order": "fqdn\nhostgroup\nos\ndomain", "override_values": [], # Remove this line. "override_values_count": 0, "parameter": "content", "parameter_type": "string", "puppetclass_id": 3, "puppetclass_name": "motd", "required": false, "updated_at": "2017-02-07 11:56:55 UTC", # Remove this line. "use_puppet_default": false, "validator_rule": null, "validator_type": "" }编辑该文件后,验证是否如下所示,然后保存更改:
{ "avoid_duplicates": false, "default_value": "No Unauthorized Access Allowed", "description": "", "hidden_value": "", "hidden_value?": false, "id": 3, "merge_default": false, "merge_overrides": false, "override": true, "override_value_order": "fqdn\nhostgroup\nos\ndomain", "override_values_count": 0, "parameter": "content", "parameter_type": "string", "puppetclass_id": 3, "puppetclass_name": "motd", "required": false, "use_puppet_default": false, "validator_rule": null, "validator_type": "" }
将文件提交到 Satellite:
$ curl --header "Accept:application/json" \ --header "Content-Type:application/json" \ --request PUT --user My_User_Name:My_Password \ --data @changed_file.json \ https://satellite.example.com/api/smart_class_parameters/3