# frozen_string_literal: true require 'json' require_relative 'deploy_rubygem/version' require_relative 'deploy_rubygem/rubygem' # DeployRubygem module helper for rubygem module DeployRubygem def no_option_txt 'Use "deploy_rubygem install" to install Chef dependencies' end def rubygem_test DeployRubygem.deployer end def self.exemple_cookbook { git: 'git@git.exemple.com:/Exemple/exemple_cookbook.git', path: File.join(Dir.home, 'jimbo_management_site'), kitchens: %w[base], compliance_profiles: { input: 'compliance/inputs/user.yml', profile: 'jimbodragon-management-site' }, execute_profiles: %w[jimbodragon-accept], groups: %w[base] } end def self.deployer chefrepo_path = File.join(%w[test exemple chefrepo]) project_options = { project_name: 'rubygem_test', git: 'git@git.exemple.com:/Exemple/rubygem', chefrepo_git: 'git@git.exemple.com:/Exemple/chefrepo', chefrepo_path: chefrepo_path, binaries: %w[exemple_deploy], dependencies: %w[deploy_rubygem], path: File.join(chefrepo_path, %w[projects rubygem_test]), cookbooks: { exemple_cookbook: exemple_cookbook } } @deployer ||= DeployRubygem::Project.new(project_options) end def install_chef_workstation workstation_options = { user_folder: '/root', node_name: ENV.fetch('NODENAME'), knife_name: ENV.fetch('KNIFE_NAME'), policyname: ENV.fetch('POLICYNAME'), policygroup: ENV.fetch('POLICYGROUP'), chef_server_url: ENV.fetch('CHEF_SERVER_URL'), chef_client_key: ENV.fetch('CHEF_CLIENT_KEY'), chef_knife_key: ENV.fetch('CHEF_KNIFE_KEY') } File.write('node_options', JSON.generate(workstation_options)) system('sudo deploy_rubygem bootstrap node_options') workstation_options[:user_folder] = Dir.home File.write('workstation_options', JSON.generate(workstation_options)) system('deploy_rubygem bootstrap workstation_options') end def bootstrap_chef_workstation(option_file) workstation_options = JSON.parse(File.read(option_file)) if workstation_options['user_folder'] == '/root' DeployRubygem::ChefAdmin.new(workstation_options).boostrap else DeployRubygem::Workstation.new(workstation_options).boostrap_workstation end end end