In the previous post, we configure the Chef Knife Plugin in Oracle Cloud Infrastructure (OCI).

Configure Chef Knife Plugin in OCI

Now, we can provision & manage resources in in Oracle Cloud Infrastructure (OCI) with Chef Knife Plugin.

  • Create a VM compute instance with Knife command.
[root@chefserver ~]# knife oci server create --availability-domain 'yQUJ:US-ASHBURN-AD-3' --compartment-id 'ocid1.compartment.oc1..aaaaaaaahezm67s5hcf2pqbxtw6omyukbdevqycn5vxzylisuojd6hj5jx6q' --image-id 'ocid1.image.oc1.iad.aaaaaaaavzjw65d6pngbghgrujb76r7zgh2s64bdl4afombrdocn4wdfrwdq' --shape 'VM.Standard2.1' --subnet-id 'ocid1.subnet.oc1.iad.aaaaaaaauxtyvarfkwdmo763gg75gcqiyvqgnlibxrzstfhdcpsbkh35er2a' --display-name ChefKnifeServer --ssh-authorized-keys-file ~/.ssh/id_rsa.pub --identity-file ~/.ssh/id_rsa --region 'us-ashburn-1' -c /root/chef-repo/.chef/knife.rb -N ChefKnifeServer -r 'sudo -i'

/root/.chefdk/gem/ruby/2.6.0/gems/oci-2.7.0/lib/oci/identity/models/base_tag_definition_validator.rb:20: warning: already initialized constant OCI::Identity::Models::BaseTagDefinitionValidator::VALIDATOR_TYPE_ENUM
/root/.chefdk/gem/ruby/2.6.0/gems/oci-2.7.0/lib/oci/identity/models/base_tag_definition_validator.rb:21: warning: previous definition of VALIDATOR_TYPE_ENUM was here
Launched instance 'ChefKnifeServer' [ocid1.instance.oc1.iad.anuwcljtjcisnjiclykwz2nrpz2j2og4ljwa77xrghqh4nvcu63igqkb23ga]
Waiting for instance to reach running state........................................done
Instance 'ChefKnifeServer' is now running.
Waiting for ssh access...done
Bootstrapping with node name 'ChefKnifeServer'.
Connecting to 150.136.164.64
WARNING: Failed to authenticate opc to 150.136.164.64 - trying password auth
Enter password for opc@150.136.164.64.

Connecting to 150.136.164.64
The authenticity of host '150.136.164.64 ()' can't be established.
fingerprint is SHA256:FVmHbHx/10A1n6MwTGTVGoyZI49EW2LiPsfLK9rzrvA.

Are you sure you want to continue connecting
? (Y/N) N
You said no, so I'm done here.
[root@chefserver ~]# 
  • Now go to OCI console and verify it. It must be in Provisioning State.

  • After couple of minutes, Instance will be running.

  • Now, let’s add the bootstrapper in new instance as client of Chef Server. Bootstrapping is done through SSH only, and uses the public IP address.  You can create your in reciepe cookbook pass it as run-list. A run-list defines all of the information necessary for Chef to configure a node into the desired state.
[root@chefserver ~]# knife bootstrap 150.136.164.64 -U opc -i '~/.ssh/id_rsa' -N 'ChefKnifeServer' --sudo 'sudo -i'
Connecting to 150.136.164.64
The authenticity of host '150.136.164.64 ()' can't be established.
fingerprint is SHA256:FVmHbHx/10A1n6MwTGTVGoyZI49EW2LiPsfLK9rzrvA.

Are you sure you want to continue connecting
? (Y/N) Y
Connecting to 150.136.164.64
Creating new client for ChefKnifeServer
Creating new node for ChefKnifeServer
Bootstrapping 150.136.164.64
 [150.136.164.64] -----> Installing Chef Omnibus (stable/15)
 [150.136.164.64] downloading https://omnitruck.chef.io/chef/install.sh
  to file /tmp/install.sh.11807/install.sh
 [150.136.164.64] trying wget...
 [150.136.164.64] el 7 x86_64
 [150.136.164.64] Getting information for chef stable 15 for el...
 [150.136.164.64] downloading https://omnitruck.chef.io/stable/chef/metadata?v=15&p=el&pv=7&m=x86_64
 [150.136.164.64]   to file /tmp/install.sh.11812/metadata.txt
 [150.136.164.64] trying wget...
 [150.136.164.64] sha1  15ee4fd0df70b3e3f320d4ebcefd250583086006
sha256  57cdf26636ffd876277dcc865d70df34a178ad2ef99f36121dc576bf07f98894
url     https://packages.chef.io/files/stable/chef/15.8.23/el/7/chef-15.8.23-1.el7.x86_64.rpm
version 15.8.23
 [150.136.164.64]
 [150.136.164.64] downloaded metadata file looks valid...
 [150.136.164.64] downloading https://packages.chef.io/files/stable/chef/15.8.23/el/7/chef-15.8.23-1.el7.x86_64.rpm
  to file /tmp/install.sh.11812/chef-15.8.23-1.el7.x86_64.rpm
 [150.136.164.64] trying wget...
 [150.136.164.64] Comparing checksum with sha256sum...
 [150.136.164.64] Installing chef 15
 [150.136.164.64] installing with rpm...
 [150.136.164.64] warning: /tmp/install.sh.11812/chef-15.8.23-1.el7.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 83ef826a: NOKEY
 [150.136.164.64] Preparing...
 [150.136.164.64] ########################################
 [150.136.164.64] Updating / installing...
chef-15.8.23-1.el7
 [150.136.164.64] #
 [150.136.164.64] #
 [150.136.164.64] #
 [150.136.164.64] #
 [150.136.164.64] #
 [150.136.164.64] #
 [150.136.164.64] #
 [150.136.164.64] #
 [150.136.164.64] #
 [150.136.164.64] #
 [150.136.164.64] #
 [150.136.164.64] #
 [150.136.164.64] Thank you for installing Chef Infra Client! For help getting started visit https://learn.chef.io
 [150.136.164.64] Starting the first Chef Infra Client Client run...
 [150.136.164.64] +---------------------------------------------+
? 2 product licenses accepted.
+---------------------------------------------+
 [150.136.164.64] Starting Chef Infra Client, version 15.8.23
 [150.136.164.64] resolving cookbooks for run list: []
 [150.136.164.64] Synchronizing Cookbooks:
 [150.136.164.64] Installing Cookbook Gems:
 [150.136.164.64] Compiling Cookbooks...
 [150.136.164.64] [2020-03-05T12:44:06+00:00] WARN: Node ChefKnifeServer has an empty run list.
 [150.136.164.64] Converging 0 resources
 [150.136.164.64]
Running handlers:
 [150.136.164.64] Running handlers complete

 [150.136.164.64] Chef Infra Client finished, 0/0 resources updated in 02 seconds

[root@chefserver ~]#
  • Now, run and verify the couple of command to manage resources.
[root@chefserver ~]# knife client list
ChefKnifeServer
oraclehelp-validator

[root@chefserver ~]# knife node list
ChefKnifeServer

[root@chefserver .chef]# knife node show ChefKnifeServer
Node Name:   ChefKnifeServer
Environment: _default
FQDN:        ChefKnifeServer.sub03051059070.k8svcn.oraclevcn.com
IP:          10.0.1.3
Run List:
Roles:
Recipes:
Platform:    oracle 7.7
Tags:

[root@chefserver ~]#  knife oci server list
/root/.chefdk/gem/ruby/2.6.0/gems/oci-2.7.0/lib/oci/identity/models/base_tag_definition_validator.rb:20: warning: already initialized constant OCI::Identity::Models::BaseTagDefinitionValidator::VALIDATOR_TYPE_ENUM
/root/.chefdk/gem/ruby/2.6.0/gems/oci-2.7.0/lib/oci/identity/models/base_tag_definition_validator.rb:21: warning: previous definition of VALIDATOR_TYPE_ENUM was here
Display		Name     State    ID
ChefKnifeServer Server  RUNNING  ocid1.instance.oc1.iad.anuwcljtjcisnjicouvsfmum6qupwvxonhx4k2i46l7apeflpvu3nykhj3zq

[root@chefserver ~]#  knife oci server show --instance-id ocid1.instance.oc1.iad.anuwcljtjcisnjicouvsfmum6qupwvxonhx4k2i46l7apeflpvu3nykhj3zq
/root/.chefdk/gem/ruby/2.6.0/gems/oci-2.7.0/lib/oci/identity/models/base_tag_definition_validator.rb:20: warning: already initialized constant OCI::Identity::Models::BaseTagDefinitionValidator::VALIDATOR_TYPE_ENUM
/root/.chefdk/gem/ruby/2.6.0/gems/oci-2.7.0/lib/oci/identity/models/base_tag_definition_validator.rb:21: warning: previous definition of VALIDATOR_TYPE_ENUM was here
Display Name: ChefKnifeServer
Instance ID: ocid1.instance.oc1.iad.anuwcljtjcisnjicouvsfmum6qupwvxonhx4k2i46l7apeflpvu3nykhj3zq
Lifecycle State: RUNNING
Availability Domain: yQUJ:US-ASHBURN-AD-3
Compartment Name: C07
Compartment ID: ocid1.compartment.oc1..aaaaaaaahezm67s5hcf2pqbxtw6omyukbdevqycn5vxzylisuojd6hj5jx6q
Region: iad
Image Name: Oracle-Linux-7.7-2020.02.21-0
Image ID: ocid1.image.oc1.iad.aaaaaaaavzjw65d6pngbghgrujb76r7zgh2s64bdl4afombrdocn4wdfrwdq
Shape: VM.Standard2.1
VCN Name: K8SVCN
VCN ID: ocid1.vcn.oc1.iad.amaaaaaajcisnjiat2g4gkzkzrak6knrqk4243jsndmbs6c6ywgudv7c2y6a
Launched: Thu,  5 Mar 2020 11:34:37 +00:00
Primary Public IP Address: 150.136.168.25
Primary Private IP Address: 10.0.1.3
Primary Hostname: ChefKnifeServerserver
Primary FQDN: ChefKnifeServerserver.sub03051059070.k8svcn.oraclevcn.com
Primary Subnet Name: Public Subnet-K8SVCN

[root@chefserver ~]#
  • Test the connection via SSH with pubic IP and Also, test with Knife SSH command.
[root@chefserver ~]# ssh -i ~/.ssh/id_rsa opc@150.136.168.25
The authenticity of host '150.136.168.25 (150.136.168.25)' can't be established.
ECDSA key fingerprint is SHA256:tVPpDkR+YsIoX+5oW7jT3oPUrErhY6ZGKQsAStLI2FU.
ECDSA key fingerprint is MD5:8b:aa:a3:90:34:01:e5:89:aa:94:97:44:61:49:5e:42.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '150.136.168.25' (ECDSA) to the list of known hosts.
[opc@ChefKnifeServer ~]$ exit
logout
Connection to 150.136.168.25 closed.

[root@chefserver ~]# knife ssh 'name:ChefKnifeServer' 'cat /etc/hosts' -x opc
ChefKnifeServer.sub03051059070.k8svcn.oraclevcn.com 127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
ChefKnifeServer.sub03051059070.k8svcn.oraclevcn.com ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
ChefKnifeServer.sub03051059070.k8svcn.oraclevcn.com 10.0.1.3    ChefKnifeServer.sub03051059070.k8svcn.oraclevcn.com ChefKnifeServer
[root@chefserver ~]#
  • Now, we can deploying the application on client from Chef Workstation with Knife plugin. 
[root@chefserver ~]# knife ssh 'name:ChefKnifeServer' 'sudo yum install -y httpd && sudo systemctl start httpd && sudo systemctl status httpd' -x opc
ChefKnifeServer.sub03051059070.k8svcn.oraclevcn.com Loaded plugins: langpacks, ulninfo
ChefKnifeServer.sub03051059070.k8svcn.oraclevcn.com Resolving Dependencies
ChefKnifeServer.sub03051059070.k8svcn.oraclevcn.com --> Running transaction check
ChefKnifeServer.sub03051059070.k8svcn.oraclevcn.com ---> Package httpd.x86_64 0:2.4.6-90.0.1.el7 will be installed
ChefKnifeServer.sub03051059070.k8svcn.oraclevcn.com --> Finished Dependency Resolution
ChefKnifeServer.sub03051059070.k8svcn.oraclevcn.com
ChefKnifeServer.sub03051059070.k8svcn.oraclevcn.com Dependencies Resolved
ChefKnifeServer.sub03051059070.k8svcn.oraclevcn.com
ChefKnifeServer.sub03051059070.k8svcn.oraclevcn.com ================================================================================
ChefKnifeServer.sub03051059070.k8svcn.oraclevcn.com  Package       Arch           Version                  Repository          Size
ChefKnifeServer.sub03051059070.k8svcn.oraclevcn.com ================================================================================
ChefKnifeServer.sub03051059070.k8svcn.oraclevcn.com Installing:
ChefKnifeServer.sub03051059070.k8svcn.oraclevcn.com  httpd         x86_64         2.4.6-90.0.1.el7         ol7_latest         1.2 M
ChefKnifeServer.sub03051059070.k8svcn.oraclevcn.com
ChefKnifeServer.sub03051059070.k8svcn.oraclevcn.com Transaction Summary
ChefKnifeServer.sub03051059070.k8svcn.oraclevcn.com ================================================================================
ChefKnifeServer.sub03051059070.k8svcn.oraclevcn.com Install  1 Package
ChefKnifeServer.sub03051059070.k8svcn.oraclevcn.com
ChefKnifeServer.sub03051059070.k8svcn.oraclevcn.com Total download size: 1.2 M
ChefKnifeServer.sub03051059070.k8svcn.oraclevcn.com Installed size: 3.7 M
ChefKnifeServer.sub03051059070.k8svcn.oraclevcn.com Downloading packages:
httpd-2.4.6-90.0.1.el7.x86_64.rpm                          | 1.2 MB   00:00
ChefKnifeServer.sub03051059070.k8svcn.oraclevcn.com Running transaction check
ChefKnifeServer.sub03051059070.k8svcn.oraclevcn.com Running transaction test
ChefKnifeServer.sub03051059070.k8svcn.oraclevcn.com Transaction test succeeded
ChefKnifeServer.sub03051059070.k8svcn.oraclevcn.com Running transaction
  Installing : httpd-2.4.6-90.0.1.el7.x86_64                                1/1
  Verifying  : httpd-2.4.6-90.0.1.el7.x86_64                                1/1
ChefKnifeServer.sub03051059070.k8svcn.oraclevcn.com
ChefKnifeServer.sub03051059070.k8svcn.oraclevcn.com Installed:
ChefKnifeServer.sub03051059070.k8svcn.oraclevcn.com   httpd.x86_64 0:2.4.6-90.0.1.el7
ChefKnifeServer.sub03051059070.k8svcn.oraclevcn.com
ChefKnifeServer.sub03051059070.k8svcn.oraclevcn.com Complete!
ChefKnifeServer.sub03051059070.k8svcn.oraclevcn.com ? httpd.service - The Apache HTTP Server
ChefKnifeServer.sub03051059070.k8svcn.oraclevcn.com    Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
ChefKnifeServer.sub03051059070.k8svcn.oraclevcn.com    Active: active (running) since Thu 2020-03-05 18:58:03 GMT; 38ms ago
ChefKnifeServer.sub03051059070.k8svcn.oraclevcn.com      Docs: man:httpd(8)
ChefKnifeServer.sub03051059070.k8svcn.oraclevcn.com            man:apachectl(8)
ChefKnifeServer.sub03051059070.k8svcn.oraclevcn.com  Main PID: 17130 (httpd)
ChefKnifeServer.sub03051059070.k8svcn.oraclevcn.com    Status: "Processing requests..."
ChefKnifeServer.sub03051059070.k8svcn.oraclevcn.com    CGroup: /system.slice/httpd.service
ChefKnifeServer.sub03051059070.k8svcn.oraclevcn.com            +-17130 /usr/sbin/httpd -DFOREGROUND
ChefKnifeServer.sub03051059070.k8svcn.oraclevcn.com            +-17131 /usr/sbin/httpd -DFOREGROUND
ChefKnifeServer.sub03051059070.k8svcn.oraclevcn.com            +-17132 /usr/sbin/httpd -DFOREGROUND
ChefKnifeServer.sub03051059070.k8svcn.oraclevcn.com            +-17133 /usr/sbin/httpd -DFOREGROUND
ChefKnifeServer.sub03051059070.k8svcn.oraclevcn.com            +-17134 /usr/sbin/httpd -DFOREGROUND
ChefKnifeServer.sub03051059070.k8svcn.oraclevcn.com            +-17135 /usr/sbin/httpd -DFOREGROUND
ChefKnifeServer.sub03051059070.k8svcn.oraclevcn.com
ChefKnifeServer.sub03051059070.k8svcn.oraclevcn.com Mar 05 18:58:03 ChefKnifeServer systemd[1]: Starting The Apache HTTP Server...
ChefKnifeServer.sub03051059070.k8svcn.oraclevcn.com Mar 05 18:58:03 ChefKnifeServer systemd[1]: Started The Apache HTTP Server.
[root@chefserver ~]#
  • Delete the Instance with Knife Plugin.
[root@chefserver ~]#  knife oci server delete --instance-id ocid1.instance.oc1.iad.anuwcljtjcisnjicouvsfmum6qupwvxonhx4k2i46l7apeflpvu3nykhj3zq
/root/.chefdk/gem/ruby/2.6.0/gems/oci-2.7.0/lib/oci/identity/models/base_tag_definition_validator.rb:20: warning: already initialized constant OCI::Identity::Models::BaseTagDefinitionValidator::VALIDATOR_TYPE_ENUM
/root/.chefdk/gem/ruby/2.6.0/gems/oci-2.7.0/lib/oci/identity/models/base_tag_definition_validator.rb:21: warning: previous definition of VALIDATOR_TYPE_ENUM was here
Instance name: ChefKnifeServer
Delete server? (y/n)
y
Initiated delete of instance ocid1.instance.oc1.iad.anuwcljtjcisnjicouvsfmum6qupwvxonhx4k2i46l7apeflpvu3nykhj3zq
[root@chefserver ~]# 
  • Move back to OCI console and verify it.

Thank you for giving your valuable time to read the above information.

If you want to be updated with all our articles send us the Invitation or Follow us:

Skant Gupta’s LinkedIn: www.linkedin.com/in/skantali/

LinkedIn Group: Oracle Cloud DBAAS

Facebook Page: OracleHelp

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.