Chef is a configuration management tool for dealing with machine setup on physical servers, virtual machines and in the cloud. Chef Infra is a powerful automation platform that transforms infrastructure into code. Whether you’re operating in the cloud, on-premises, or in a hybrid environment, Chef Infra automates how infrastructure is configured, deployed, and managed across your network, no matter its size. The knife-oci plugin allows users to interact with Oracle Cloud Infrastructure through Chef Knife.

  • After the verify your account, you have to login now.

  • Now, create one organization. An organization is the top-level entity for role-based access control in the Chef server.

  • Provide the Full name  and short name, then click on Create Organization.

  • Download the Chef Repo by clicking on Download Starter Kit in your Chef workstation.

  • In Chef Workstation host, unzip the chef repo.
[root@chefserver ~]# ls
chef-starter.zip

[root@chefserver ~]# 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/
  inflating: chef-repo/cookbooks/starter/metadata.rb
   creating: chef-repo/cookbooks/starter/files/
   creating: chef-repo/cookbooks/starter/files/default/
  inflating: chef-repo/cookbooks/starter/files/default/sample.txt
   creating: chef-repo/cookbooks/starter/templates/
   creating: chef-repo/cookbooks/starter/templates/default/
  inflating: chef-repo/cookbooks/starter/templates/default/sample.erb
   creating: chef-repo/cookbooks/starter/attributes/
  inflating: chef-repo/cookbooks/starter/attributes/default.rb
   creating: chef-repo/cookbooks/starter/recipes/
  inflating: chef-repo/cookbooks/starter/recipes/default.rb
  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/oraclehelp.pem

[root@chefserver ~]# ls
chef-repo  chef-starter.zip
  • Now install to ChefDK. The ChefDK contains all the tools you need to develop and test your infrastructure
[root@chefserver ~]# wget https://packages.chef.io/files/stable/chefdk/4.7.73/el/7/chefdk-4.7.73-1.el7.x86_64.rpm                                                                            

Resolving packages.chef.io (packages.chef.io)... 199.232.66.110
Connecting to packages.chef.io (packages.chef.io)|199.232.66.110|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 85946453 (82M) [application/x-rpm]
Saving to: ‘chefdk-4.7.73-1.el7.x86_64.rpm’

100%[===================================================================================================================================================>] 85,946,453   128MB/s   in 0.6s

2020-03-05 11:06:09 (128 MB/s) - ‘chefdk-4.7.73-1.el7.x86_64.rpm’ saved [85946453/85946453]

[root@chefserver ~]# ls
chefdk-4.7.73-1.el7.x86_64.rpm  chef-repo  chef-starter.zip


[root@chefserver ~]# rpm -ivh chefdk-4.7.73-1.el7.x86_64.rpm
warning: chefdk-4.7.73-1.el7.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 83ef826a: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:chefdk-4.7.73-1.el7              ################################# [100%]
Thank you for installing ChefDK!
You can find some tips on getting started at https://learn.chef.io

[root@chefserver ~]# chef -v
ChefDK version: 4.7.73
Chef Infra Client version: 15.7.32
Chef InSpec version: 4.18.51
Test Kitchen version: 2.3.4
Foodcritic version: 16.2.0
Cookstyle version: 5.20.0

[root@chefserver ~]#
  • Install Knife plugin to use with OCI.
[root@chefserver ~]# chef gem install knife-oci
+---------------------------------------------+
            Chef License Acceptance

Before you can continue, 3 product licenses
must be accepted. View the license at
End User License Agreement
Licenses that need accepting: * Chef Development Kit * Chef Infra Client * Chef InSpec Do you accept the 3 product licenses (yes/no)? > yes Persisting 3 product licenses... ? 3 product licenses persisted. +---------------------------------------------+ Fetching oci-2.7.0.gem Fetching knife-oci-2.0.2.gem WARNING: You don't have /root/.chefdk/gem/ruby/2.6.0/bin in your PATH, gem executables will not run. Successfully installed oci-2.7.0 Successfully installed knife-oci-2.0.2 2 gems installed [root@chefserver ~]#

 

Following are the knife-oci plugin commands available.

  1. knife oci ad list
  2. knife oci compartment list
  3. knife oci image list
  4. knife oci server create
  5. knife oci server delete
  6. knife oci server list
  7. knife oci server show
  8. knife oci shape list
  9. knife oci subnet list
  10. knife oci vcn list
  • Collect your OCI account details for connection and save it into file.
  1.  User OCID
  2.  API KEY in PEM format
  3.  Fingerprint
  4.  Tenancy OCID
  5.  Region
  6.  Compartment OCID (Optional)
[root@chefserver ~]# cat /root/oci.txt
[DEFAULT]

user=ocid1.user.oc1..aaaaaaaag4xxjns4f5edfewlrjz7y74cgtbggdhnc6zzpmbkicgrxki6ftya

fingerprint=a3:a1:70:58:fc:e1:0e:7a:2a:13:b6:12:e1:26:19:9a

key_file=/root/.oci/oci_api_key.pem

tenancy=ocid1.tenancy.oc1..aaaaaaaasf5piu7vbf72x2ortivvc5wdisajtpwoupt66qkcdn5v74lgcrvq

region=us-ashburn-1
[root@chefserver ~]# 
  • Configure knife-oci plugin configuration file (kinfe.rb).
[root@chefserver ~]# cd /root/chef-repo/.chef
[root@chefserver .chef]# cat knife.rb
# See http://docs.chef.io/config_rb_knife.html for more information on knife configuration options

current_dir = File.dirname(__FILE__)
log_level                :info
log_location             STDOUT
node_name                "oraclehelp"
client_key               "#{current_dir}/oraclehelp.pem"
chef_server_url          "https://api.chef.io/organizations/oraclehelp"
cookbook_path            ["#{current_dir}/../cookbooks"]

knife[:oci_config_file] = '/root/oci.txt'
knife[:compartment_id] = 'ocid1.compartment.oc1..aaaaaaaahezm67s5hcf2pqbxtw6omyukbdevqycn5vxzylisuojd6hj5jx6q'
[root@chefserver .chef]#
  • Now test the OCI connection with Knife command to verify it.
[root@chefserver .chef]# knife oci ad 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
yQUJ:US-ASHBURN-AD-1
yQUJ:US-ASHBURN-AD-2
yQUJ:US-ASHBURN-AD-3
[root@chefserver .chef]#

In the next post, we can provision and manage resources from Chef Knife Plugin in OCI.

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.