



- Create a linux machine, login into it and execute the following command:
curl -s https://omnitruck.chef.io/install.sh | sudo bash -s -- -P chefdk - Now we need to change the default ruby to point it to the chef ruby and not the system ruby. Execute the following command for it.
echo 'eval "$(chef shell-init bash)"' >> ~/.bash_profileNote:eval
is part of POSIX. Its an interface which can be a shell built-in.Its described in the "POSIX Programmer's Manual": http://www.unix.com/man-page/posix/1posix/eval/eval - construct command by concatenating arguments
It will take an argument and construct a command of it, which will be executed by the shell. This is the example of the manpage:1) foo=10 x=foo
2) y='$'$x
3) echo $y
4) $foo
5) eval y='$'$x
6) echo $y
7) 10- In the first line you define
$foo
with the value'10'
and$x
with the value'foo'
. - Now define
$y
, which consists of the string'$foo'
. The dollar sign must be escaped with'$'
. - To check the result,
echo $y
. - The result will be the string
'$foo'
- Now we repeat the assignment with
eval
. It will first evaluate$x
to the string'foo'
. Now we have the statementy=$foo
which will get evaluated toy=10
. - The result of
echo $y
is now the value'10'
.
This is a common function in many languages, e.g. Perl and JavaScript. - In the first line you define
- The chef shell-init bash command ouputs as follows:
export PATH="/opt/chefdk/bin:/root/.chefdk/gem/ruby/2.4.0/bin:/opt/chefdk/embedded/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/chefdk/gitbin"
export GEM_ROOT="/opt/chefdk/embedded/lib/ruby/gems/2.4.0"
export GEM_HOME="/root/.chefdk/gem/ruby/2.4.0"
export GEM_PATH="/root/.chefdk/gem/ruby/2.4.0:/opt/chefdk/embedded/lib/ruby/gems/2.4.0"
_chef_comp() {
local COMMANDS="exec env gem generate shell-init install update push push-archive show-policy diff provision export clean-policy-revisions clean-policy-cookbooks delete-policy-group delete-policy undelete verify"
COMPREPLY=($(compgen -W "$COMMANDS" -- ${COMP_WORDS[COMP_CWORD]} ))
}
complete -F _chef_comp chef
Thus eval command will execute the above arguments as a command and set all the necessary variables. - We then add these variables in .bash_profile file so that it is loaded for all the shell termnals. So load the .bash_profile by executing source ~/.bash_profile
Check by executing which chef and which ruby - Execute chef -v to check chef version. Output will be as follows:
chef-client version: 13.4.19
delivery version: master (73ebb72a6c42b3d2ff5370c476be800fee7e5427)
berks version: 6.3.1
kitchen version: 1.17.0
inspec version: 1.36.1 - Then execute the following:
yum install -y git yum-utils - Then configure git name and email:
git config --global user.name "Arati"
git config --global user.email "aratik711@gmail.com"
git config --global core.editor vi
git config --global color.ui auto - Add the docker repo with the following command:
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum makecache fast - Install docker container Engine with the following command:
yum -y install docker-ce - Enable and start the docker service:
systemctl enable docker
systemctl start docker - If you are not using the root user you will need to add your user to the docker group to execute docker commands:
sudo usermod -aG docker $USER - So as to avoid the systemd issue that occurs in the containers we will have to stop and disable the getty@tty1 service.
A getty is the generic name for a program which manages a terminal line and its connected terminal. Its purpose is to protect the system from unauthorized access. Generally, each getty process is started by systemd and manages a single terminal line.
sudo systemctl stop getty@tty1.service
sudo systemctl mask getty@tty1.service
Create a test network:
docker network create --subnet=10.1.1.0/24 testnet - Then install docker driver so that the test-kitchen can use it:
gem install kitchen-docker
You might get an error as follows:Fetching: mixlib-shellout-2.3.2.gem (100%)
ERROR: Error installing kitchen-docker:
mixlib-shellout requires Ruby version >= 2.2.
Then install the individual dependencies with the following commands:gem install mixlib-shellout -v 2.2.7
gem install test-kitchen -v 1.16.0
gem install kitchen-docker
Comments
Post a Comment