Auto deploy Puppet Agent


Continue with my previous Puppet and Puppet dashboard installation, now I start to deploy the agent to all my Ubuntu desktops. I wrote a script to do the dirty work.
Pre-requisite package: expect (no need if use passwordless ssh, but you need to change the script slightly).
How to use:
1) Create the following 4 scripts (sshlogin.exp, scplogin.exp, install_puppet and deploy_puppet), and make them executable.
2) Add all IP address into the IP.list file, only one IP in each line.
3) Run ./deploy_puppet, then go to get a cup of coffee :)
+++++++++++++++++++++++++++++
#!/usr/bin/expect -f
# sshlogin.exp
# syntax:  ./sshlogin.exp password ip command
# set Variables
set password [lrange $argv 0 0]
set ipaddr [lrange $argv 1 1]
set scriptname [lrange $argv 2 2]
set arg1 [lrange $argv 3 3]
set timeout -1
# now connect to remote UNIX box (ipaddr) with given script to execute
# replace jchen with your username
spawn ssh -o StrictHostKeyChecking=no jchen@$ipaddr $scriptname $arg1
match_max 100000
# Look for passwod prompt
expect “*?assword:*”
# Send password aka $password
send — “$password”
# send blank line () to make sure we get back to gui
send — “”
expect eof
+++++++++++++++++++++++++++++
#!/usr/bin/expect -f
# scplogin.exp
# syntax: ./sshlogin.exp password ip filename
# set Variables
set password [lrange $argv 0 0]
set ipaddr [lrange $argv 1 1]
set filename [lrange $argv 2 2]
set timeout -1
# now connect to remote UNIX box (ipaddr) with given script to execute
# replace jchen with your username
spawn scp $filename jchen@$ipaddr:~/
match_max 100000
# Look for passwod prompt
expect “*?assword:*”
# Send password aka $password
send — “$password”
# send blank line () to make sure we get back to gui
send — “”
expect eof
+++++++++++++++++++++++++++++
#!/bin/bash
# install_puppet
#install puppet
echo N  | sudo apt-get install -y puppet
#start puppet on boot
sudo puppet resource service puppet ensure=running enable=true
sudo puppet agent –test
sudo chmod 666 /etc/default/puppet
sudo echo START=yes > /etc/default/puppet
sudo echo DAEMON_OPTS=”” >> /etc/default/puppet
#configure the server in the conf file
agent=$(hostname | tr ‘[A-Z]‘ ‘[a-z]‘)
sudo touch /etc/puppet/puppet.conf
sudo chmod 666 /etc/puppet/puppet.conf
sudo echo [main] > /etc/puppet/puppet.conf
# replace CentOS.my.lab with your Master server name
sudo echo server=CentOS.my.lab >> /etc/puppet/puppet.conf
sudo echo certname=$agent >> /etc/puppet/puppet.conf
sudo echo logdir=/var/log/puppet >> /etc/puppet/puppet.conf
sudo echo vardir=/var/lib/puppet >> /etc/puppet/puppet.conf
sudo echo ssldir=/var/lib/puppet/ssl >> /etc/puppet/puppet.conf
sudo echo rundir=/var/run/puppet >> /etc/puppet/puppet.conf
sudo echo factpath=$vardir/lib/facter >> /etc/puppet/puppet.conf
sudo echo templatedir=$confdir/templates >> /etc/puppet/puppet.conf
sudo echo prerun_command=/etc/puppet/etckeeper-commit-pre >> /etc/puppet/puppet.conf
sudo echo postrun_command=/etc/puppet/etckeeper-commit-post >> /etc/puppet/puppet.conf
#restart puppet
sudo puppet agent
+++++++++++++++++++++++++++++++
#!/bin/bash
# deploy_puppet
# check if IP pingable
for ip in $(cat IP.list)
do
if  ping -c 4 $ip > /dev/null 2>&1
then
echo $ip ‘is pingable’
#check /etc/puppet exisitence
 if ./sshlogin.exp password $ip ls /etc | grep puppet > /dev/null 2>&1
 then
 echo ‘Puppet is already installed on’ $ip
 else
 #copy install script to remote host
 ./scplogin.exp password $ip install_puppet
 #install puppet on remote host
 ./sshlogin.exp password $ip /home/jchen/install_puppet
 echo $ip >> IP.success
 fi
else
echo $ip ‘is NOT pingable’
echo $ip >> IP.not_pingable
fi
done
download_icon

Puppet-dashboard Installation


Continue with my previous Puppet Installation, here is how I installed the puppet dashboard which offers a web UI.

Install puppet-dashboard

sudo yum install puppet-dashboard

Config /usr/share/puppet-dashboard/config/database.yml

production:
database: dashboard_production
username: dashboard
password: puppet
encoding: utf8
adapter: mysql

Create MySQL database for puppet-dashboard

CREATE DATABASE dashboard_production CHARACTER SET utf8;
CREATE USER ‘dashboard’@’localhost’ IDENTIFIED BY ‘puppet';
GRANT ALL PRIVILEGES ON dashboard_production.* TO ‘dashboard’@’localhost';

Prepare Schema

cd /usr/share/puppet-dashboard/
rake RAILS_ENV=production db:migrate

Start puppet-dashboard

sudo -u puppet-dashboard /usr/share/puppet-dashboard/script/server -e production &

Configure  puppet master server

#/etc/puppet/puppet.conf (puppet master)

[master]
node_terminus = exec
external_nodes = /usr/bin/env PUPPET_DASHBOARD_URL=http://localhost:3000 /usr/share/puppet-dashboard/bin/external_node

Restart puppet master server

/etc/init.d/puppetmaster restart

Start delayed job workers

sudo -u puppet-dashboard env RAILS_ENV=production /usr/share/puppet-dashboard/script/delayed_job -p dashboard -n 2 -m start &

Test

In Agent: sudo puppet agent

Go to the http://Master_Server_IP:3000

Reference: http://docs.puppetlabs.com/dashboard/manual/1.2/bootstrapping.html

Puppet Installation


In my lab I have set up the CentOS 6.3 as the Puppet Master server, and Ubunt 12.10 as the Puppet agent.

Install Puppet-Server on CentOS (Master)

sudo rpm -ivh http://yum.puppetlabs.com/el/6/products/i386/puppetlabs-release-6-6.noarch.rpm
sudo yum install puppet-server

Install Puppet on Ubuntu (Agent)

wget http://apt.puppetlabs.com/puppetlabs-release-precise.deb
sudo dpkg -i puppetlabs-release-precise.deb
sudo apt-get update
sudo apt-get install puppet 

Specify the Puppet Master server name in /etc/puppet/puppet.conf in Agent

[main]
server=CentOS.my.lab

Enable the service

In Agent: sudo puppet resource service puppet ensure=running enable=true
In Master: sudo puppet resource service puppetmaster ensure=running enable=true

Request (Agent) and Sign Certificate (Master)

In Agent: sudo puppet agent –test (or sudo puppet agent, when with ‘–test’ it only runs once)
In Master: sudo puppet cert sign –all

Test – Create a file in the Agent

In Master: 

vi /etc/puppet/manifests/site.pp

node default{
file {“/tmp/puppet_test_file”:
content => “this is a puppet test file”}
}

In Agent: sudo puppet agent –test

Reference: http://docs.puppetlabs.com/guides/installation.html

Disable the blinking wifi LED in Ubuntu


The wifi LED keeps blinking in my Ubunut 12.10 laptop (Intel chips) when it is connected. To disable it, I have changed the led_mode to 0. Here is how I did it:

1) Change to root user.

jchen@JC:~$ sudo -i
[sudo] password for jchen: 

2) Find out the wifi module.

root@JC:~# lsmod | grep iw
iwlwifi               348584  0 
mac80211              461203  1 iwlwifi
cfg80211              175574  2 iwlwifi,mac80211

3) Change the led_mode to 1.

root@JC:~# vi /etc/modprobe.d/iwlwifi.conf
# iwlwifi will dyamically load either iwldvm or iwlmvm depending on the
# microcode file installed on the system.  When removing iwlwifi, first
# remove the iwl?vm module and then iwlwifi.
remove iwlwifi
(/sbin/lsmod | grep -o -e ^iwlmvm -e ^iwldvm -e ^iwlwifi | xargs /sbin/rmmod)
&& /sbin/modprobe -r mac80211
options iwlwifi led_mode=1

4) Reload the wifi module

root@JC:~# modprobe -r iwlwifi && modprobe iwlwifi 
root@JC:~# exit
logout
jchen@JC:~$ 

Screen brightness reset in Ubuntu


My Ubuntu laptop’s screen brightness resets everytime after reboot. I have found a way to make the brightness adjustment ‘stay permantly':

1) Adjust the brightness to the level that I like, then run ‘cat /sys/class/backlight/acpi_video0/brightness ‘. The command will return the brightness level in a integer value. Mine is 12.
2) Add the line ‘echo 12 > /sys/class/backlight/acpi_video0/brightness‘ into the /etc/rc.local file.