Chef workstation and client installation
First we install Chef development kit package.
[root@workstation1 ~]# wget https://packages.chef.io/files/stable/chefdk/3.1.0/el/7/chefdk-3.1.0-1.el7.x86_64.rpm
--2018-08-19 21:06:30-- https://packages.chef.io/files/stable/chefdk/3.1.0/el/7/chefdk-3.1.0-1.el7.x86_64.rpm
Resolving packages.chef.io (packages.chef.io)... 151.101.26.110
Connecting to packages.chef.io (packages.chef.io)|151.101.26.110|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 111403205 (106M) [application/x-rpm]
Saving to: âefdk-3.1.0-1.el7.x86_64.rpmâ100%[==============================================================================================================>] 111,403,205 12.1MB/s in 9.1s
2018-08-19 21:06:42 (11.6 MB/s) - âefdk-3.1.0-1.el7.x86_64.rpmâaved [111403205/111403205]
[root@workstation1 ~]# ls
chefdk-3.1.0-1.el7.x86_64.rpm
[root@workstation1 ~]# rpm -ivh chefdk-3.1.0-1.el7.x86_64.rpm
warning: chefdk-3.1.0-1.el7.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 83ef826a: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:chefdk-3.1.0-1.el7 ################################# [100%]
Thank you for installing Chef Development Kit!
[root@workstation1 ~]# chef-client -version
Chef: 14.2.0
Next we do is download the chef starter kit. Click on the Administration tab then the organization the starter kit is on the left hand side.
Take note, every time you download this starter kit it will reset the private key.
[root@workstation1 ~]# scp centos7:chef-starter.zip .
root@centos7's password:
chef-starter.zip 100% 7830 10.9MB/s 00:00
[root@workstation1 ~]# unzip chef-starter.zip
Archive: chef-starter.zip
inflating: chef-repo/README.md
creating: chef-repo/cookbooks/
inflating: chef-repo/cookbooks/chefignore
creating: chef-repo/cookbooks/starter/
creating: chef-repo/cookbooks/starter/attributes/
inflating: chef-repo/cookbooks/starter/attributes/default.rb
creating: chef-repo/cookbooks/starter/files/
creating: chef-repo/cookbooks/starter/files/default/
inflating: chef-repo/cookbooks/starter/files/default/sample.txt
inflating: chef-repo/cookbooks/starter/metadata.rb
creating: chef-repo/cookbooks/starter/recipes/
inflating: chef-repo/cookbooks/starter/recipes/default.rb
creating: chef-repo/cookbooks/starter/templates/
creating: chef-repo/cookbooks/starter/templates/default/
inflating: chef-repo/cookbooks/starter/templates/default/sample.erb
inflating: chef-repo/.gitignore
creating: chef-repo/.chef/
creating: chef-repo/roles/
inflating: chef-repo/.chef/knife.rb
inflating: chef-repo/roles/starter.rb
inflating: chef-repo/.chef/chef_admin.pem
Next we need to create link to the.chef sub-directory.
[root@workstation1 ~]# ln -s /root/chef-repo/.chef/ /root/.chef
[root@workstation1 ~]# ls -l .chef
lrwxrwxrwx. 1 root root 22 Aug 18 21:51 .chef -> /root/chef-repo/.chef/
[root@workstation1 ~]# ls .chef
chef_admin.pem knife.rb
[root@workstation1 ~]# knife client list
ERROR: SSL Validation failure connecting to host: centos7 - SSL_connect returned=1 errno=0 state=error: certificate verify failed (self signed certificate)
ERROR: Could not establish a secure connection to the server.
Use `knife ssl check` to troubleshoot your SSL configuration.
If your Chef Server uses a self-signed certificate, you can use
`knife ssl fetch` to make knife trust the server's certificates.
Original Exception: OpenSSL::SSL::SSLError: SSL Error connecting to https://centos7/organizations/unixguide/clients - SSL_connect returned=1 errno=0 state=error: certificate verify failed (self signed certificate)
[root@workstation1 ~]# knife ssl fetch
WARNING: Certificates from centos7 will be fetched and placed in your trusted_cert
directory (/root/.chef/trusted_certs).
Knife has no means to verify these are the correct certificates. You should
verify the authenticity of these certificates after downloading.
Adding certificate for centos7 in /root/.chef/trusted_certs/centos7.crt
[root@workstation1 ~]# knife ssl check
Connecting to host centos7:443
Successfully verified certificates from `centos7'
[root@workstation1 ~]# knife client list
unixguide-validator
Next we bootstrap the workstation itself.
[root@workstation1 ~]# knife bootstrap workstation1 -N workstation1
Creating new client for workstation1
Creating new node for workstation1
Connecting to workstation1
root@workstation1's password:
workstation1 -----> Existing Chef installation detected
workstation1 Starting the first Chef Client run...
workstation1 Starting Chef Client, version 14.2.0
workstation1 resolving cookbooks for run list: []
workstation1 Synchronizing Cookbooks:
workstation1 Installing Cookbook Gems:
workstation1 Compiling Cookbooks...
workstation1 [2018-08-19T21:11:23-07:00] WARN: Node workstation1 has an empty run list.
workstation1 Converging 0 resources
workstation1
workstation1 Running handlers:
workstation1 Running handlers complete
workstation1 Chef Client finished, 0/0 resources updated in 02 seconds
Now, we can see that the workstation is now listed as a client.
[root@workstation1 ~]# knife client list
workstation1
unixguide-validator
Next, we will create the admintools cookbook.
[root@workstation1 ~]# cd chef-repo
[root@workstation1 chef-repo]# ls
cookbooks README.md roles
[root@workstation1 chef-repo]# chef generate cookbook admintools
Generating cookbook admintools
- Ensuring correct cookbook file content
- Ensuring delivery configuration
- Ensuring correct delivery build cookbook content
Your cookbook is ready. Type `cd admintools` to enter it.
There are several commands you can run to get started locally developing and testing your cookbook.
Type `delivery local --help` to see a full list.
Why not start by writing a test? Tests for the default recipe are stored at:
test/integration/default/default_test.rb
If you'd prefer to dive right in, the default recipe can be found at:
recipes/default.rb
[root@workstation1 chef-repo]# ls
admintools cookbooks README.md roles
[root@workstation1 chef-repo]# mv admintools/ cookbooks/
[root@workstation1 chef-repo]# cd cookbooks/admintools/recipes/
Next, we just create default recipe to install the nmap package.
[root@workstation1 recipes]# vi default.rb
[root@workstation1 recipes]# cat default.rb
#
# Cookbook:: admintools
# Recipe:: default
#
# Copyright:: 2018, The Authors, All Rights Reserved.
package 'nmap' do
action :install
end
[root@workstation1 recipes]# pwd
/root/chef-repo/cookbooks/admintools/recipes
[root@workstation1 recipes]# knife cookbook upload -a
Uploading admintools [0.1.0]
Uploading starter [1.0.0]
Uploaded all cookbooks.
Next thing is we edit the workstation and add this the recipe ""recipe[admintools]"" to the run_list.
[root@workstation1 recipes]# knife node edit workstation1
ERROR: You must set your EDITOR environment variable or configure your editor via knife.rb
[root@workstation1 recipes]# export EDITOR=vi
[root@workstation1 recipes]# knife node edit workstation1
Saving updated run_list on node workstation1
[root@workstation1 recipes]# knife node list workstation1
workstation1
[root@workstation1 recipes]# knife node show workstation1
Node Name: workstation1
Environment: _default
FQDN: workstation1.mylab.com
IP: 192.168.1.5
Run List: recipe[admintools]
Roles:
Recipes:
Platform: oracle 7.5
Tags:
[root@workstation1 recipes]# knife node show workstation1 -F json
{
"name": "workstation1",
"chef_environment": "_default",
"run_list": [
"recipe[admintools]"
]
,
"normal": {
"tags": [
]
}
}
Execute the chef client and watch it install the nmap package.
[root@workstation1 recipes]# chef-client
Starting Chef Client, version 14.2.0
resolving cookbooks for run list: ["admintools"]
Synchronizing Cookbooks:
- admintools (0.1.0)
Installing Cookbook Gems:
Compiling Cookbooks...
Converging 1 resources
Recipe: admintools::default
* yum_package[nmap] action install
- install version 2:6.40-13.el7.x86_64 of package nmap
Running handlers:
Running handlers complete
Chef Client finished, 1/1 resources updated in 14 seconds
Bootstrap a chef client.
[root@workstation1 ~]# knife bootstrap oel75.mylab.com -N oel75
Creating new client for oel75
Creating new node for oel75
Connecting to oel75.mylab.com
root@oel75.mylab.com's password:
oel75.mylab.com -----> Installing Chef Omnibus (-v 14)
oel75.mylab.com downloading https://omnitruck-direct.chef.io/chef/install.sh
oel75.mylab.com to file /tmp/install.sh.17211/install.sh
oel75.mylab.com trying wget...
oel75.mylab.com el 7 x86_64
oel75.mylab.com Getting information for chef stable 14 for el...
oel75.mylab.com downloading https://omnitruck-direct.chef.io/stable/chef/metadata?v=14&p=el&pv=7&m=x86_64
oel75.mylab.com to file /tmp/install.sh.17224/metadata.txt
oel75.mylab.com trying wget...
oel75.mylab.com sha1 3229e44c1136741be7df65d1441732bae55a2a02
oel75.mylab.com sha256 1807c453c5a16fd2cb0941f98847a0031c3812ccb9e3a628b2f8fba8335f485c
oel75.mylab.com url https://packages.chef.io/files/stable/chef/14.3.37/el/7/chef-14.3.37-1.el7.x86_64.rpm
oel75.mylab.com version 14.3.37
oel75.mylab.com downloaded metadata file looks valid...
oel75.mylab.com downloading https://packages.chef.io/files/stable/chef/14.3.37/el/7/chef-14.3.37-1.el7.x86_64.rpm
oel75.mylab.com to file /tmp/install.sh.17224/chef-14.3.37-1.el7.x86_64.rpm
oel75.mylab.com trying wget...
oel75.mylab.com Comparing checksum with sha256sum...
oel75.mylab.com Installing chef 14
oel75.mylab.com installing with rpm...
oel75.mylab.com warning: /tmp/install.sh.17224/chef-14.3.37-1.el7.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 83ef826a: NOKEY
oel75.mylab.com Preparing... ################################# [100%]
oel75.mylab.com Updating / installing...
oel75.mylab.com 1:chef-14.3.37-1.el7 ################################# [100%]
oel75.mylab.com Thank you for installing Chef!
oel75.mylab.com Starting the first Chef Client run...
oel75.mylab.com Starting Chef Client, version 14.3.37
oel75.mylab.com resolving cookbooks for run list: []
oel75.mylab.com Synchronizing Cookbooks:
oel75.mylab.com Installing Cookbook Gems:
oel75.mylab.com Compiling Cookbooks...
oel75.mylab.com [2018-08-19T21:28:09-07:00] WARN: Node oel75 has an empty run list.
oel75.mylab.com Converging 0 resources
oel75.mylab.com
oel75.mylab.com Running handlers:
oel75.mylab.com Running handlers complete
oel75.mylab.com Chef Client finished, 0/0 resources updated in 05 seconds
Next, we create the role base and assign the run_list: with the recipe "recipe[admintools]".
[root@workstation1 ~]# knife role create base
Created role[base]
[root@workstation1 ~]# knife role show base
chef_type: role
default_attributes:
description:
env_run_lists:
json_class: Chef::Role
name: base
override_attributes:
run_list: recipe[admintools]
[root@workstation1 ~]# knife role show base -F json
{
"name": "base",
"description": "",
"json_class": "Chef::Role",
"default_attributes": {
},
"override_attributes": {
},
"chef_type": "role",
"run_list": [
"recipe[admintools]"
],
"env_run_lists": {
}
}
The next series of commands will show you how we assigned the role base to chef workstation1 and client oel75.
[root@workstation1 ~]# knife node show oel75
Node Name: oel75
Environment: _default
FQDN: oel75.mylab.com
IP: 192.168.1.18
Run List:
Roles:
Recipes:
Platform: oracle 7.5
Tags:
[root@workstation1 ~]# knife node run_list add workstation1 "role[base]"
workstation1:
run_list:
recipe[admintools]
role[base]
[root@workstation1 ~]# knife node show workstation1
Node Name: workstation1
Environment: _default
FQDN: workstation1.mylab.com
IP: 192.168.1.5
Run List: recipe[admintools], role[base]
Roles:
Recipes: admintools, admintools::default
Platform: oracle 7.5
Tags:
[root@workstation1 ~]# chef-client
Starting Chef Client, version 14.2.0
resolving cookbooks for run list: ["admintools"]
Synchronizing Cookbooks:
- admintools (0.1.0)
Installing Cookbook Gems:
Compiling Cookbooks...
Converging 1 resources
Recipe: admintools::default
* yum_package[nmap] action install (up to date)
Running handlers:
Running handlers complete
Chef Client finished, 0/1 resources updated in 02 seconds
After running the chef-client command, it tried to install the nmap package and set the role base to workstation1.
[root@workstation1 ~]# knife node show workstation1
Node Name: workstation1
Environment: _default
FQDN: workstation1.mylab.com
IP: 192.168.1.5
Run List: recipe[admintools], role[base]
Roles: base
Recipes: admintools, admintools::default
Platform: oracle 7.5
Tags:
[root@workstation1 ~]# knife node run_list add oel75 "role[base]"
oel75:
run_list: role[base]
[root@workstation1 ~]# ssh oel75
root@oel75's password:
Last login: Sun Aug 19 21:27:46 2018 from workstation1.home
[root@oel75 ~]# chef-client
Starting Chef Client, version 14.3.37
resolving cookbooks for run list: ["admintools"]
Synchronizing Cookbooks:
- admintools (0.1.0)
Installing Cookbook Gems:
Compiling Cookbooks...
Converging 1 resources
Recipe: admintools::default
* yum_package[nmap] action install
- install version 2:6.40-13.el7.x86_64 of package nmap
Running handlers:
Running handlers complete
Chef Client finished, 1/1 resources updated in 14 seconds
Recent comments