<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Ansible on Madprof&#39;s workshop</title>
    <link>http://www.madprof.net/tags/ansible/</link>
    <description>Recent content in Ansible on Madprof&#39;s workshop</description>
    <generator>Hugo</generator>
    <language>en</language>
    <lastBuildDate>Fri, 21 Mar 2014 11:16:00 +0000</lastBuildDate>
    <atom:link href="http://www.madprof.net/tags/ansible/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>LVM snapshots for a resetable machine</title>
      <link>http://www.madprof.net/2014/03/21/lvm-snapshots-for-a-resetable-machine/</link>
      <pubDate>Fri, 21 Mar 2014 11:16:00 +0000</pubDate>
       <guid isPermaLink="false">https://blog.madprof.net/?p=313</guid> 
      <description>&lt;p&gt;I have ended up maintaining a few websites which we are hosting on a machine off in Germany somewhere.&lt;/p&gt;
&lt;p&gt;I want to get everything automated, so I have less work to do if something goes wrong.&lt;/p&gt;
&lt;p&gt;I&amp;rsquo;m using ansible, which is wonderful, and have a nice set of playbooks I&amp;rsquo;ve written which take a raw CentOS install, and install everything, (php-fpm, nginx, etc&amp;hellip;) set up the virtualhosts, install wordpress &amp;amp; joomla and all that for the sites that need it, etc.&lt;/p&gt;
&lt;p&gt;Until today, I&amp;rsquo;ve been using a virtualbox on my local computer to test on, and it works great.  I haven&amp;rsquo;t bothered with vagrant, as I tried it for a couple of days, and it crashed my whole computer twice, so I gave up.  With virtualbox, it&amp;rsquo;s almost as simple.  I have a virtualmachine which I can spin up, install stuff on, and then when I want to go back to a fresh machine, it&amp;rsquo;s a matter of turning it off, and clicking &amp;lsquo;restore snapshot&amp;rsquo; to the snapshot I made when it was clean installed.&lt;/p&gt;
&lt;p&gt;It&amp;rsquo;s practically instant, and just works.&lt;/p&gt;
&lt;p&gt;However, running a virtualmachine on my primary work computer all the time does make everything else somewhat sluggish.  So I&amp;rsquo;ve scrouged an old computer that wasn&amp;rsquo;t doing anything, and am now using that instead.&lt;/p&gt;
&lt;p&gt;In order to get snapshots and restore points going well, here&amp;rsquo;s how I did it:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Install CentOS, leaving a bunch of free space on the LVM primary group.&lt;/li&gt;
&lt;li&gt;Make a snapshot when it&amp;rsquo;s first installed&lt;/li&gt;
&lt;li&gt;Restore (merge to) that snapshot whenever I want it back to original settings.&lt;/li&gt;
&lt;li&gt;Reboot&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;To make &amp;amp; restore the snapshots, I&amp;rsquo;ve written the commands as scripts so I don&amp;rsquo;t have to remember the lg-whatever stuff. (vg_localtest is the name of the volume group I set up for the HD when I installed):&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;/usr/sbin/snapshot_make&lt;/strong&gt;:&lt;/p&gt;
&lt;p&gt;#!/bin/sh&lt;br&gt;
lvcreate &amp;ndash;size 100G -s -n original_snapshot /dev/vg_localtest/root&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;/usr/sbin/snapshot_restore&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;#/bin/sh&lt;br&gt;
lvconvert &amp;ndash;merge /dev/vg_localtest/original_snapshot &amp;amp;&amp;amp; reboot&lt;/p&gt;
&lt;p&gt;It works great so far.  One improvement I&amp;rsquo;m making, since I one time forgot to make a snapshot, and so couldn&amp;rsquo;t restore to a blank slate without re-installing the whole thing (which, admittedly, only takes half an hour or so):&lt;/p&gt;
&lt;p&gt;I&amp;rsquo;m adding &amp;lsquo;snapshot_make&amp;rsquo; into a boot script, and then modifying it to remove itself from the bootscript once it&amp;rsquo;s made the snapshot.  That way as soon as the machine reboots into it&amp;rsquo;s original snapshot, it will automatically re-create the snapshot.&lt;/p&gt;
&lt;p&gt;This looks like:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;/usr/sbin/snapshot_make&lt;/strong&gt;:&lt;/p&gt;
&lt;p&gt;#!/bin/sh&lt;br&gt;
lvcreate &amp;ndash;size 100G -s -n original_snapshot /dev/vg_localtest/root&lt;br&gt;
sed -ine &amp;lsquo;/snapshot/d&amp;rsquo; /etc/rc.local&lt;/p&gt;
&lt;p&gt;and then &lt;strong&gt;/etc/rc.local&lt;/strong&gt; will look like:&lt;/p&gt;
&lt;p&gt;#&amp;hellip; whatever it has&lt;br&gt;
/usr/sbin/snapshot_make&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
