Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #3125 - Add new Technique in order to have a CFEngine variable from execution of commands #65

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#####################################################################################
# Copyright 2011 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 common generic_cmd_var_def {

vars:

&GENERIC_COMMAND_VARIABLE_NAME, GENERIC_COMMAND_VARIABLE_BINARY, GENERIC_COMMAND_VARIABLE_SHELL:{name, binary, shell |"&name&" string => execresult("&binary&", "&shell&");
}&

}

bundle agent generic_cmd_var_def_report {
vars:
&TRACKINGKEY:{directiveId |"generic_command_name_uuid[&i&]" string => "&directiveId&";
}&
&GENERIC_COMMAND_VARIABLE_NAME:{name |"generic_cmd_variable_name[&i&]" string => "&name&";
}&

"generic_cmd_variable_name_index" slist => getindices("generic_command_name_uuid");

reports:

(linux|!linux)::

"@@genericCommandVariableDefinition@@result_success@@$(generic_command_name_uuid[$(generic_cmd_variable_name_index)])@@Variable command definition@@$(generic_cmd_variable_name[$(generic_cmd_variable_name_index)])@@$(g.execRun)##$(g.uuid)@#A generic command variable definition is set for variable $(generic_cmd_variable_name[$(generic_cmd_variable_name_index)])";

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<!--
Copyright 2011 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="Generic CFEngine Command variable definition">
<DESCRIPTION>Configures a generic CFEngine variable in a common bundle from the output of an executable, to be used in another Technique. This Technique does nothing by itself, you must reuse the variable(s) you will create here in another Technique with the form: $(generic_cmd_var_def.variablename)</DESCRIPTION>
<COMPATIBLE>
<OS>Every OS</OS>
<AGENT version=">= 3.1.5">cfengine-community</AGENT>
</COMPATIBLE>

<MULTIINSTANCE>true</MULTIINSTANCE>

<BUNDLES>
<NAME>generic_cmd_var_def_report</NAME>
</BUNDLES>

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

<TRACKINGVARIABLE>
<SAMESIZEAS>GENERIC_COMMAND_VARIABLE_NAME</SAMESIZEAS>
</TRACKINGVARIABLE>

<SECTIONS>
<!-- general Section -->
<SECTION name="Variable command definition" component="true" multivalued="true" componentKey="GENERIC_COMMAND_VARIABLE_NAME">
<INPUT>
<NAME>GENERIC_COMMAND_VARIABLE_NAME</NAME>
<DESCRIPTION>Variable name for the output of this command</DESCRIPTION>
<CONSTRAINT>
<TYPE>string</TYPE>
<REGEXP error="Please enter a valid CFEngine variable name"><![CDATA[ [a-zA-Z][a-zA-Z0-9_]* ]]></REGEXP>
</CONSTRAINT>
</INPUT>
<SELECT1>
<NAME>GENERIC_COMMAND_VARIABLE_SHELL</NAME>
<DESCRIPTION>Use CFEnginge embeded shell or system shell</DESCRIPTION>
<LONGDESCRIPTION>
Use of a shell has both resource and security consequences. A shell consumes an extra process and inherits environment variables,
reads commands from files and performs other actions beyond the control of CFEngine.
If one does not need shell functionality such as piping through multiple commands then it is best to manage without it.</LONGDESCRIPTION>
<ITEM>
<VALUE>noshell</VALUE>
<LABEL>CFEngine shell</LABEL>
</ITEM>
<ITEM>
<VALUE>useshell</VALUE>
<LABEL>system shell</LABEL>
</ITEM>
<CONSTRAINT>
<DEFAULT>noshell</DEFAULT>
</CONSTRAINT>
</SELECT1>
<INPUT>
<NAME>GENERIC_COMMAND_VARIABLE_BINARY</NAME>
<DESCRIPTION>Executable whose output is to be stored as a variable</DESCRIPTION>
<LONGDESCRIPTION>Be careful, the absolute path to the binary must be specified here. Example: /bin/uname instead of uname</LONGDESCRIPTION>
<CONSTRAINT>
<TYPE>string</TYPE>
</CONSTRAINT>
</INPUT>
</SECTION>
</SECTIONS>

</TECHNIQUE>