diff --git a/techniques/applications/yumPackageManagerRepositories/1.0/changelog b/techniques/applications/yumPackageManagerRepositories/1.0/changelog new file mode 100644 index 000000000..15a383731 --- /dev/null +++ b/techniques/applications/yumPackageManagerRepositories/1.0/changelog @@ -0,0 +1,4 @@ + -- Nicolas CHARLES Wed Nov 25 12:00:00 CEST 2014 + * Version 1.0 + ** Creation of technique to manage Yum repositories + diff --git a/techniques/applications/yumPackageManagerRepositories/1.0/metadata.xml b/techniques/applications/yumPackageManagerRepositories/1.0/metadata.xml new file mode 100644 index 000000000..2551b7f12 --- /dev/null +++ b/techniques/applications/yumPackageManagerRepositories/1.0/metadata.xml @@ -0,0 +1,100 @@ + + This technique configures repositories for Yum package manager. + + Each repositories are identified by their repository id. + + true + + + cfengine-community + + + + yum_repositories_management_RudderUniqueID + + + + + + + + + false + + + + + YUM_REPO_ID + + + +
+ + YUM_REPO_ID + Repository id + The unique repository id, in [ ] in the repository configuration + + + YUM_REPO_ACTION + Add/modify or delete the repository + + add + + + + delete + + + + add + + + + YUM_REPO_NAME + Repository name + + + YUM_REPO_URL + Repository URL + + + YUM_REPO_ENABLED + Repository activation status + Activate or deactive a specific repository + + 0 + + + + 1 + + + + 1 + + + + YUM_REP_GPG_CHECK + Activate GPG check + + 0 + + + + 1 + + + + 1 + + + + YUM_REPO_GPG_URI + Location of the GPG Key + + true + + +
+
+
diff --git a/techniques/applications/yumPackageManagerRepositories/1.0/yum-repositories-management.st b/techniques/applications/yumPackageManagerRepositories/1.0/yum-repositories-management.st new file mode 100644 index 000000000..156c72d04 --- /dev/null +++ b/techniques/applications/yumPackageManagerRepositories/1.0/yum-repositories-management.st @@ -0,0 +1,75 @@ +bundle agent yum_repositories_management_&RudderUniqueID& { + + vars: + &YUM_REPO_ID:{repo_id |"repo_id[&i&]" string => "&repo_id&"; +}& + &YUM_REPO_NAME:{repo_name |"repo_name[&i&]" string => "&repo_name&"; +}& + &YUM_REPO_ACTION:{repo_action |"repo_action[&i&]" string => "&repo_action&"; +}& + + &YUM_REPO_URL:{repo_url |"repo_url[&i&]" string => "&repo_url&"; +}& + &YUM_REPO_ENABLED:{repo_enabled |"repo_enabled[&i&]" string => "&repo_enabled&"; +}& + &YUM_REP_GPG_CHECK:{repo_gpg_check |"repo_gpg_check[&i&]" string => "&repo_gpg_check&"; +}& + &YUM_REPO_GPG_URI:{repo_gpg_uri |"repo_gpg_uri[&i&]" string => "&repo_gpg_uri&"; +}& + &TRACKINGKEY:{uuid |"trackingkey[&i&]" string => "&uuid&"; +}& + + "index" slist => getindices("repo_id"); + + + # Construct the identifier string : \[repo_id\] + "grep_repo_id[${index}]" string => "\[${repo_id[${index}]}\]"; + + pass1:: + "filename[${index}]" string => execresult("grep -rl '${grep_repo_id[${index}]}' /etc/yum.repos.d"); + + # override filename if repo is absent + "filename[${index}]" string => "/etc/yum.repos.d/rudder-${repo_id[${index}]}.repo", + if => "repo_entry_absent_${index}"; + + "canonified_filename[${index}]" string => canonify("${filename[${index}]}"); + + classes: + "delete_repo_${index}" expression => strcmp("${repo_action$[${index}]}", "delete"); + + pass1:: + "repo_entry_absent_${index}" expression => strcmp("${filename$[${index}]}", ""); + + + any:: + "pass3" expression => "pass2"; + "pass2" expression => "pass1"; + "pass1" expression => "any"; + + + methods: + pass3:: + # create or enforce entries + "set repo name ${index}" usebundle => file_key_value_present_in_ini_section("${filename[${index}]}", "${repo_id[${index}]}", "name", "${repo_name[${index}]}"), + if => "!delete_repo_${index}"; + "set repo url ${index}" usebundle => file_key_value_present_in_ini_section("${filename[${index}]}", "${repo_id[${index}]}", "url", "${repo_url[${index}]}"), + if => "!delete_repo_${index}"; + "set repo enabled ${index}" usebundle => file_key_value_present_in_ini_section("${filename[${index}]}", "${repo_id[${index}]}", "enabled", "${repo_enabled[${index}]}"), + if => "!delete_repo_${index}"; + "set repo gpgcheck ${index}" usebundle => file_key_value_present_in_ini_section("${filename[${index}]}", "${repo_id[${index}]}", "gpgcheck", "${repo_gpg_check[${index}]}"), + if => "!delete_repo_${index}"; + "set repo gpg uri ${index}" usebundle => file_key_value_present_in_ini_section("${filename[${index}]}", "${repo_id[${index}]}", "gpgkey", "${repo_gpg_uri[${index}]}"), + if => "!delete_repo_${index}"; + + + # report + # Using old_class_prefix to avoid having to copy all classes + "report for modification" usebundle => rudder_common_reports_generic_index("Package sources (Yum)", "file_key_value_present_in_ini_section_${canonified_filename[${index}]}", "${trackingkey[${index}]}", "Repositories", "${repo_id[${index}]}", "Setting repository ${repo_name[${index}]} with id ${repo_id[${index}]} ", "${index}"), + if => "!delete_repo_${index}"; + + # Deletion of repo + "delete repo ${index}" usebundle => file_absent("${filename[${index}]}"), + if => "delete_repo_${index}"; + "report for deletion" usebundle => rudder_common_reports_generic_index("Package sources (Yum)", "file_absent_${canonified_filename[${index}]}", "${trackingkey[${index}]}", "Repositories", "${repo_id[${index}]}", "Deleting repository with id ${repo_id[${index}]} ", "${index}"), + if => "delete_repo_${index}"; +}