Skip to content

Commit

Permalink
Used one recipe instead of two
Browse files Browse the repository at this point in the history
  • Loading branch information
directdevops committed Jan 22, 2021
1 parent 91e4e18 commit e988753
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 8 deletions.
9 changes: 1 addition & 8 deletions Jan21/cookbooks/qtlampserver/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,5 @@
#
# Copyright:: 2021, The Authors, All Rights Reserved.

if node['platform'] == 'centos'
include_recipe 'qtlampserver::lamp_centos'
end

if node['platform'] == 'ubuntu'
include_recipe 'qtlampserver::lamp_ubuntu'
end

include_recipe 'qtlampserver::lamp'
include_recipe 'qtlampserver::phppage'
37 changes: 37 additions & 0 deletions Jan21/cookbooks/qtlampserver/recipes/lamp.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#
# Cookbook:: .
# Recipe:: lamp
#
# Copyright:: 2021, The Authors, All Rights Reserved.

package_name = nil
php_packages = nil
if node['platform'] == 'ubuntu'
apt_update 'update ubuntu packages' do
ignore_failure true
action :update
end
package_name = 'apache2'
php_packages = %w(php libapache2-mod-php php-mysql php-cli)

elsif node['platform'] == 'centos'
package_name = 'httpd'
php_packages = %w(php php-mysql php-fpm)

else
raise 'this cookbook is developed only for centos and ubuntu'
end

package package_name do
action :install
end

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

service package_name do
action :restart
end
29 changes: 29 additions & 0 deletions Jan21/cookbooks/qtlampserver/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 18.04' do
# for a complete list of available platforms and versions see:
# https://github.com/chefspec/fauxhai/blob/master/PLATFORMS.md
platform 'ubuntu', '18.04'

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

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

it 'converges successfully' do
expect { chef_run }.to_not raise_error
end
end
end
16 changes: 16 additions & 0 deletions Jan21/cookbooks/qtlampserver/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 InSpec reference, with examples and extensive documentation, can be
# found at https://www.inspec.io/docs/reference/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

0 comments on commit e988753

Please sign in to comment.