X

Justin Bye's Weblog

  • Chef |
    February 23, 2016

Chef-solo configuration on remote server

Below is a simple Hello World using chef-solo

1) Log on to the remote machine

[jbye] ➤ ssh apphost -l jbye

Use: Justin - EA Training - RIB

Host specific info (below) - you can modify contents of /etc/motd_hostinfo as needed to update data:

2) Install chef solo rpm (https://downloads.chef.io/chef-client/redhat/)

$ pwd
/home/jbye
$ sudo rpm -ivh chef-12.7.2-1.el6.x86_64.rpm

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these two things:

        #1) Respect the privacy of others.
        #2) Think before you type.

Password:
warning: chef-12.7.2-1.el6.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 83ef826a: NOKEY
Preparing...                ########################################### [100%]
   1:chef                   ########################################### [100%]
Thank you for installing Chef!
$

3) su to the user that will be running chef-solo on the server

$ sudo su - webadmin

4) Create a directory for your chef-repo

$ pwd
/u00/webadmin

$ mkdir chef
$ cd chef

5) Create the .json which will be your run list on the server

$ vi ribserver.json
{
"run_list":["recipe[test]"]
}

6) Create a .rb file that will hold chef configuration values

$ vi ribserver.rb
node_name 'ribserver'
cookbook_path '/u00/webadmin/chef/cookbooks'

7) Create your recipe

$ mkdir -p cookbooks/test/recipes
$ vi cookbooks/test/recipes/default.rb

file "/u00/webadmin/helloworld.txt" do
  owner "webadmin"
  group "dba"
  mode 0777
  action :create
  content "Hello, Implementor!"
end

8) Run the chef-solo script

Your directory structure can look like this

$ pwd
/u00/webadmin

$ tree
.
── chef
   ├── cookbooks
   │   └── test
   │       └── recipes
   │           └── default.rb
   ├── ribserver.json
   └── ribserver.rb

$ cd chef
$ chef-solo -c ./ribserver.rb -j ./ribserver.json
Starting Chef Client, version 12.7.2
Compiling Cookbooks...
Converging 1 resources
Recipe: test::default
  * file[/u00/webadmin/helloworld.txt] action create
    - create new file /u00/webadmin/helloworld.txt
    - update content in file /u00/webadmin/helloworld.txt from none to 676ff8
    --- /u00/webadmin/helloworld.txt    2016-02-23 13:35:59.533850971 -0600
    +++ /u00/webadmin/.helloworld.txt20160223-25260-1r6nvx4     2016-02-23 13:35:59.533850971 -0600
    @@ -1 +1,2 @@
    +Hello, Implementor!
    - change mode from '' to '0777'
    - change owner from '' to 'webadmin'
    - change group from '' to 'dba'

Running handlers:
Running handlers complete
Chef Client finished, 1/1 resources updated in 32 seconds

9) Check your results


$ ls -l /u00/webadmin/helloworld.txt
-rwxrwxrwx 1 webadmin dba 19 Feb 23 13:35 /u00/webadmin/helloworld.txt
$ cat /u00/webadmin/helloworld.txt
Hello, Implementor!
$

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.Captcha
Oracle

Integrated Cloud Applications & Platform Services