Skip to content

Commit

Permalink
Added Hash example
Browse files Browse the repository at this point in the history
  • Loading branch information
qtsathish committed Jun 1, 2021
1 parent e3bf671 commit 0ec4931
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 32 deletions.
33 changes: 2 additions & 31 deletions May21/cookbooks/lampserver/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,6 @@
# Recipe:: default
#
# Copyright:: 2021, The Authors, All Rights Reserved.
# recipe => lampserver::default => lampserver

# sudo apt update
# https://docs.chef.io/resources/apt_update/

apt_update 'update packages' do
ignore_failure true
action :update
end

# sudo apt install apache2 -y
# We can use apt_package resource or common package resource

package 'apache2' do
action :install
end

# sudo apt install php libapache2-mod-php php-mysql php-cli -y
php_packages = %w(php libapache2-mod-php php-mysql php-cli)

php_packages.each do |php_package|
package php_package do
action :install
end
end


# echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php

file '/var/www/html/info.php' do
content '<?php phpinfo(); ?>'
action :create
end
include_recipe 'lampserver::lamp'
38 changes: 38 additions & 0 deletions May21/cookbooks/lampserver/recipes/lamp.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#
# Cookbook:: lampserver
# Recipe:: lamp
#
# Copyright:: 2021, The Authors, All Rights Reserved.
# recipe => lampserver::lamp

# sudo apt update
# https://docs.chef.io/resources/apt_update/

apt_update 'update packages' do
ignore_failure true
action :update
end

# sudo apt install apache2 -y
# We can use apt_package resource or common package resource

package 'apache2' do
action :install
end

# sudo apt install php libapache2-mod-php php-mysql php-cli -y
php_packages = %w(php libapache2-mod-php php-mysql php-cli)

php_packages.each do |php_package|
package php_package do
action :install
end
end


# echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php

file '/var/www/html/info.php' do
content '<?php phpinfo(); ?>'
action :create
end
2 changes: 2 additions & 0 deletions May21/cookbooks/lampserver/spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require 'chefspec'
require 'chefspec/berkshelf'
29 changes: 29 additions & 0 deletions May21/cookbooks/lampserver/spec/unit/recipes/lamp_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#
# Cookbook:: .
# Spec:: lamp
#
# Copyright:: 2021, The Authors, All Rights Reserved.

require 'spec_helper'

describe '.::lamp' do
context 'When all attributes are default, on Ubuntu 20.04' do
# for a complete list of available platforms and versions see:
# https://github.com/chefspec/fauxhai/blob/master/PLATFORMS.md
platform 'ubuntu', '20.04'

it 'converges successfully' do
expect { chef_run }.to_not raise_error
end
end

context 'When all attributes are default, on CentOS 8' do
# for a complete list of available platforms and versions see:
# https://github.com/chefspec/fauxhai/blob/master/PLATFORMS.md
platform 'centos', '8'

it 'converges successfully' do
expect { chef_run }.to_not raise_error
end
end
end
16 changes: 16 additions & 0 deletions May21/cookbooks/lampserver/test/integration/default/lamp_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# InSpec test for recipe .::lamp

# The Chef InSpec reference, with examples and extensive documentation, can be
# found at https://docs.chef.io/inspec/resources/

unless os.windows?
# This is an example test, replace with your own test.
describe user('root'), :skip do
it { should exist }
end
end

# This is an example test, replace it with your own test.
describe port(80), :skip do
it { should_not be_listening }
end
17 changes: 16 additions & 1 deletion May21/ruby/learning.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,19 @@

courses.each do |course|
puts(course)
end
end

# hash
# it is list of keys and values
qt = {
'name' => 'QualityThought',
'courses' => %w(DevOps AWS Azure),
'address' => {
'building' => '209, Nilgiri Block',
'landmark' => 'ameerpet metro',
'city' => 'hyderabad'
},
}

puts(qt['name'])
puts(qt['address']['landmark'])

0 comments on commit 0ec4931

Please sign in to comment.