Linux
CfEngine - 從不同的 CF 或 promises.cf 呼叫變數和類
我想將
body package_method
一些變數放在 promises.cf 或不同的文件中,我應該能夠從我編寫的任何新 CF 文件中呼叫它。那可能嗎?我在文件中找不到與此類方法相關的任何內容。
我正在考慮在其中創建一個新文件,
/var/cfengine/masterfiles/
然後編輯/var/cfengine/promises.cf
並插入新文件,inputs
但它沒有成功。這是我想放的(可能在一個新文件中)應該可以全域訪問的內容。
bundle common variables { vars: "global_var_1" string => "value_var_1"; }
和
body package_method yum { any:: package_changes => "bulk"; package_list_command => "/usr/bin/yum list installed"; package_list_name_regex => "([^.]+).*"; package_list_version_regex => "[^\s]\s+([^\s]+).*"; package_list_arch_regex => "[^.]+\.([^\s]+).*"; package_installed_regex => ".*installed.*"; package_name_convention => "$(name).$(arch)"; package_name_regex => "amanda-client"; package_arch_regex => "x86_64"; package_add_command => "/usr/bin/yum -y install"; package_delete_command => "/bin/rpm -e"; package_verify_command => "/bin/rpm -V"; }
然後我應該可以在任何新的 CF 中呼叫它:
"${variables.global_var_1}"
和
bundle agent packages { packages: "wget" package_policy => "add", package_method => yum; }
解決了。
創建全域變數:
創建一個
variables.cf
並在該文件中插入以下行。bundle common variables { vars: "global_var_1" string => "value_var_1"; }
然後創建任何 CF,但在
body common control
- 輸入variables.cf
文件下。body common control { bundlesequence => { "myclasses" }; inputs => { "variables.cf" }; }
然後您可以將變數稱為
"${variables.global_var_1}"
.
package_method
全域呼叫:在任何新的 CF 下
body common control
輸入文件/var/cfengine/masterfiles/lib/packages.cf
body common control { bundlesequence => { "myclasses", "packages_to_install" }; inputs => { "/var/cfengine/masterfiles/lib/packages.cf" }; }
然後你可以添加像
bundle agent packages_to_install { packages: "wget" package_policy => "add", package_method => yum; }