Tuesday, June 30, 2015

Creating puppetlab with vagrant and bash shell

#To create puppetlab environment, we need to first install virtualbox and vagrant.(Each virtualbox.org and vagrangup.com).

#Vagrantfile use bash(other shell?) shell to install update guest os as in Linux servers such as centos, debian and ubuntu.
#Here is my Vagrantfile.
# Wee need to first create vagrant box. We can obtain those boxes from "https://atlas.hashicorp.com/boxes/search". Or we can create box on our own.

I made boxes on my filesystem like belows.


whatsup@whatsup-To-be-filled-by-O-E-M ~/deploy_rails $ ls ../vg/*.box
../vg/apm.box  ../vg/centos70.box  ../vg/package.box  ../vg/ubuntu14.box

My humble article shortly explained.
http://wnapdlf.blogspot.kr/2014/12/vagrant-packaging.html

#Here is my Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

  config.vm.define "puppetmaster" do |puppetmaster|
   puppetmaster.vm.box = "puppetmaster"
   puppetmaster.vm.box_url = "file:///home/whatsup/vg/ubuntu14.box"
   puppetmaster.vm.provision "shell", inline: "echo now time to executing shell"
   puppetmaster.vm.provision "shell", inline: "echo timezone config; echo 'Asia/Seoul' > /etc/timezone && dpkg-reconfigure --frontend noninteractive tzdata"
   puppetmaster.vm.provision "shell", :path => "install-puppet-master.sh"
   puppetmaster.vm.network "private_network",ip:"10.1.0.2"
        #virtualbox__nat: false
   puppetmaster.vm.host_name = "puppetmaster"
      puppetmaster.vm.provider :virtualbox do |vb|
        vb.customize ["modifyvm", :id,"--memory","1024"]
      end
   end


  config.vm.define "puppetclient1" do |puppetclient1|
   puppetclient1.vm.box = "puppetclient1"
   puppetclient1.vm.box_url = "file:///home/whatsup/vg/ubuntu14.box"
   puppetclient1.vm.provision "shell", :path => "install-puppet-node.sh"
   puppetclient1.vm.provision "shell", inline: "echo now time to executing shell"
   puppetclient1.vm.provision "shell", inline: "echo timezone config; echo 'Asia/Seoul' > /etc/timezone && dpkg-reconfigure --frontend noninteractive tzdata"
   puppetclient1.vm.provision "shell", inline: "apt-get update && apt-get upgrade"
   puppetclient1.vm.network "private_network",ip:"10.1.0.3"
   puppetclient1.vm.host_name = "puppetclient1"
      puppetclient1.vm.provider :virtualbox do |vb|
        vb.customize ["modifyvm", :id,"--memory","1024"]
      end
   end

  config.vm.define "puppetclient2" do |puppetclient2|
   puppetclient2.vm.box = "puppetclient2"
   puppetclient2.vm.box_url = "file:///home/whatsup/vg/ubuntu14.box"
   puppetclient2.vm.provision "shell", :path => "install-puppet-node.sh"
   puppetclient2.vm.provision "shell", inline: "echo now time to executing shell"
   puppetclient2.vm.provision "shell", inline: "echo timezone config; echo 'Asia/Seoul' > /etc/timezone && dpkg-reconfigure --frontend noninteractive tzdata"
   puppetclient2.vm.provision "shell", inline: "apt-get update && apt-get upgrade"
   puppetclient2.vm.network "private_network",ip:"10.1.0.4"
   puppetclient2.vm.host_name = "puppetclient2"
      puppetclient2.vm.provider :virtualbox do |vb|
        vb.customize ["modifyvm", :id,"--memory","256"]
        vb.cpus = 1
      end
   end



  config.vm.define "puppetclient3" do |puppetclient3|
   puppetclient3.vm.box = "puppetclient3"
   puppetclient3.vm.box_url = "file:///home/whatsup/test/package.box"
   puppetclient3.vm.provision "shell", :path => "install-puppet-node.sh"
   puppetclient3.vm.provision "shell", inline: "echo now time to executing shell"
   puppetclient3.vm.provision "shell", inline: "echo timezone config; echo 'Asia/Seoul' > /etc/timezone && dpkg-reconfigure --frontend noninteractive tzdata"
   puppetclient3.vm.provision "shell", inline: "apt-get update && apt-get upgrade"
   puppetclient3.vm.network "private_network",ip:"10.1.0.5"
   puppetclient3.vm.host_name = "puppetclient3"
      puppetclient3.vm.provider :virtualbox do |vb|
        vb.customize ["modifyvm", :id,"--memory","256"]
        vb.cpus = 1
      end
   end

end



  config.vm.define "centos7-puppet-client" do |ct7|
   ct7.vm.box = "ct7"
   ct7.vm.box_url = "file:///home/whatsup/vg/centos7-puppet-client0.box"
   ct7.vm.provision "shell", :path => "install-puppet-centos7.sh"
   ct7.vm.provision "shell", inline: "echo now time to executing shell"
   ct7.vm.provision "shell", inline: "echo timezone config; timedatectl set-timezone Asia/Seoul"
   ct7.vm.network "private_network", ip:"10.1.0.6"
   ct7.vm.host_name = "centos7-puppet-client"
     ct7.vm.provider :virtualbox do |vb|
      vb.customize ["modifyvm", :id, "--memory", "256"]
     end
  end
 

#And shell script that are inserted into Vagrantfile are as follows.
#!/usr/bin/env bash

remove(){
  #remove previous packages
  apt-get remove --purge -y puppet*
}

check(){
   RV=$?
   if  [[ $RV != "0" ]]
   then
       echo -e "\e[31m $JOB failed please check"
       exit $RV
   else
       echo -e "\e[34m $JOB successful"
   fi

}

 

check_remove(){
   /usr/bin/which puppet
   sudo rm -rf /var/log/puppet
   JOB="puppet remove check on ubuntu14.04 trusty"
   check
}




install(){
   #install trusty puppet-package
   wget https://apt.puppetlabs.com/puppetlabs-release-trusty.deb
   sudo dpkg -i puppetlabs-release-trusty.deb
   sudo apt-get update -y
   JOB="INSTALLING PUPPET REPO UBUNTU TRUSTY14.04"
   check

}

install_master(){
   sudo apt-get install puppetmaster-passenger -y
   JOB="INSTALLING PUPPET MASTER"
   check
}

#puppet package install for puppet master
remove
check_remove
install
install_master
whatsup@whatsup-To-be-filled-by-O-E-M ~/deploy_rails $ cat install-puppet-node.sh
#!/usr/bin/env bash

remove(){
  #remove previous packages
  sudo apt-get remove --purge -y puppet*
}

check(){
   RV=$?
   if  [[ $RV != "0" ]]
   then
       echo -e "\e[31m $JOB failed please check"
       exit $RV
   else
       echo -e "\e[34m $JOB successful"
   fi
}
 

check_remove(){
   /usr/bin/which puppet
   sudo rm -rf /var/log/puppet
   JOB="puppet remove check on ubuntu14.04 trusty"
   check
}


install(){
   #install trusty puppet-package
   wget https://apt.puppetlabs.com/puppetlabs-release-trusty.deb
   sudo dpkg -i puppetlabs-release-trusty.deb
   sudo apt-get update -y
   JOB="INSTALLING PUPPET REPO UBUNTU TRUSTY14.04"
   check
}

install_node(){
   sudo apt-get install puppet -y
   JOB="INSTALLING PUPPET NODE"
   check
}

#puppet package install for puppet master
remove
check_remove
install
install_node

whatsup@whatsup-To-be-filled-by-O-E-M ~/deploy_rails $ cat install-puppet-centos7.sh
#!/usr/bin/env bash

remove(){
  #remove previous packages
  sudo yum remove  -y puppet*
}

check(){
   RV=$?
   if  [[ $RV != "0" ]]
   then
       echo -e "\e[31m $JOB failed please check"
       exit $RV
   else
       echo -e "\e[34m $JOB successful"
   fi
}
 

check_remove(){
   /usr/bin/which puppet
   sudo rm -rf /var/log/puppet
   JOB="puppet remove check on centos7 "
   check
}


install_repo(){
   #install centos7 puppet-package
    sudo rpm -ivh http://yum.puppetlabs.com/puppetlabs-release-el-7.noarch.rpm

   sudo yum update -y
   JOB="INSTALLING PUPPET REPO centos7"
   check
}

install_puppet(){
   #install puppet with yum
   sudo yum install puppet
   JOB="INSTALLING PUPPET REPO centos7"
   check
}

###If everything prepared, vagrant up command will make up basic puppetlab###


### I wrote master and node setup on my blog###
http://wnapdlf.blogspot.kr/2015/06/puppet-master-and-node-configuration.html




No comments:

Post a Comment