- Joined
- Jan 24, 2006
- Location
- South Dakota
So I thought that I would start a thread (hopefully a sticky) that is similar to "/bin". The purpose of this thread will be to post recipes/bundles/promises for your configuration management tools. At current I am thinking about CFEngine/Puppet/Chef, but if you have others feel free to clearly identify which system you are applying the configuration to before posting the code.
Without further adu....
CFEngine 3
The purpose of this simple bundle is to take a base install of a virtualbox vm, and install the guest additions, change its networking and hostname from the default image.
It makes most of its decisions based on the mac address and may take up to 15 minutes to converge completely because I have 2 reboot statements. This is obviously for a YUM based system
For those interested, I have created syntax highlight (in basic form) for gedit
And a much better version for nano
Without further adu....
CFEngine 3
The purpose of this simple bundle is to take a base install of a virtualbox vm, and install the guest additions, change its networking and hostname from the default image.
It makes most of its decisions based on the mac address and may take up to 15 minutes to converge completely because I have 2 reboot statements. This is obviously for a YUM based system
Code:
bundle agent vbox_install
{
#I am attempting to define a class only of the vbox guest additions are installed
classes:
"additions_installed" and => { fileexists("/etc/init.d/vboxadd") };
vars:
"install_me" slist => { "nmap", "htop", "samba", "samba-winbind", "gcc", "kernel-devel", "kernel-headers", "dkms", "make", "bzip2", "nautilu$
packages:
mac_08_00_27_6d_9f_fe::
"$(install_me)"
package_policy => "add",
package_method => yum;
#In this section I am making decisions about a host based on its mac address
files:
mac_08_00_27_6d_9f_fe::
#If the mac address matches, set the networking and hostname
"/etc/sysconfig/network"
create => "true",
edit_line => ChangeHost,
edit_defaults => empty;
"/etc/sysconfig/network-scripts/ifcfg-eth0"
create => "true",
edit_line => SetNetworking,
edit_defaults => empty;
#This command will execute only if the mac address AND the correct hostname are not found
#This is to ensure that the changes will take effect
commands:
mac_08_00_27_6d_9f_fe&!cfengineclient_stratus_sphere&!additions_installed::
"/usr/bin/yum update -y";
"/sbin/reboot";
mac_08_00_27_6d_9f_fe&!additions_installed::
"/bin/mount /dev/sr0 /mnt";
"/bin/sh /mnt/VBoxLinuxAdditions.run";
"/sbin/reboot";
}
bundle edit_line ChangeHost
{
#I emptied the file above and so I am now putting contents back in it
insert_lines:
"NETWORKING=yes";
"HOSTNAME=cfEngineClient.stratus-sphere";
}
bundle edit_line SetNetworking
{
#Insert the networking information
insert_lines:
"DEVICE=\"eth0\"
BOOTPROTO=\"static\"
HWADDR=08:00:27:6d:9f:fe
IPADDR=192.168.56.200
NM_CONTROLLED=\"yes\"
ONBOOT=yes
TYPE=\"Ethernet\"
NAME=\"System eth0\"";
}
For those interested, I have created syntax highlight (in basic form) for gedit
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!--
Author: Gustavo Giráldez <[email protected]>
Copyright (C) 2003 Gustavo Giráldez <[email protected]>
Copyright (C) 2004 Benoît Dejean <[email protected]>
Copyright (C) 2006 Steve Frécinaux <[email protected]>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
-->
<language id="cfengine" _name="CFEninge" version="2.0" _section="Scripts">
<metadata>
<property name="mimetypes">text/x-cfengine;application/x-cfengine</property>
<property name="globs">*.cf</property>
<property name="line-comment-start">#</property>
</metadata>
<styles>
<style id="module-handler" _name="Module Handler" map-to="def:preprocessor"/>
<style id="keyword" _name="Keyword" map-to="def:keyword"/>
<style id="multiline-string" _name="Multiline string" map-to="def:string"/>
<style id="string" _name="String" map-to="def:string"/>
<style id="escaped-char" _name="Escaped Character" map-to="def:special-char"/>
<style id="format" _name="Format" map-to="def:character"/>
<style id="string-conversion" _name="string-conversion"/>
<style id="special-variable" _name="Special Variable" map-to="def:identifier"/>
<style id="boolean" _name="Boolean" map-to="def:boolean"/>
<style id="floating-point" _name="Floating point number" map-to="def:floating-point"/>
<style id="decimal" _name="Decimal number" map-to="def:decimal"/>
<style id="base-n-integer" _name="Base-N number" map-to="def:base-n-integer"/>
<style id="complex" _name="Complex number" map-to="def:complex"/>
<style id="builtin-constant" _name="Builtin Constant" map-to="def:special-constant"/>
<style id="builtin-object" _name="Builtin Object" map-to="def:type"/>
<style id="builtin-function" _name="Builtin Function" map-to="def:builtin"/>
</styles>
<definitions>
<define-regex id="identifier">[_a-zA-Z][_a-zA-Z0-9]*</define-regex>
<define-regex id="number">[1-9][0-9]*</define-regex>
<!-- http://docs.cfengine.org/lib/typesseq-strings.html -->
<context id="format" style-ref="format" extend-parent="false">
<match extended="true">
% # leading % sign
\(\%{identifier}\)? # mapping key
[#0\-\ \+]* # conversion flags
(\-?\%{number}|\*)? # minimum field width
(\.(\-?\%{number}|\*))? # precision
(hlL)? # lentgh modifier
[diouxXeEfFgGcrs%] # conversion type
</match>
</context>
<!-- http://docs.cfengine.org/ref/strings.html -->
<context id="escaped-char" style-ref="escaped-char" extend-parent="true">
<match extended="true">
\\( # leading backslash
[\\'"abfnrtv] | # single escaped char
N\{[A-Z\ ]+\} | # named unicode character
u[0-9A-Fa-f]{4} | # xxxx - character with 16-bit hex value xxxx
U[0-9A-Fa-f]{8} | # xxxxxxxx - character with 32-bit hex value xxxxxxxx
x[0-9A-Fa-f]{1,2} | # \xhh - character with hex value hh
[0-7]{1,3} # \ooo - character with octal value ooo
)
</match>
</context>
<define-regex id="string-prefix">(u|U)?</define-regex>
<define-regex id="raw-string-prefix">(r|ur|R|UR|Ur|uR)</define-regex>
<context id="multiline-double-quoted-string" style-ref="multiline-string" class="string" class-disabled="no-spell-check">
<start>\%{string-prefix}"""</start>
<end>"""</end>
<include>
<context ref="format"/>
<context ref="escaped-char"/>
</include>
</context>
<context id="multiline-single-quoted-string" style-ref="multiline-string" class="string" class-disabled="no-spell-check">
<start>\%{string-prefix}'''</start>
<end>'''</end>
<include>
<context ref="format"/>
<context ref="escaped-char"/>
</include>
</context>
<context id="double-quoted-string" style-ref="string" end-at-line-end="true" class="string" class-disabled="no-spell-check">
<start>\%{string-prefix}"</start>
<end>"</end>
<include>
<context ref="format"/>
<context ref="escaped-char"/>
<context ref="def:line-continue"/>
</include>
</context>
<context id="single-quoted-string" style-ref="string" end-at-line-end="true" class="string" class-disabled="no-spell-check">
<start>\%{string-prefix}'</start>
<end>'</end>
<include>
<context ref="format"/>
<context ref="escaped-char"/>
<context ref="def:line-continue"/>
</include>
</context>
<context id="multiline-double-quoted-raw-string" style-ref="multiline-string" class="string" class-disabled="no-spell-check">
<start>\%{raw-string-prefix}"""</start>
<end>"""</end>
<include>
<context ref="format"/>
</include>
</context>
<context id="multiline-single-quoted-raw-string" style-ref="multiline-string" class="string" class-disabled="no-spell-check">
<start>\%{raw-string-prefix}'''</start>
<end>'''</end>
<include>
<context ref="format"/>
</include>
</context>
<context id="double-quoted-raw-string" style-ref="string" end-at-line-end="true" class="string" class-disabled="no-spell-check">
<start>\%{raw-string-prefix}"</start>
<end>"</end>
<include>
<context ref="format"/>
<context ref="def:line-continue"/>
</include>
</context>
<context id="single-quoted-raw-string" style-ref="string" end-at-line-end="true" class="string" class-disabled="no-spell-check">
<start>\%{raw-string-prefix}'</start>
<end>'</end>
<include>
<context ref="format"/>
<context ref="def:line-continue"/>
</include>
</context>
<context id="cfengine" class="no-spell-check">
<include>
<context ref="def:shebang"/>
<context ref="def:shell-like-comment"/>
<context ref="multiline-double-quoted-string"/>
<context ref="multiline-single-quoted-string"/>
<context ref="double-quoted-string"/>
<context ref="single-quoted-string"/>
<context ref="multiline-double-quoted-raw-string"/>
<context ref="multiline-single-quoted-raw-string"/>
<context ref="double-quoted-raw-string"/>
<context ref="single-quoted-raw-string"/>
<context id="string-conversion" style-ref="string-conversion" end-at-line-end="true">
<start>`</start>
<end>`</end>
<include>
<context ref="cfengine"/>
</include>
</context>
<context id="special-variables" style-ref="special-variable">
<prefix>(?<![\w\.])</prefix>
<keyword>self</keyword>
<keyword>__name__</keyword>
<keyword>__debug__</keyword>
</context>
<context id="boolean" style-ref="boolean">
<prefix>(?<![\w\.])</prefix>
<keyword>False</keyword>
<keyword>True</keyword>
</context>
<define-regex id="float" extended="true">
( (\d+)?\.\d+ | \d+\. ) |
( (\d+|(\d+)?\.\d+|\d+\.)[eE][+-]?\d+ )
</define-regex>
<context id="complex" style-ref="complex">
<match>(?<![\w\.])(\%{float}|\d+)[jJ]\b</match>
</context>
<context id="float" style-ref="floating-point">
<match>(?<![\w\.])\%{float}(?![\w\.])</match>
</context>
<context id="decimal" style-ref="decimal">
<match>(?<![\w\.])([1-9][0-9]*|0)[lL]?(?![\w\.])</match>
</context>
<context id="octal" style-ref="base-n-integer">
<match>(?<![\w\.])0[0-7]+[lL]?(?![\w\.])</match>
</context>
<context id="hex" style-ref="base-n-integer">
<match>(?<![\w\.])0[xX][0-9A-Fa-f]+[lL]?(?![\w\.])</match>
</context>
<context id="module-handler" style-ref="module-handler">
<keyword>import</keyword>
<keyword>from</keyword>
<keyword>as</keyword>
</context>
<context id="keyword" style-ref="keyword">
<keyword>bundle agent</keyword>
<keyword>bundle common</keyword>
<keyword>bundle sequence</keyword>
<keyword>bundle eddit_line</keyword>
<keyword>body common control</keyword>
<keyword>body control</keyword>
<keyword>body acl</keyword>
<keyword>body action</keyword>
<keyword>body changes</keyword>
<keyword>body classes</keyword>
<keyword>body contain</keyword>
<keyword>body copy_from</keyword>
<keyword>body delete</keyword>
<keyword>body depth_search</keyword>
<keyword>body edit_defaults</keyword>
<keyword>body edit_field</keyword>
<keyword>body file_select</keyword>
<keyword>body location</keyword>
<keyword>body match_value</keyword>
<keyword>lambda</keyword>
<keyword>body mount</keyword>
<keyword>body package_method</keyword>
<keyword>body perms</keyword>
<keyword>body process_count</keyword>
<keyword>body process_select</keyword>
<keyword>body rename</keyword>
<keyword>body replace_with</keyword>
<keyword>body service_method</keyword>
<keyword>body volume</keyword>
</context>
<context id="builtin-constants" style-ref="builtin-constant">
<prefix>(?<![\w\.])</prefix>
<keyword>Ellipsis</keyword>
<keyword>None</keyword>
<keyword>NotImplemented</keyword>
</context>
<context id="sequence_define" style-ref="keyword">
<match>[".*?"\s+(.*?)\s]</match>
</context>
<context id="builtin-objects" style-ref="builtin-object">
<prefix>(?<![\w\.])</prefix>
<keyword>AssertionError</keyword>
<keyword>any</keyword>
<keyword>cfengine</keyword>
</context>
<context id="builtin-function" style-ref="builtin-function">
<prefix>(?<![\w\.])</prefix>
<keyword>reports</keyword>
<keyword>classes</keyword>
<keyword>methods</keyword>
<keyword>vars</keyword>
<keyword>xrange</keyword>
<keyword>zip</keyword>
</context>
</include>
</context>
</definitions>
</language>
And a much better version for nano
Code:
## Here is an example for cfengine files
##
syntax "cfengine" "\.cf"
## String highlighting. You will in general want your comments and
## strings to come last, because syntax highlighting rules will be
## applied in the order they are read in.
icolor brightblue "def [0-9A-Z_]+"
#Declarations are denoted in red
color red "[^*]*[>]"
color yellow start="\<^(bundle)" end="(agent)\>|(common)\>|(edit_line)\>" start="\<^(body)" end="(control)\>|(acl)\>|(action)\>|(changes)\>|(classes)\>|(contain)\>|(copy_from)\>|(delete)\>|(depth_search)\>|(edit_defaults)\>|(edit_field)\>|(file_select)\>|(location)\>|(match_value)\>|(mount)\>|(package_method)\>|(perms)\>|(process_count)\>|(process_select)\>|(rename)\>|(replace_with)\>|(service_method)\>|(volume)\>"
##
color green "[^*]*[:]"
color cyan "[^>]*[;]"
color magenta "[(nt)]* [:space:]*$"
## Comment highlighting
color brightblue "["][^"]*[^\\]"