Monday, August 20, 2012

Capturing %Post Kickstart Install output

I found this very very useful in troubling my provisioning systems to find out what happend in the post install script output of kickstart.  The tee command is very useful for this.




%post --interpreter /bin/bash
(
scripting goes here

) |  2>&1 | tee /root/post-log.log

In your kickstart file add something like this.




%post --interpreter /bin/sh
(
# mount disk from the NFS server which contains support files
mkdir -p /mnt/tmp
mount nfs:volume /mnt/tmp
# run the top-level post-install script
cd /mnt/tmp
. ./postinstall.sh
cd /
# unmount the disk and delete the mount point
umount /mnt/tmp
rmdir /mnt/tmp )  2>&1 | tee /root/post-log.log
# post-installation script ends



Friday, August 3, 2012

Converting Pupppet User.pp to Chef User.json

For the last couple weeks my team and I have been looking at Chef.
We currently have medium size puppet deployment but wants to see if the grass is greener on the other side with chef. Chef seems to be allot more scripting where puppet is more of template based DSL.

Regardless One of the first hurdles we faced was migrating users from one to another
Here is a little perl to help anybody get past this hurdle.

*** Update *****

Ran into a little issue converting this with the GID so I took it out the useradd adds this for you so no need to do it.

./convert-to-chef.pl user.pp

It outputs it as user.json


###### Convert-to-chef.pl ################
#!/usr/bin/perl
use Switch;
$userfile = $ARGV[0];
open(USERFILE, "$userfile") or die $! ;
@lines = ;
foreach (@lines)
{
 $line = $_ ;
  switch ( $line )
  {

    case (/account/) {
                                   @account_line = split(/\{/,$line);
                              $account = $account_line[1];
                              $account =~ s/\,//g ;
                              $account =~ s/\://g ;
                              $account =~ s/\"//g ;
                              $account =~ s/\”//g ;
                              $account =~ s/\ //g ;
                              chomp($account);   
                         }

    case (/uid/) {
                                   @uid_line = split(/\>/, $line);
                              $uid = $uid_line[1];
                              $uid =~ s/\,//g ;
                              $uid =~ s/\ //g ;
                              chomp($uid);
                     }
    case (/gid/) {
                              @gid_line = split(/\>/, $line);
                             $gid = $gid_line[1] ;
                              $gid =~ s/\,//g ;
                              $gid =~ s/\ //g ;
                              chomp($gid);
                       }
    case (/comment/) {
                              @comment_array = split(/\>/, $line);
                              $comment = $comment_array[1];
                              $comment =~ s/\,//g ;
                              chomp($comment);
                            }
  }
}
close(USERFILE);

open(CHEFFILE, ">$account.json") or die $! ;

print CHEFFILE "
\{
  \"id\"\: \"$account\"\,
  \"uid\"\: \"$uid\"\,
  \"home_dir\"\: \"\/home\/$account\"\,
  \"group\"\: \"wheel\"\,
  \"shell\"\: \"\/bin\/bash\"\
\}
";
close(CHEFFILE);