Last active
November 22, 2022 03:29
-
-
Save devops-school/986439fd8804a79e713a70a3451dbaf0 to your computer and use it in GitHub Desktop.
Chef in-built and common resource types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
chef-common-resource-types.rb | |
# =======package============== | |
package 'Install Apache' do | |
case node[:platform] | |
when 'redhat', 'centos' | |
package_name 'httpd' | |
when 'ubuntu', 'debian' | |
package_name 'apache2' | |
end | |
end | |
# =======service============== | |
service "tomcat" do | |
action :start | |
end | |
# =======user============== | |
user 'a user' do | |
comment 'A random user' | |
uid 1234 | |
gid 'groupname' | |
home '/home/random' | |
shell '/bin/bash' | |
password '$1$JJsvHslasdfjVEroftprNn4JHtDi' | |
end | |
# =======group============== | |
group 'name' do | |
append true, false # default value: false | |
comment String | |
excluded_members String, Array | |
gid String, Integer | |
group_name String # default value: 'name' unless specified | |
members String, Array | |
non_unique true, false # default value: false | |
system true, false # default value: false | |
action Symbol # defaults to :create if not specified | |
end | |
# =======template============== | |
template '/etc/motd' do | |
source 'motd.erb' | |
owner 'root' | |
group 'root' | |
mode '0755' | |
end | |
# =======cookbook_file============== | |
cookbook_file '/var/www/customers/public_html/index.php' do | |
source 'index.php' | |
owner 'web_admin' | |
group 'web_admin' | |
mode '0755' | |
action :create | |
end | |
# =======file============== | |
file '/var/www/customers/public_html/index.php' do | |
content '<html>This is a placeholder for the home page.</html>' | |
mode '0755' | |
owner 'web_admin' | |
group 'web_admin' | |
end | |
# =======directory============== | |
directory '/etc/apache2' do | |
owner 'root' | |
group 'root' | |
mode '0755' | |
action :create | |
end | |
# =======execute============== | |
execute 'apache_configtest' do | |
command '/usr/sbin/apachectl configtest' | |
end | |
execute 'Execute my script' do | |
user 'root' | |
cwd '/mydir' | |
command './myscript.sh' | |
end | |
execute 'Execute my script' do | |
user 'root' | |
cwd '/mydir' | |
command './myscript.sh' | |
command 'ls srini' #will fail | |
command 'ls' # will be successful | |
end | |
# =======cron============== | |
cron 'cookbooks_report' do | |
action :create | |
minute '0' | |
hour '0' | |
weekday '1' | |
user 'getchef' | |
mailto 'sysadmin@example.com' | |
home '/srv/supermarket/shared/system' | |
command %W{ | |
cd /srv/supermarket/current && | |
env RUBYLIB="/srv/supermarket/current/lib" | |
RAILS_ASSET_ID=`git rev-parse HEAD` RAILS_ENV="#{rails_env}" | |
bundle exec rake cookbooks_report | |
}.join(' ') | |
end | |
# ===================Bash======================= | |
bash 'Execute my script' do | |
user 'root' | |
cwd '/mydir' | |
code <<-EOH | |
./myscript.sh | |
EOH | |
end | |
bash 'Execute my script' do | |
user 'root' | |
cwd '/mydir' | |
code <<-EOH | |
./myscript.sh | |
ls srini ##This will fail | |
ls ## this will be successful | |
EOH | |
end | |
# ============== log ================ | |
log 'message' do | |
message 'A message add to the log.' | |
level :info | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment