Enabled: false
Style/SpaceBeforeFirstArg:
Enabled: false
+Style/SpaceInsideBlockBraces:
+ Enabled: false
Style/TrailingCommaInLiteral:
- EnforcedStyleForMultiline: comma
+ EnforcedStyleForMultiline: consistent_comma
Style/WordArray:
Enabled: false
#Style/AccessorMethodName:
# Enabled: false
+Metrics/BlockLength:
+ Max: 50
Metrics/MethodLength:
Max: 60
Metrics/ModuleLength:
platform_utils CHANGELOG
========================
+0.5.0
+-----
+- adds the `platform_utils::pip` recipe.
+
0.4.4
-----
- improves the `platform_utils::kernel_modules` recipe.
require 'rspec/core/rake_task'
require 'rubocop/rake_task'
require 'foodcritic'
+require 'stove/rake_task'
namespace :style do
desc 'Run Ruby style checks'
- RuboCop::RakeTask.new(:ruby)
+ RuboCop::RakeTask.new(:ruby) do |t|
+ t.options = [
+ '--auto-gen-config', # creates .rubocop_todo.yml
+ ]
+ end
desc 'Run Chef style checks'
FoodCritic::Rake::LintTask.new(:chef) do |t|
desc 'Run ChefSpec examples'
RSpec::Core::RakeTask.new(:spec)
+desc 'Publish cookbook'
+Stove::RakeTask.new(:publish) do |t|
+ t.stove_opts = [
+ # `--username` and `--key` are set in ~/.stove typically.
+ #'--username', 'somebody',
+ #'--key', '~/chef/chef.io.example.com/somebody.pem',
+ #'--endpoint', 'https://supermarket.io.example.com/api/v1', # default: supermarket.chef.io
+ #'--no-ssl-verify',
+ '--no-git',
+ '--log-level', 'info',
+ ]
+end
+
task default: ['style', 'spec']
--- /dev/null
+---
+# $ fly -t $CC_TARGET sp -p platform_utils-cookbook -c concourse.yml -l fly-vars.yml -l ~/sec/credentials-prod.yml
+resources:
+- name: src-git
+ type: git
+ source:
+ uri: ((git-id-osdn))@git.osdn.net:/gitroot/metasearch/grid-chef-repo.git
+ branch: master
+ paths:
+ - cookbooks/((cookbook-name))
+ private_key: ((git-private-key))
+ git_user: ((git-user-osdn))
+ #check_every: 1h # default: 1m
+- name: chefdk-cache
+ type: docker-image
+ source:
+ repository: chef/chefdk
+ tag: ((chefdk-version))
+ # ((param)) style: fly >= 3.2.0
+ registry_mirror: https://((registry-mirror-domain)) # e.g. https://registry.docker.example.com:5000
+ ca_certs:
+ - domain: ((registry-mirror-domain)) # e.g. registry.docker.example.com:5000
+ cert: ((docker-reg-ca-cert))
+ check_every: 6h # default: 1m
+
+jobs:
+- name: test-cookbook
+ plan:
+ - aggregate:
+ - get: src-git
+ params:
+ depth: 5
+ trigger: true
+ - get: chefdk-cache
+ - task: ci-build
+ image: chefdk-cache
+ params:
+ http_proxy: ((http-proxy)) # e.g. http://proxy.example.com:3128
+ #HTTP_PROXY: ((http-proxy))
+ config:
+ platform: linux
+ #image_resource:
+ # type: docker-image
+ # source:
+ # repository: chef/chefdk
+ # tag: ((chefdk-version))
+ # NG, setting disable
+ #registry_mirror: https://((registry-mirror-domain))
+ #ca_certs:
+ #- domain: ((registry-mirror-domain))
+ # cert: ((docker-reg-ca-cert))
+ inputs:
+ - name: src-git
+ run:
+ #dir: ./src-git/cookbooks/((cookbook-name))
+ #path: rake
+ path: /bin/bash
+ args:
+ - -c
+ - |
+ cd ./src-git/cookbooks/((cookbook-name))
+ bundle install
+ rake
+- name: publish-cookbook
+ plan:
+ - aggregate:
+ - get: src-git
+ params:
+ depth: 5
+ trigger: false
+ passed: [test-cookbook]
+ - get: chefdk-cache
+ passed: [test-cookbook]
+ - task: publish
+ image: chefdk-cache
+ params:
+ http_proxy: ((http-proxy))
+ chef_username: ((chef-username))
+ chef_client_key: ((chef-client-key))
+ config:
+ platform: linux
+ inputs:
+ - name: src-git
+ run:
+ path: /bin/bash
+ args:
+ - -c
+ - |
+ echo '{"username":"((chef-username))","key":"/root/chef-client-key.pem"}' > /root/.stove
+ echo "$chef_client_key" > /root/chef-client-key.pem
+ cd ./src-git/cookbooks/((cookbook-name))
+ bundle install
+ rake publish
+ - put: src-git
+ params:
+ repository: src-git
+ tag_prefix: ((cookbook-name))-
+ tag: src-git/cookbooks/((cookbook-name))/version
+ only_tag: true
+ annotate: src-git/cookbooks/((cookbook-name))/version
--- /dev/null
+---
+cookbook-name: platform_utils
+chefdk-version: 1.4.3
include PlatformUtils::VirtUtils
def load_kernel_module(mod_name)
- unless container_guest_node?
- # for old distributions.
- dir = '/etc/modules-load.d'
- resources(directory: dir) rescue directory dir do
- owner 'root'
- group 'root'
- mode '0755'
- end
+ return if container_guest_node?
+
+ # for old distributions.
+ dir = '/etc/modules-load.d'
+ resources(directory: dir) rescue directory dir do
+ owner 'root'
+ group 'root'
+ mode '0755'
+ end
- exec_name = "load_#{mod_name}_kernel_module"
- resources(execute: exec_name) rescue execute exec_name do
- command "modprobe #{mod_name}"
- not_if "lsmod | grep #{mod_name}"
- end
+ exec_name = "load_#{mod_name}_kernel_module"
+ resources(execute: exec_name) rescue execute exec_name do
+ command "modprobe #{mod_name}"
+ not_if "lsmod | grep #{mod_name}"
+ end
- file_name = "/etc/modules-load.d/#{mod_name}.conf"
- resources(file: file_name) rescue file file_name do
- content "#{mod_name}\n"
- owner 'root'
- group 'root'
- mode '0644'
- end
+ file_name = "/etc/modules-load.d/#{mod_name}.conf"
+ resources(file: file_name) rescue file file_name do
+ content "#{mod_name}\n"
+ owner 'root'
+ group 'root'
+ mode '0644'
end
end
invalid_word = words.find {|word|
word =~ /[;\|&<>`]/
}
- unless invalid_word.nil?
- Chef::Log.fatal("Command string includes the invalid character (;|&<>`): #{invalid_word}")
- raise
- end
+
+ return if invalid_word.nil?
+ Chef::Log.fatal("Command string includes the invalid character (;|&<>`): #{invalid_word}")
+ raise
end
def touch_subid_files
module PackageUtils
def cron_pkg_name
case node['platform_family']
- when 'debian'then return 'cron'
- when 'rhel' then return 'crontabs'
+ when 'debian'then 'cron'
+ when 'rhel' then 'crontabs'
end
end
def cron_serv_name
case node['platform_family']
- when 'debian'then return 'cron'
- when 'rhel' then return 'crond'
+ when 'debian'then 'cron'
+ when 'rhel' then 'crond'
end
end
def httpd_pkg_name
case node['platform_family']
- when 'debian'then return 'apache2'
- when 'rhel' then return 'httpd'
+ when 'debian'then 'apache2'
+ when 'rhel' then 'httpd'
end
end
def httpd_serv_name
case node['platform_family']
- when 'debian'then return 'apache2'
- when 'rhel' then return 'httpd'
+ when 'debian'then 'apache2'
+ when 'rhel' then 'httpd'
end
end
def jsvc_pkg_name
case node['platform_family']
- when 'debian' then return 'jsvc'
- when 'rhel' then return 'jakarta-commons-daemon-jsvc'
+ when 'debian' then 'jsvc'
+ when 'rhel' then 'jakarta-commons-daemon-jsvc'
end
end
def libbz2_pkg_name
case node['platform_family']
- when 'debian' then return 'libbz2-1.0'
- when 'rhel' then return 'bzip2-libs'
+ when 'debian' then 'libbz2-1.0'
+ when 'rhel' then 'bzip2-libs'
end
end
end
license 'Apache 2.0'
description 'Platform Utilities'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
-version '0.4.4'
+version IO.read(File.join(File.dirname(__FILE__), 'version')).chomp
source_url 'http://scm.osdn.jp/gitroot/metasearch/grid-chef-repo.git'
issues_url 'https://osdn.jp/projects/metasearch/ticket'
-%w( centos redhat debian ubuntu ).each do |os|
+chef_version '>= 12'
+%w(centos redhat debian ubuntu).each do |os|
supports os
end
--- /dev/null
+#
+# Cookbook Name:: platform_utils
+# Recipe:: pip
+#
+# Copyright 2018, whitestar
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+case node['platform_family']
+when 'debian'
+ pkgs = [
+ 'python-setuptools',
+ 'python-pip',
+ ]
+ pkgs.each {|pkg|
+ resources(package: pkg) rescue package pkg do
+ action :install
+ end
+ }
+when 'rhel'
+ pkg = 'python-setuptools'
+ resources(package: pkg) rescue package pkg do
+ action :install
+ end
+
+ execute 'install_pip' do
+ user 'root'
+ command 'easy_install pip'
+ action :run
+ not_if 'which pip'
+ end
+end
)
sudo_members = node['platform_utils']['sudo']['group']['members']
-group "append_#{sudo_members.join('_')}_to_#{sudo_group}_group" do
- group_name sudo_group
- action :modify
- members sudo_members
- append true
-end unless sudo_members.empty?
+unless sudo_members.empty?
+ group "append_#{sudo_members.join('_')}_to_#{sudo_group}_group" do
+ group_name sudo_group
+ action :modify
+ members sudo_members
+ append true
+ end
+end