Install Jenkins Using Chef on Redhat OS

On the Workstation

Step1:
Goto the repository location -- /root/chef-repo/cookbook
knife cookbook create jenkins

The command will create these directories.

drwxr-xr-x 10 root root 4096 Dec  2 12:38 .
drwxrwxrwx  5 root root 4096 Dec  2 10:58 ..
drwxr-xr-x  2 root root 4096 Dec  2 00:16 attributes
-rw-r--r--  1 root root  455 Dec  2 00:16 CHANGELOG.md
drwxr-xr-x  2 root root 4096 Dec  2 00:16 definitions
drwxr-xr-x  3 root root 4096 Dec  2 00:16 files
drwxr-xr-x  2 root root 4096 Dec  2 00:16 libraries
-rw-r--r--  1 root root  309 Dec  2 10:57 metadata.rb
drwxr-xr-x  2 root root 4096 Dec  2 00:16 providers
-rw-r--r--  1 root root 1456 Dec  2 00:16 README.md
drwxr-xr-x  2 root root 4096 Dec  2 12:33 recipes
drwxr-xr-x  2 root root 4096 Dec  2 00:16 resources
drwxr-xr-x  3 root root 4096 Dec  2 00:16 templates


Step2:
Open the default.rb file that is located in /root/chef-repo/cookbook/jenkins/recipes
Add this piece of code, this is specific to Redhat
========================================================================
#
# Cookbook Name:: jenkins
# Recipe:: default
#
# Copyright 2014, YOUR_COMPANY_NAME
#
# All rights reserved - Do Not Redistribute
#

include_recipe "yum"
include_recipe "java"


yum_repository "jenkins" do
  baseurl "http://pkg.jenkins-ci.org/redhat"
  gpgkey "http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key"
  #components ["binary/"]
  action :create
end

package 'jenkins'

service 'jenkins' do
  supports [:stop, :start, :restart]
  action [:start, :enable]
end

========================================================================
Step3:
Now edit the metadata.rb file located in /root/chef-repo/cookbook/jenkins

Add the dependencies

depends 'yum'
depends 'java'

Step4:
download the dependancy cookbooks from chef-site

knife cookbook site download yum
knife cookbook site download java


tar -xvf yum-3.5.1.tar.gz
tar -xvf java-1.29.0.tar.gz

Step5:
Now upload the cookbooks jenkins, java and yum to the chefserver

knife cookbook upload jenkins
knife cookbook upload java
knife cookbook upload yum

Step6:
Now edit the node file

export EDITOR=vi
knife node edit

or
 knife node run_list add 'recipe[jenkins]'

And add the entry like
 "run_list": [
  "recipe[jenkins]"
 
step7:
Now go to the client(node) machine where we want this jenkins to be installed.
Execute: chef-client


If you get this kind of error message ----goto the cookbooks/java/recipes/openjdk.rb on the workstaion machine

     45   node['java']['openjdk_packages'].each do |pkg|
     46   package pkg do
     47     version node['java']['openjdk_version'] if node['java']['openjdk_version']
     48   end
     49 end



**** Comment out this section and upload the jenkins package from the workstation and execute the chef-client from the node again.




    ========================================================================
    Error executing action `install` on resource 'package[java-1.6.0-openjdk]'
    ========================================================================
   
    Mixlib::ShellOut::ShellCommandFailed
    ------------------------------------
    Expected process to exit with [0], but received '1'
    ---- Begin output of /usr/bin/python /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.16.4/lib/chef/provider/package/yum-dump.py --options --installed-provides --yum-lock-timeout 30 ----
    STDOUT: [option installonlypkgs] kernel kernel-bigmem installonlypkg(kernel-module) installonlypkg(vm) kernel-enterprise kernel-smp kernel-debug kernel-unsupported kernel-source kernel-devel kernel-PAE kernel-PAE-debug
    STDERR: yum-dump Repository Error: Cannot retrieve repository metadata (repomd.xml) for repository: jenkins. Please verify its path and try again
    ---- End output of /usr/bin/python /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.16.4/lib/chef/provider/package/yum-dump.py --options --installed-provides --yum-lock-timeout 30 ----
    Ran /usr/bin/python /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.16.4/lib/chef/provider/package/yum-dump.py --options --installed-provides --yum-lock-timeout 30 returned 1

Comments

Popular posts from this blog

Aix Interview Commands

Websphere Portal