Skip to content

Commit

Permalink
Work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
amousset committed Sep 26, 2016
1 parent 2059228 commit 6dcf01e
Show file tree
Hide file tree
Showing 3 changed files with 245 additions and 0 deletions.
3 changes: 3 additions & 0 deletions techniques/applications/packageManagement/1.0/changelog
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- Alexis Mousset <alexis.mousset@normation.com> Mon, 26 Sep 2016 17:19:00 +0100
* Version 1.0
** Use the new package promises
165 changes: 165 additions & 0 deletions techniques/applications/packageManagement/1.0/metadata.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
<!--
Copyright 2016 Normation SAS
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, Version 3.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->

<TECHNIQUE name="Package management">
<DESCRIPTION>This technique operates on individual packages.

It will ensure that the defined packages are in the desired state using the appropriate package manager.</DESCRIPTION>

<MULTIINSTANCE>true</MULTIINSTANCE>
<COMPATIBLE>
<OS version=">= 4">RHEL / CentOS</OS>
<OS version=">= 10 SP1">SuSE LES / DES / OpenSuSE</OS>
<OS version=">= 5">Debian / Ubuntu</OS>
<AGENT version=">= 3.7.0">cfengine-community</AGENT>
</COMPATIBLE>

<BUNDLES>
<NAME>ensure_package_state</NAME>
</BUNDLES>

<TMLS>
<TML name="packageManagement"/>
</TMLS>

<TRACKINGVARIABLE>
<SAMESIZEAS>PACKAGE_LIST</SAMESIZEAS>
</TRACKINGVARIABLE>

<SECTIONS>
<SECTION name="packages" multivalued="true" component="true" componentKey="PACKAGE_LIST">
<INPUT>
<NAME>PACKAGE_LIST</NAME>
<DESCRIPTION>Package name</DESCRIPTION>
</INPUT>
<SELECT1>
<NAME>PACKAGE_STATE</NAME>
<DESCRIPTION>State to enforce for this package</DESCRIPTION>
<ITEM>
<LABEL>Present</LABEL>
<VALUE>present</VALUE>
</ITEM>
<ITEM>
<LABEL>Absent</LABEL>
<VALUE>absent</VALUE>
</ITEM>
<CONSTRAINT>
<DEFAULT>present</DEFAULT>
</CONSTRAINT>
</SELECT1>
<SECTION name="Package version" component="false">
<SELECT1>
<NAME>PACKAGE_VERSION_DEFINITION</NAME>
<DESCRIPTION>Define package version</DESCRIPTION>
<ITEM>
<LABEL>Lastest available version</LABEL>
<VALUE>latest</VALUE>
</ITEM>
<ITEM>
<LABEL>Any version</LABEL>
<VALUE>any</VALUE>
</ITEM>
<ITEM>
<LABEL>A specific version</LABEL>
<VALUE>specific</VALUE>
</ITEM>
<CONSTRAINT>
<DEFAULT>default</DEFAULT>
</CONSTRAINT>
</SELECT1>
<INPUT>
<NAME>PACKAGE_VERSION</NAME>
<DESCRIPTION>Package version</DESCRIPTION>
<CONSTRAINT>
<MAYBEEMPTY>true</MAYBEEMPTY>
</CONSTRAINT>
</INPUT>
</SECTION>
<SECTION name="Package architecture" component="false">
<SELECT1>
<NAME>PACKAGE_ARCHITECTURE_DEFINITION</NAME>
<DESCRIPTION>Define package architecture</DESCRIPTION>
<ITEM>
<LABEL>Use default architecture</LABEL>
<VALUE>default</VALUE>
</ITEM>
<ITEM>
<LABEL>Ensure a specific version is installed</LABEL>
<VALUE>specific</VALUE>
</ITEM>
<CONSTRAINT>
<DEFAULT>default</DEFAULT>
</CONSTRAINT>
</SELECT1>
<INPUT>
<NAME>PACKAGE_ARCHITECTURE</NAME>
<DESCRIPTION>Package architecture</DESCRIPTION>
<CONSTRAINT>
<MAYBEEMPTY>true</MAYBEEMPTY>
</CONSTRAINT>
</INPUT>
</SECTION>
<SECTION name="Package manager" component="false">
<SELECT1>
<NAME>PACKAGE_MANAGER_DEFINITION</NAME>
<DESCRIPTION>Define package manager to use</DESCRIPTION>
<ITEM>
<LABEL>Default package manager</LABEL>
<VALUE>default</VALUE>
</ITEM>
<ITEM>
<LABEL>yum/rpm</LABEL>
<VALUE>yum</VALUE>
</ITEM>
<ITEM>
<LABEL>apt/dpkg</LABEL>
<VALUE>apt</VALUE>
</ITEM>
<ITEM>
<LABEL>zypper/rpm</LABEL>
<VALUE>zypper</VALUE>
</ITEM>
<ITEM>
<LABEL>pkg</LABEL>
<VALUE>pkg</VALUE>
</ITEM>
<CONSTRAINT>
<DEFAULT>default</DEFAULT>
</CONSTRAINT>
</SELECT1>
</SECTION>
<SECTION name="Post-modification hook" component="true" componentKey="PACKAGE_LIST">
<INPUT>
<NAME>PACKAGE_POST_HOOK_RUN</NAME>
<DESCRIPTION>Should the command(s) below be run if the above package has been modified?</DESCRIPTION>
<CONSTRAINT>
<TYPE>boolean</TYPE>
<DEFAULT>false</DEFAULT>
</CONSTRAINT>
</INPUT>
<INPUT>
<NAME>PACKAGE_POST_HOOK_COMMAND</NAME>
<DESCRIPTION>Command to run after any modifications</DESCRIPTION>
<CONSTRAINT>
<TYPE>textarea</TYPE>
<MAYBEEMPTY>true</MAYBEEMPTY>
</CONSTRAINT>
</INPUT>
</SECTION>
</SECTION>
</SECTIONS>

</TECHNIQUE>
77 changes: 77 additions & 0 deletions techniques/applications/packageManagement/1.0/packageManagement.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#####################################################################################
# Copyright 2016 Normation SAS
#####################################################################################
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, Version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#####################################################################################

bundle agent ensure_package_state {

vars:
&PACKAGE_LIST:{name |"package[&i0&]" string => "&name&";
}&

&TRACKINGKEY:{uuid | "trackingkey[&i&]" string => "&uuid&";

This comment has been minimized.

Copy link
@ncharles

ncharles Sep 26, 2016

it should be i0

}&

&PACKAGE_STATE:{state |"state[&i0&]" string => "&state&";
}&

&PACKAGE_VERSION_DEFINITION:{version |"version[&i0&]" string => "&version&";
}&
&PACKAGE_VERSION:{version |"version[&i0&]" string => "&version&", ifvarclass => "specific_version_${index_pkg}";
}&

&PACKAGE_ARCHITECTURE_DEFINITION:{architecture |"architecture[&i0&]" string => "&architecture&";
}&
&PACKAGE_ARCHITECTURE:{architecture |"architecture[&i0&]" string => "&architecture&", ifvarclass => "specific_architecture_${index_pkg}";
}&

&PACKAGE_MANAGER_DEFINITION:{manager |"manager[&i0&]" string => "&manager&";
}&
&PACKAGE_MANAGER:{manager |"manager[&i0&]" string => "&manager&", ifvarclass => "specific_manager_${index_pkg}";
}&

&PACKAGE_POST_HOOK_COMMAND:{command |"posthook[&i0&]" string => "&command&";
}&

"index_pkg" slist => getindices("package");

classes:

&PACKAGE_POST_HOOK_RUN:{run |"execute_command_&i0&" expression => strcmp("&run&", "true");
}&

&PACKAGE_VERSION_DEFINITION:{run |"specific_architecture_&i0&" expression => strcmp("&run&", "specific");
}&

&PACKAGE_ARCHITECTURE_DEFINITION:{run |"specific_version_&i0&" expression => strcmp("&run&", "specific");
}&

&PACKAGE_MANAGER_DEFINITION:{run |"specific_manager_&i0&" expression => strcmp("&run&", "specific");
}&

"class_prefix[${index_pkg}]" string => "package_${state[${index_pkg}]}_${name[${index_pkg}]}";

methods:

"any" usebundle => _package_state("${package[${index_pkg}]}", "${version[${index_pkg}]}", "${architecture[${index_pkg}]}", "${manager[${index_pkg}]}", "${state[${index_pkg}]}");

"report_${index_pkg}" usebundle => rudder_common_reports_generic_index("packageManagement", "${class_prefix_${index}}", "${trackingkey[${index}]}", "File", "${file[${index}]}", "TODO", "${index}");

"any" usebundle => command_execution("${posthook[${index_pkg}]}"),
ifvarclass => "execute_command_${index_pkg}.${class_prefix[${index_pkg}]}_repaired";

}

2 comments on commit 6dcf01e

@ncharles
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget the maintained-techniques file !

@ncharles
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so far, this looks great ! thank you for the readable code

Please sign in to comment.