<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>techslaves.org &#187; cfengine</title>
	<atom:link href="http://techslaves.org/tag/cfengine/feed/" rel="self" type="application/rss+xml" />
	<link>http://techslaves.org</link>
	<description>Owned (and fascinated) by technology!</description>
	<lastBuildDate>Thu, 23 Feb 2012 04:55:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>It has been a while&#8230;</title>
		<link>http://techslaves.org/2012/02/10/it-has-been-a-while/</link>
		<comments>http://techslaves.org/2012/02/10/it-has-been-a-while/#comments</comments>
		<pubDate>Sat, 11 Feb 2012 00:40:21 +0000</pubDate>
		<dc:creator>rthomson</dc:creator>
				<category><![CDATA[Sysadmin]]></category>
		<category><![CDATA[cfengine]]></category>
		<category><![CDATA[job]]></category>
		<category><![CDATA[life]]></category>
		<category><![CDATA[new]]></category>
		<category><![CDATA[professional]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://techslaves.org/?p=190</guid>
		<description><![CDATA[It has been a while since I last expressed myself and shared thoughts with the world via techslaves.org. Time to change that. So what is new? For the first time in 5.5 years, I am single and living totally, utterly alone. This is a big change that I am learning to deal with day by [...]
No related posts.]]></description>
			<content:encoded><![CDATA[<p>It has been a while since I last expressed myself and shared thoughts with the world via techslaves.org. Time to change that.</p>
<p>So what is new?</p>
<p>For the first time in 5.5 years, I am single and living totally, utterly alone. This is a big change that I am learning to deal with day by day.  Thankfully, I find myself busy enough that there isn&#8217;t a lot of downtime for me to dwell on negativity. I have challenged myself to use this as an opportunity to self-evaluate and change the things that I find which I do not like. I call it &#8220;Continuous Improvement&#8221;.</p>
<p>I recently achieved my goal of commuting by bicycle for 100 consecutive work days. I then promptly took several days off due to a series of crashes caused by the &#8220;winter&#8221; conditions here that quickly fade away. I&#8217;m now back in the saddle riding everyday and it feels great. 22km of cycling a day does the body good.</p>
<p>Professionally, my interest in cfengine and IT operations has been steadily increasing.</p>
<p>My adventures with cfengine have led to much pondering over the &#8220;meta topics&#8221; of configuration management such as the release management aspect (version controlled workflow for updating, authorizing and installing policy) and policy writing best practices such as file copy vs. file edit and policy layout/design. It is these meta topics that I find most immediately challenging when considering cfengine deployment. Learning from others, I have developed a release management workflow of sorts. Perhaps it will eventually be of quality enough to share.</p>
<p>With regards to IT operations, I&#8217;ve been invigorated by the LISA &#8217;11 talks available on YouTube. These talks exposed me to several (new-ish and old) books and authors that I am now exploring and enjoying. Some favorites so far are <em>&#8220;The Visible Ops Handbook&#8221;</em> and <em>&#8220;Future Shock&#8221;. </em>I am just getting started with <em>&#8220;Lean IT&#8221;</em>.</p>
<p>Speaking of LISA, I am now registered for the <a href="http://casitconf.org">Cascadia IT Conference</a> held March 23 and 24th this year in Seattle, WA. I am super excited to meet my fellow LOPSA members (and semi-local sysadmins) that I normally only interact with via the #lopsa and #lopsa-lounge IRC channels! Hopefully the employer professional development funds can cover the registration fees&#8230; but the conference is so close to fiscal year-end and the fund might be exhausted before HR reviews my application for reimbursement. Fingers crossed.</p>
<p>Aside from new interests in system administration but remaining in the professional sphere, there is also an excellent potential opportunity for a new position with my current employer available to me. I don&#8217;t regard anything as set in stone so tonight I will gear up and put in my application ASAP. Some very excellent key people are waiting for it to hit their desks and I will not disappoint!</p>
<p>I will make no promises with regards to new content&#8230; but let it be known, techslaves.org lives!</p>
<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://techslaves.org/2012/02/10/it-has-been-a-while/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cfengine 3 Snippets Part 2: sudo</title>
		<link>http://techslaves.org/2010/10/02/cfengine-3-snippets-part-2-sudo/</link>
		<comments>http://techslaves.org/2010/10/02/cfengine-3-snippets-part-2-sudo/#comments</comments>
		<pubDate>Sat, 02 Oct 2010 02:59:42 +0000</pubDate>
		<dc:creator>rthomson</dc:creator>
				<category><![CDATA[Sysadmin]]></category>
		<category><![CDATA[cfengine]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[policy]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[sudo]]></category>

		<guid isPermaLink="false">http://techslaves.org/?p=87</guid>
		<description><![CDATA[It&#8217;s been a while since I&#8217;ve really had time to delve too much further into cfengine 3 since my previous post on the subject way back in May but I do have another simple example to share. This time it&#8217;s about managing your sudo policy via the sudoers file. The example is that of a very, [...]
Related posts:<ol>
<li><a href='http://techslaves.org/2010/05/18/cfengine-3-snippets-part-1-denyhosts/' rel='bookmark' title='Cfengine 3 Snippets Part 1: DenyHosts'>Cfengine 3 Snippets Part 1: DenyHosts</a></li>
<li><a href='http://techslaves.org/2010/03/29/nanorcs/' rel='bookmark' title='Nanorcs: Ultrasimplistic Configuration File Revision Control'>Nanorcs: Ultrasimplistic Configuration File Revision Control</a></li>
<li><a href='http://techslaves.org/2010/05/07/rhelcentos-nfs-and-firewalls/' rel='bookmark' title='RHEL/CentOS, NFS and Firewalls'>RHEL/CentOS, NFS and Firewalls</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been a while since I&#8217;ve really had time to delve too much further into cfengine 3 since my <a href="http://techslaves.org/2010/05/18/cfengine-3-snippets-part-1-denyhosts/">previous post</a> on the subject way back in May but I do have another simple example to share. This time it&#8217;s about managing your sudo policy via the <em>sudoers</em> file.</p>
<p>The example is that of a very, very basic <em>sudoers</em> policy but the principles are easily extended to create much more complex policy. The general idea here is that we want cfengine to ensure that specific rules are always in place. Instructed properly, cfengine accomplishes this very well.</p>
<p>Warning: I don&#8217;t know anything. I&#8217;m just someone learning cfengine 3 and posting about it. If I&#8217;m wrong about something, let me know! If you find this at all useful, be my guest. That is all.</p>
<p><span id="more-87"></span></p>
<pre>################################################################################
##
## FILE: sudo.cf
## DESC: Control /etc/sudoers file on various servers
##
################################################################################

bundle agent sudo
{

vars:

  "sudoers" string =&gt; "/etc/sudoers";

  "sudo"     slist =&gt; {
                      "%admin ALL = ALL",
                      "%sysadmin ALL = /sbin/mount",
                      "%devel ALL = /sbin/mount"
                      };

packages:

  Night::

  "sudo" -&gt; "Security policy"
    comment               =&gt; "Ensure sudo is up to date every 24 hours (and only at night)",
    package_policy        =&gt; "update",
    package_method        =&gt; yum,
    package_architectures =&gt; { "$(sys.arch)" },
    action                =&gt; if_elapsed("1440");

files:

  "$(sudoers)" -&gt; "Security Policy"
    comment      =&gt; "Append common configuration to sudoers",
    edit_line    =&gt; append_if_no_lines("$(sudo)");

}</pre>
<p>As with last snippet I posted, the above does not even resemble a complete cfengine policy/configuration, just a small portion that can be contained in it&#8217;s own bundle. It can be put in a separate .cf file, imported by promises.cf and added to the bundle sequence, inheriting variables and classes! Also, just like last time I&#8217;m using cfengine&#8217;s built in interface for package management systems to ensure &#8220;sudo&#8221; is always installed via yum at night, every 24 hours.</p>
<p>What&#8217;s new here is file editing with <em>edit_line</em> and the use of iteration which proves to be very powerful in cfengine 3.</p>
<h2>Editing Files</h2>
<p>Editing files with cfengine is supposed to be easy but initially it seemed a bit awkward to me.</p>
<p>First you have the promise file promise:</p>
<pre>files:

  "$(sudoers)" -&gt; "Security Policy"
    comment      =&gt; "Append common configuration to sudoers",
    edit_line    =&gt; append_if_no_lines("$(sudo)");</pre>
<p>Which makes some reference to the <em>edit_line</em> facility and what looks like a function name with <em>append_if_no_lines(&#8230;)</em>.</p>
<p>Then you have the <em>edit_line</em> bundle defined elsewhere:</p>
<pre>bundle edit_line append_if_no_lines(list)
{
insert_lines:

 "$(list)";
}</pre>
<p>Which describes what &#8220;append_if_no_lines&#8221; actually does.</p>
<p>Of course I&#8217;m just learning cfengine and new things can often seem strange and scary but I am finally warming up to editing files with cfengine&#8230; I think. What I seemed to have initial trouble with was with the <em>bundles</em> necessary for <em>edit_lines</em>, as described above. The bundle within a bundle concept. The <em>append_if_no_lines</em> and <em>append_if_no_line</em> bundles I&#8217;m using are implemented in the <a href="http://www.cfengine.org/manuals/cfengine_stdlib.cf">cfengine std library</a>, which is highly recommended so that you may avoid re-inventing the wheel a little bit.</p>
<p>For basic promises, to add or remove, comment or uncomments lines and the such there are good <em>edit_lines</em> bundles available in the stdlib. For other more complex or customized file editing, writing your own bundles will be necessary. Either way, understanding what a <em>bundle</em> is and how to create your own is key to fully grasping file editing and getting the most out of it. This seems obvious in retrospect but something I didn&#8217;t pickup instantly.</p>
<p>See the cfengine documentation for more about editing files, check the cfengine documentation. There&#8217;s waaaaay more good information over there and it&#8217;s from the cfengine team, not some random newb.</p>
<h2><strong>Iteration</strong></h2>
<p>Iteration is powerful mechanism within cfengine that harnesses the power of lists to express a large possible number of actions/operations with very little amount of code. When lists are used, single actions can be made to repeat for every item in a list by using the <em>$(varname)</em> syntax to refer to the list&#8230; which as it turns out is the same for scalar values! Funny that!</p>
<p>So cfengine allows us to define X different lines of code to ensure are in a file using only a single <em>file:</em> promise all with the same simple syntax as scalar variables? Brilliant!</p>
<p>A demonstration of iteration can be seen with the <em>$(sudo)</em> slist and the &#8220;Append common configuration to sudoers&#8221; <em>file:</em> promise. With this single promise definition, <em>up to</em> 6 actual promises are made because the <em>$(sudo)</em> variable is an slist. Each element or item in the list is iterated over in sequence and the promise is evaluated and acted upon, if necessary. The reason that <em>up to</em> 6 promises will be evaluated is the <em>ifvarclass</em> property of promise, ensuring the promise will only be kept if we&#8217;re in the context of the class&#8230; and looking at the promise to find out which class, we see another example of iteration using the <em>$(sudo)</em> list and the <em>canonify</em> function that turns a string into a class. Thusly, if the host currently running this policy defines all the classes that are tested by the <em>ifvarclass</em> iteration, 6 promises will be made. If the host defines 3 of the classes, then 3 promises will be made and so on, and so forth.</p>
<p>As a beginner, using lists and iteration effectively and creatively seems fairly important to getting the most out of cfengine 3.</p>
<h2>Editing Files vs. Copying Files</h2>
<p>In my previous snippet, I demonstrated how to promise to copy a file from a secure remote server if the local file does not match the server&#8217;s file in order to manage a configuration with cfengine. This time, I&#8217;m promising to add lines to a configuration file if they do not already exist exactly as provided.</p>
<p>This represents two rather different takes on policy. The first says: &#8220;The configuration must always be exactly like this file, byte per byte!&#8221; the second says &#8220;These lines must exist but I don&#8217;t care about anything else in the file&#8221;. The file copy method is what I would call hard policy and the second is soft policy. In the cfengine community solutions, they recommend managing sudo by copying an <em>/etc/sudoers</em> from a remote server. That way is great (just like my DenyHosts example) but this is just another way if you have a use case for cfengine not owning every byte of your configuration file.</p>
<h2>Conclusion</h2>
<p>Yeah, that&#8217;s about it. Enjoy.</p>
<p>Related posts:<ol>
<li><a href='http://techslaves.org/2010/05/18/cfengine-3-snippets-part-1-denyhosts/' rel='bookmark' title='Cfengine 3 Snippets Part 1: DenyHosts'>Cfengine 3 Snippets Part 1: DenyHosts</a></li>
<li><a href='http://techslaves.org/2010/03/29/nanorcs/' rel='bookmark' title='Nanorcs: Ultrasimplistic Configuration File Revision Control'>Nanorcs: Ultrasimplistic Configuration File Revision Control</a></li>
<li><a href='http://techslaves.org/2010/05/07/rhelcentos-nfs-and-firewalls/' rel='bookmark' title='RHEL/CentOS, NFS and Firewalls'>RHEL/CentOS, NFS and Firewalls</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://techslaves.org/2010/10/02/cfengine-3-snippets-part-2-sudo/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Cfengine 3 Snippets Part 1: DenyHosts</title>
		<link>http://techslaves.org/2010/05/18/cfengine-3-snippets-part-1-denyhosts/</link>
		<comments>http://techslaves.org/2010/05/18/cfengine-3-snippets-part-1-denyhosts/#comments</comments>
		<pubDate>Tue, 18 May 2010 22:02:09 +0000</pubDate>
		<dc:creator>rthomson</dc:creator>
				<category><![CDATA[Sysadmin]]></category>
		<category><![CDATA[cfengine]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[denyhosts]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[snippet]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://techslaves.org/?p=63</guid>
		<description><![CDATA[I&#8217;ve recently begun looking into configuration management with cfengine 3. I&#8217;ve ignored this growing sub-field of system administration for too long and I just can&#8217;t ignore it anymore. After spending quite some time researching the philosophies, methods and different tools out there, I settled on starting out with cfengine 3. There&#8217;s no special reason that [...]
Related posts:<ol>
<li><a href='http://techslaves.org/2010/10/02/cfengine-3-snippets-part-2-sudo/' rel='bookmark' title='Cfengine 3 Snippets Part 2: sudo'>Cfengine 3 Snippets Part 2: sudo</a></li>
<li><a href='http://techslaves.org/2010/05/07/rhelcentos-nfs-and-firewalls/' rel='bookmark' title='RHEL/CentOS, NFS and Firewalls'>RHEL/CentOS, NFS and Firewalls</a></li>
<li><a href='http://techslaves.org/2010/03/29/nanorcs/' rel='bookmark' title='Nanorcs: Ultrasimplistic Configuration File Revision Control'>Nanorcs: Ultrasimplistic Configuration File Revision Control</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve recently begun looking into configuration management with <a href="http://cfengine.org">cfengine 3</a>. I&#8217;ve ignored this growing sub-field of system administration for too long and I just can&#8217;t ignore it anymore. After spending quite some time researching the philosophies, methods and different tools out there, I settled on starting out with cfengine 3. There&#8217;s no special reason that I chose cfengine instead of puppet, bcfg2, chef or AutomateIT. I haven&#8217;t used any of these tools and thus I cannot pass judgement on them or their methods. All these projects seem to have intelligent and highly motivated people behind them. I simply gravitated towards cfengine because of its strong academic background and the fact that version 3 now represents the most recent and modern research in the field by Mark Burgess et. al.</p>
<p>As part of my learning experience with cfengine, I&#8217;ve decided to start posting some of the code that I&#8217;ve begun developing in the hopes that by writing about it, I can learn better, faster and maybe even receive some helpful comments from readers along the way. Beware, I&#8217;m a cfengine newbie and so what I post here should NOT be copy and pasted into your environment unless you&#8217;re ok with the potential of wildly breaking things!</p>
<p>The first snippet of code I want to discuss is related to managing our <a href="http://denyhosts.sourceforge.net/">DenyHosts</a> configuration. As part of our &#8220;security policy&#8221;, I would like to ensure that every RedHat/CentOS system is running a properly configured DenyHosts instance. Here is what I&#8217;ve come up with so far.</p>
<p><span id="more-63"></span></p>
<pre>################################################################################
#
# FILE: denyhosts.cf
# DESC: Install, update, configure and ensure DenyHosts is running
# DATE: May 2010
#
#################################################################################

bundle agent denyhosts
{

packages:

  "denyhosts" -&gt; "Security policy"
    comment               =&gt; "Ensure denyhosts is installed once a week",
    package_policy        =&gt; "add",
    package_method        =&gt; yum,
    package_architectures =&gt; { "noarch" },
    action                =&gt; if_elapsed("10080");

  Night::

  "denyhosts" -&gt; "Security policy"
    comment               =&gt; "Check for update to denyhosts every 24 hours (and only at night)",
    package_policy        =&gt; "update",
    package_method        =&gt; yum,
    package_architectures =&gt; { "noarch" },
    action                =&gt; if_elapsed("1440");

files:

  "/etc/denyhosts.conf" -&gt; "Security policy"
    comment   =&gt; "Standard base DenyHosts configuration",
    copy_from =&gt; mycopy("$(g.confdir)/denyhosts/denyhosts.conf", "$(g.cfserver)"),
    classes   =&gt; cdefine("denyhosts_restart", "denyhosts_conf_copy_failed"),
    perms     =&gt; mo("400", "root"),
    action    =&gt; if_elapsed("1440");

processes:

  "python /usr/bin/denyhosts.py" -&gt; "Security policy"
    comment       =&gt; "Define denyhosts_restart class if denyhost is NOT running",
    restart_class =&gt; canonify("denyhosts_restart");

commands:

  "/sbin/service denyhosts restart" -&gt; "Security policy"
     comment    =&gt; "Restarting DenyHosts after configuration change or death",
     ifvarclass =&gt; canonify("denyhosts_restart");

}</pre>
<p>If you&#8217;re familiar with cfengine at all, you&#8217;ll quickly realize this is not a complete configuration. I am relying on the cfengine standard library for several body definitions as well as custom site variables defined in the common bundle named &#8220;g&#8221; (not shown). And of course, there are no control bodies, bundlesequence or many other things that make up a complete cfengine configuration, hence &#8220;snippet&#8221;.</p>
<p>Let&#8217;s ignore what&#8217;s lacking for now and focus on the meat of the promises.</p>
<h3>Packages</h3>
<p>The first part of the denyhosts bundle is dealing with packages. I&#8217;m making two promises regarding the &#8220;denyhosts&#8221; package. The first promise is that the package has been added to the system via yum and the second is that the package is up to date via yum. I&#8217;m not entirely clear on how to best manage promises like this yet so perhaps I&#8217;m missing some cute shorthand for both adding and keeping packages up to date. For now, I&#8217;ll stick with two separate promises.</p>
<p>You&#8217;ll also notice that I&#8217;m only checking to see if the package is installed once a week (via action =&gt; if_elapsed) and only checking to see if the package is up to date once every 24 hours (if_elapsed, again). The update promise is also subject to the Night class to ensure that package updates only occur at night and not during the work day. This is just a matter of preference. I&#8217;d prefer if updates occur at night, you may not.</p>
<p>Since I&#8217;m using a &#8220;smart&#8221; package manager to ensure that denyhosts is installed, I can count on having yum resolve any dependencies (such as python) for me automatically. I would loath to describe every dependency for every package I want control over by hand.</p>
<h3>Files</h3>
<p>There is only one file that I&#8217;m concerned with when it comes to denyhosts and that is the denyhosts configuration file in /etc/denyhosts.conf. Instead of doing file edits on the default denyhosts.conf file provided in the denyhosts packages that I&#8217;ve promised to install, I simply copy a pre-defined configuration from my cfengine server. This file has our site&#8217;s default denyhosts configuration all ready to go. If I needed to customize the configuration on a per-host or per-host-type basis, I could copy the base file to a temporary location then perform edits on the temp file and write out the changes to the final location of the default configuration file or simply maintain several pre-configured versions of denyhosts.conf and copy the appropriate file.</p>
<p>Also of note about files is that if the file promise must be repaired (if the file must be copied because it&#8217;s changed), I&#8217;m setting a class to be defined so that DenyHosts can be restarted. More on that later.</p>
<h3>Processes</h3>
<p>In this case, I&#8217;m only checking to see if the DenyHosts python process is running or not. If DenyHosts is running, we do nothing. If DenyHosts is not running, we define a class using the same name as the class we define if we have to copy the configuration file.</p>
<h3>Commands</h3>
<p>Finally, in the commands section we tell cfengine how and when to restart DenyHosts. If the &#8220;denyhosts_restart&#8221; class is defined, we instruct cfengine to restart DenyHosts with the &#8220;/sbin/service denyhosts restart&#8221; command. The canonify and cdefine special functions in cfengine provide a very powerful way of defining some rather complex relationships.</p>
<h3>What is Missing?</h3>
<p>Well, probably <em>a lot</em> of stuff. One obvious thing is that I&#8217;m not promising that DenyHosts is set to startup at boot time using the hosts&#8217; native init system. Of course, this shouldn&#8217;t be a big deal because cfengine will start it up if it&#8217;s not running at the next cf-agent run, but perhaps it would be nice to make that promise anyways.</p>
<p>I&#8217;m also not using many (or any!) classes to limit the scope of where (to what hosts) these promises will apply. Right now, I&#8217;m just working with a test environment so it&#8217;s easy to get away with that but I&#8217;m learning that it&#8217;s good to be as explicit at possible from the start when building promises.</p>
<p><strong>UPDATE:</strong> Ah, how could I forget.. Reporting is totally missing! I knew I was setting some of those classes for a reason. In the next installment, I&#8217;ll include the most basic of reporting functionality.</p>
<p>I think that&#8217;s all for now. Please critique my amateur use of cfengine 3 in the comments, I want to hear from you!</p>
<p>Related posts:<ol>
<li><a href='http://techslaves.org/2010/10/02/cfengine-3-snippets-part-2-sudo/' rel='bookmark' title='Cfengine 3 Snippets Part 2: sudo'>Cfengine 3 Snippets Part 2: sudo</a></li>
<li><a href='http://techslaves.org/2010/05/07/rhelcentos-nfs-and-firewalls/' rel='bookmark' title='RHEL/CentOS, NFS and Firewalls'>RHEL/CentOS, NFS and Firewalls</a></li>
<li><a href='http://techslaves.org/2010/03/29/nanorcs/' rel='bookmark' title='Nanorcs: Ultrasimplistic Configuration File Revision Control'>Nanorcs: Ultrasimplistic Configuration File Revision Control</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://techslaves.org/2010/05/18/cfengine-3-snippets-part-1-denyhosts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

