Debug School

ambati.raghavareddy@gmail.com
ambati.raghavareddy@gmail.com

Posted on

Chef Day1 Assignment

Write a recipe to create a file which should be owned by group called “root”, user “ec2-user” and permission executable.

user 'ec2-user' do
action :create
end
file 'hostfile' do
content '10.30.2.44 hello
10.30.4.50 boss
22.123.44.11 ATM
33.44.56.7 Branch'
mode '0755'
owner 'ec2-user'
group 'root'
end

Write a recipe to updates the access (atime) and file modification (mtime) times for a file.

user 'ec2-user' do
action :create
end
file 'hostfile' do
content '10.30.2.44 hello
10.30.4.50 boss
33.44.56.7 Branch'
mode '0755'
owner 'ec2-user'
group 'root'
action :create
action :touch
end

Write a recipe to download the java tar ball, extract it under /opt/ and set JAVA_HOME using bash resources. Note – https://jdk.java.net/archive/

file 'javainstall.sh' do
content 'wget https://download.java.net/java/GA/jdk18.0.2/f6ad4b4450fd4d298113270ec84f30ee/9/GPL/openjdk-18.0.2_linux-aarch64_bin.tar.gz
gunzip openjdk-18.0.2_linux-aarch64_bin.tar.gz
tar -xvf openjdk-18.0.2_linux-aarch64_bin.tar -C /opt/
export JAVA_HOME=/opt/jdk-18.0.2'
mode '0755'
owner 'root'
group 'root'
end
execute 'Execute my script' do
user 'root'
cwd '/root/chefday1'
command './javainstall.sh'
end

Write a chef recipe to execute one sample bash script.

file 'shellscript.sh' do
content '
ls -ltr;
pwd'
mode '0755'
owner 'root'
group 'root'
end
execute 'Execute my script' do
user 'root'
cwd '/root/chefday1'
command './shellscript.sh'
end

Write a chef recipe to Create a directory
user 'nfast' do
action :create
end
group 'nfast' do
members 'nfast'
action :create
end
directory '/opt/nfast/kmdata/local' do
recursive true
owner 'nfast'
group 'nfast'
mode '0755'
action:create
end

**
Write a chef recipe to install git.**
package 'git' do
action :install
end

**
Write a chef recipe to clone git repo https://github.com/scmgalaxy/chef-repo**

git 'gitclone' do
remote 'origin'
repository 'https://github.com/scmgalaxy/chef-repo'
user 'root'
action :sync
end

Write a chef recipe to create group and use in linux.

group 'nfast' do
members 'nfast'
action :create
end

Write a chef recipe to Download a file from a URL. Note –https://raw.githubusercontent.com/scmgalaxy/chef-repo/master/README.md

bash 'downloadfile' do
user 'root'
cwd '/root/chefday1'
code <<-EOH
wget https://raw.githubusercontent.com/scmgalaxy/chef-repo/master/README.md
EOH
end

**
Write a chef recipe to create a new user and password in the Nodes automatically?**

user 'raghu' do
comment 'create raghu user'
uid 9999
gid 'nfast'
home '/home/raghu'
shell '/bin/bash'
password '$1$JJsvHslasdfjVEroftprNn4JHtDi'
end

**
Write a chef recipe to add= a message to a log file.**

log 'mymessage' do
message 'A message add to the log.'
level :info
action :write
end

Top comments (0)