selfbootstrap 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data/LICENSE +3 -0
- data/README.md +12 -0
- data/bin/selfbootstrap +10 -0
- data/certs/public/jimbodragon.pem +26 -0
- data/lib/selfbootstrap/nochef/berks.rb +108 -0
- data/lib/selfbootstrap/nochef/chef.rb +63 -0
- data/lib/selfbootstrap/nochef/chefrepo.rb +237 -0
- data/lib/selfbootstrap/nochef/commandline.rb +114 -0
- data/lib/selfbootstrap/nochef/defaultvalues.rb +258 -0
- data/lib/selfbootstrap/nochef/defaultworkstationresource.rb +95 -0
- data/lib/selfbootstrap/nochef/git.rb +128 -0
- data/lib/selfbootstrap/nochef/kitchen.rb +84 -0
- data/lib/selfbootstrap/nochef/knife.rb +95 -0
- data/lib/selfbootstrap/nochef/platforms.rb +54 -0
- data/lib/selfbootstrap/nochef/provisioners.rb +68 -0
- data/lib/selfbootstrap/nochef/selfbootstrap.rb +467 -0
- data/lib/selfbootstrap/nochef/ssh.rb +72 -0
- data/lib/selfbootstrap/nochef/suites.rb +46 -0
- data/lib/selfbootstrap/nochef/update.rb +62 -0
- data/lib/selfbootstrap/nochef/users.rb +106 -0
- data/lib/selfbootstrap/nochef/verifiers.rb +59 -0
- data/lib/selfbootstrap/nochef/workstation.rb +250 -0
- data/lib/selfbootstrap/nochef/workstationresource.rb +140 -0
- data/lib/selfbootstrap/nochef.rb +52 -0
- data/lib/selfbootstrap/withchef/chef.rb +120 -0
- data/lib/selfbootstrap/withchef/chefrepo.rb +84 -0
- data/lib/selfbootstrap/withchef/commandline.rb +40 -0
- data/lib/selfbootstrap/withchef/defaultvalues.rb +39 -0
- data/lib/selfbootstrap/withchef/git.rb +86 -0
- data/lib/selfbootstrap/withchef/selfbootstrap.rb +41 -0
- data/lib/selfbootstrap/withchef/users.rb +161 -0
- data/lib/selfbootstrap/withchef/workstation.rb +77 -0
- data/lib/selfbootstrap/withchef/workstationresource.rb +60 -0
- data/lib/selfbootstrap/withchef.rb +55 -0
- data/lib/selfbootstrap/withlogger/defaultvalues.rb +33 -0
- data/lib/selfbootstrap/withlogger/selfbootstrap.rb +41 -0
- data/lib/selfbootstrap/withlogger/workstationresource.rb +59 -0
- data/lib/selfbootstrap/withlogger.rb +52 -0
- data/lib/selfbootstrap.rb +132 -0
- data.tar.gz.sig +0 -0
- metadata +117 -0
- metadata.gz.sig +0 -0
@@ -0,0 +1,52 @@
|
|
1
|
+
#
|
2
|
+
# Chef Infra Documentation
|
3
|
+
# https://docs.chef.io/libraries/
|
4
|
+
#
|
5
|
+
|
6
|
+
#
|
7
|
+
# This module name was auto-generated from the cookbook name. This name is a
|
8
|
+
# single word that starts with a capital letter and then continues to use
|
9
|
+
# camel-casing throughout the remainder of the name.
|
10
|
+
#
|
11
|
+
|
12
|
+
require 'withchef'
|
13
|
+
require_relative 'nochef/selfbootstrap'
|
14
|
+
|
15
|
+
module ChefWorkstationInitialize
|
16
|
+
module SelfBootstrap
|
17
|
+
if respond_to? 'Chef'
|
18
|
+
include ChefWorkstationInitialize::SelfBootstrap::WithChef
|
19
|
+
else
|
20
|
+
include ChefWorkstationInitialize::SelfBootstrap::NoChef
|
21
|
+
end
|
22
|
+
|
23
|
+
module NoChef
|
24
|
+
include ChefWorkstationInitialize::SelfBootstrap::NoChef::SelfBootstrapHelpers
|
25
|
+
#
|
26
|
+
# Define the methods that you would like to assist the work you do in recipes,
|
27
|
+
# resources, or templates.
|
28
|
+
#
|
29
|
+
# def my_helper_method
|
30
|
+
# # help method implementation
|
31
|
+
# end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
#
|
37
|
+
# The module you have defined may be extended within the recipe to grant the
|
38
|
+
# recipe the helper methods you define.
|
39
|
+
#
|
40
|
+
# Within your recipe you would write:
|
41
|
+
#
|
42
|
+
# extend ChefWorkstationInitialize::SelfBootstrap::NoChefHelpers
|
43
|
+
#
|
44
|
+
# my_helper_method
|
45
|
+
#
|
46
|
+
# You may also add this to a single resource within a recipe:
|
47
|
+
#
|
48
|
+
# template '/etc/app.conf' do
|
49
|
+
# extend ChefWorkstationInitialize::SelfBootstrap::NoChefHelpers
|
50
|
+
# variables specific_key: my_helper_method
|
51
|
+
# end
|
52
|
+
#
|
@@ -0,0 +1,120 @@
|
|
1
|
+
# name 'Helper file for chef_workstation_initialize'
|
2
|
+
# maintainer 'Jimbo Dragon'
|
3
|
+
# maintainer_email 'jimbo_dragon@hotmail.com'
|
4
|
+
# license 'MIT'
|
5
|
+
# description 'Helper file for chef_workstation_initialize'
|
6
|
+
# version '0.1.0'
|
7
|
+
# chef_version '>= 16.6.14'
|
8
|
+
# issues_url 'https://github.com/jimbodragon/chef_workstation_initialize/issues'
|
9
|
+
# source_url 'https://github.com/jimbodragon/chef_workstation_initialize'
|
10
|
+
#
|
11
|
+
# Chef Infra Documentation
|
12
|
+
# https://docs.chef.io/libraries/
|
13
|
+
#
|
14
|
+
|
15
|
+
#
|
16
|
+
# This module name was auto-generated from the cookbook name. This name is a
|
17
|
+
# single word that starts with a capital letter and then continues to use
|
18
|
+
# camel-casing throughout the remainder of the name.
|
19
|
+
#
|
20
|
+
|
21
|
+
require_relative 'git'
|
22
|
+
|
23
|
+
module ChefWorkstationInitialize
|
24
|
+
module SelfBootstrap
|
25
|
+
module WithChef
|
26
|
+
module ChefHelpers
|
27
|
+
include ChefWorkstationInitialize::SelfBootstrap::WithChef::GitHelpers
|
28
|
+
|
29
|
+
def generate_secret_databag(databag_name, item_name)
|
30
|
+
generate_databag(databag_name, item_name, { secret: UnixCrypt::SHA512.build(SecureRandom.base64(12)) }, nil, :update)
|
31
|
+
end
|
32
|
+
|
33
|
+
def get_databag(databag_name, item_name, secret_databag_item = nil)
|
34
|
+
secret = nil
|
35
|
+
unless secret_databag_item.nil?
|
36
|
+
secret = get_databag(cookbook_name, secret_databag_item)
|
37
|
+
if secret.nil?
|
38
|
+
# chef_vault_secret "github_ssh_keys" do
|
39
|
+
# data_bag "github"
|
40
|
+
# admins ENV['USER'] # if ENV['USER'] != "root"
|
41
|
+
# clients [node[:name]]
|
42
|
+
# environment node[:chef_environment]
|
43
|
+
# raw_data({ENV['USER'] => {"private_key" => file_open("#{ENV["HOME"]}/.ssh/id_rsa.pub")}})
|
44
|
+
# search "*:*"
|
45
|
+
# action :create
|
46
|
+
# end
|
47
|
+
generate_secret_databag(cookbook_name, secret_databag_item)
|
48
|
+
secret = get_databag(cookbook_name, secret_databag_item)['secret']
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
case ChefVault::Item.data_bag_item_type(databag_name, item_name)
|
53
|
+
when :normal || :encrypted
|
54
|
+
data_bag_item(databag_name, item_name, secret)
|
55
|
+
when :vault
|
56
|
+
ChefVault::Item.load(databag_name, item_name)
|
57
|
+
end unless data_bag(databag_name).nil? || data_bag(databag_name).empty? || !data_bag(databag_name).include?(item_name)
|
58
|
+
end
|
59
|
+
|
60
|
+
def generate_databag(databag_name, item_name, raw_databag, secret_databag_item = nil, databag_action = :create)
|
61
|
+
chef_data_bag databag_name
|
62
|
+
|
63
|
+
generate_secret_databag(cookbook_name, secret_databag_item) unless secret_databag_item.nil?
|
64
|
+
|
65
|
+
debug_worklog("Generating databag #{databag_name} for item #{item_name} using the secret #{secret_databag_item.nil? ? 'no secret' : "#{get_databag(cookbook_name, secret_databag_item)['secret']} using encryption version #{Chef::Config[:data_bag_encrypt_version]}"} containing #{raw_databag}")
|
66
|
+
|
67
|
+
chef_data_bag_item item_name do
|
68
|
+
raw_json raw_databag
|
69
|
+
data_bag databag_name
|
70
|
+
unless secret_databag_item.nil?
|
71
|
+
encryption_version Chef::Config[:data_bag_encrypt_version].nil? ? 3 : Chef::Config[:data_bag_encrypt_version]
|
72
|
+
secret get_databag(cookbook_name, secret_databag_item)['secret']
|
73
|
+
encrypt true
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
if databag_action == :update
|
78
|
+
# dtbg = get_databag(databag_name, item_name, secret_databag_item)
|
79
|
+
# raw_databag['id'] = item_name if raw_databag['id'].nil?
|
80
|
+
# dtbg.raw_data = raw_databag
|
81
|
+
# dtbg.save
|
82
|
+
ruby_block "Update data bag item #{databag_name}/#{item_name}" do
|
83
|
+
block do
|
84
|
+
# extend ChefWorkstationInitialize::SelfBootstrap
|
85
|
+
extend ChefWorkstationInitialize::ChefHelpers
|
86
|
+
dtbg = get_databag(databag_name, item_name, secret_databag_item)
|
87
|
+
unless dtbg.nil?
|
88
|
+
raw_databag['id'] = item_name if raw_databag['id'].nil?
|
89
|
+
dtbg.raw_data = raw_databag
|
90
|
+
dtbg.save
|
91
|
+
end
|
92
|
+
end
|
93
|
+
action :run
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
#
|
103
|
+
# The module you have defined may be extended within the recipe to grant the
|
104
|
+
# recipe the helper methods you define.
|
105
|
+
#
|
106
|
+
# Within your recipe you would write:
|
107
|
+
#
|
108
|
+
# extend ChefWorkstationInitialize::ChefHelpers
|
109
|
+
#
|
110
|
+
# my_helper_method
|
111
|
+
#
|
112
|
+
# You may also add this to a single resource within a recipe:
|
113
|
+
#
|
114
|
+
# template '/etc/app.conf' do
|
115
|
+
# extend ChefWorkstationInitialize::ChefHelpers
|
116
|
+
# variables specific_key: my_helper_method
|
117
|
+
# end
|
118
|
+
#
|
119
|
+
|
120
|
+
# require_relative "../providers/git_resource"
|
@@ -0,0 +1,84 @@
|
|
1
|
+
# name 'Helper file for chef_workstation_initialize'
|
2
|
+
# maintainer 'Jimbo Dragon'
|
3
|
+
# maintainer_email 'jimbo_dragon@hotmail.com'
|
4
|
+
# license 'MIT'
|
5
|
+
# description 'Helper file for chef_workstation_initialize'
|
6
|
+
# version '0.1.0'
|
7
|
+
# chef_version '>= 16.6.14'
|
8
|
+
# issues_url 'https://github.com/jimbodragon/chef_workstation_initialize/issues'
|
9
|
+
# source_url 'https://github.com/jimbodragon/chef_workstation_initialize'
|
10
|
+
#
|
11
|
+
# Chef Infra Documentation
|
12
|
+
# https://docs.chef.io/libraries/
|
13
|
+
#
|
14
|
+
|
15
|
+
#
|
16
|
+
# This module name was auto-generated from the cookbook name. This name is a
|
17
|
+
# single word that starts with a capital letter and then continues to use
|
18
|
+
# camel-casing throughout the remainder of the name.
|
19
|
+
#
|
20
|
+
|
21
|
+
require_relative 'chef'
|
22
|
+
|
23
|
+
module ChefWorkstationInitialize
|
24
|
+
module SelfBootstrap
|
25
|
+
module WithChef
|
26
|
+
module ChefRepoHelpers
|
27
|
+
include ChefWorkstationInitialize::SelfBootstrap::WithChef::ChefHelpers
|
28
|
+
|
29
|
+
def define_cron_job
|
30
|
+
cron_d "chef_client_#{project_name}" do
|
31
|
+
if workstation_resource[:chef_boostrapped]
|
32
|
+
command 'chef-client'
|
33
|
+
else
|
34
|
+
command workstation_resource[:cron_chef_solo_command]
|
35
|
+
end
|
36
|
+
comment 'Run chef client periodicaly'
|
37
|
+
day workstation_resource[:cron]['day'] if workstation_resource[:cron]['day']
|
38
|
+
hour workstation_resource[:cron]['hour'] if workstation_resource[:cron]['hour']
|
39
|
+
minute workstation_resource[:cron]['minute'] if workstation_resource[:cron]['minute']
|
40
|
+
month workstation_resource[:cron]['month'] if workstation_resource[:cron]['month']
|
41
|
+
weekday workstation_resource[:cron]['weekday'] if workstation_resource[:cron]['weekday']
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def render_template(generated_path, source, **variables)
|
46
|
+
template generated_path do
|
47
|
+
extend ChefWorkstationInitialize::SelfBootstrap
|
48
|
+
cookbook workstation_resource[:cookbook_source]
|
49
|
+
source source
|
50
|
+
variables variables
|
51
|
+
end
|
52
|
+
template ::File.join(get_path(workstation_chef_repo_path), 'chefignore') do
|
53
|
+
extend ChefWorkstationInitialize::SelfBootstrap
|
54
|
+
cookbook workstation_resource[:cookbook_source]
|
55
|
+
source 'chefignore.erb'
|
56
|
+
variables(workstation: self)
|
57
|
+
action :create_if_missing
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
#
|
66
|
+
# The module you have defined may be extended within the recipe to grant the
|
67
|
+
# recipe the helper methods you define.
|
68
|
+
#
|
69
|
+
# Within your recipe you would write:
|
70
|
+
#
|
71
|
+
# extend ChefWorkstationInitialize::ChefHelpers
|
72
|
+
#
|
73
|
+
# my_helper_method
|
74
|
+
#
|
75
|
+
# You may also add this to a single resource within a recipe:
|
76
|
+
#
|
77
|
+
# template '/etc/app.conf' do
|
78
|
+
# extend ChefWorkstationInitialize::ChefHelpers
|
79
|
+
# variables specific_key: my_helper_method
|
80
|
+
# end
|
81
|
+
#
|
82
|
+
|
83
|
+
# require_relative "../providers/git_resource"
|
84
|
+
|
@@ -0,0 +1,40 @@
|
|
1
|
+
#
|
2
|
+
# Chef Infra Documentation
|
3
|
+
# https://docs.chef.io/libraries/
|
4
|
+
#
|
5
|
+
|
6
|
+
#
|
7
|
+
# This module name was auto-generated from the cookbook name. This name is a
|
8
|
+
# single word that starts with a capital letter and then continues to use
|
9
|
+
# camel-casing throughout the remainder of the name.
|
10
|
+
#
|
11
|
+
|
12
|
+
require_relative 'defaultvalues'
|
13
|
+
|
14
|
+
module ChefWorkstationInitialize
|
15
|
+
module SelfBootstrap
|
16
|
+
module WithChef
|
17
|
+
module CommandlineHelpers
|
18
|
+
include ChefWorkstationInitialize::SelfBootstrap::WithChef::DefaultValuesHelpers
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
#
|
25
|
+
# The module you have defined may be extended within the recipe to grant the
|
26
|
+
# recipe the helper methods you define.
|
27
|
+
#
|
28
|
+
# Within your recipe you would write:
|
29
|
+
#
|
30
|
+
# extend ChefWorkstationInitialize::CommandlineHelpers
|
31
|
+
#
|
32
|
+
# my_helper_method
|
33
|
+
#
|
34
|
+
# You may also add this to a single resource within a recipe:
|
35
|
+
#
|
36
|
+
# template '/etc/app.conf' do
|
37
|
+
# extend ChefWorkstationInitialize::CommandlineHelpers
|
38
|
+
# variables specific_key: my_helper_method
|
39
|
+
# end
|
40
|
+
#
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# name 'Helper file for chef_workstation_initialize'
|
2
|
+
# maintainer 'Jimbo Dragon'
|
3
|
+
# maintainer_email 'jimbo_dragon@hotmail.com'
|
4
|
+
# license 'MIT'
|
5
|
+
# description 'Helper file for chef_workstation_initialize'
|
6
|
+
# version '0.1.0'
|
7
|
+
# chef_version '>= 16.6.14'
|
8
|
+
# issues_url 'https://github.com/jimbodragon/chef_workstation_initialize/issues'
|
9
|
+
# source_url 'https://github.com/jimbodragon/chef_workstation_initialize'
|
10
|
+
#
|
11
|
+
# Chef Infra Documentation
|
12
|
+
# https://docs.chef.io/libraries/
|
13
|
+
#
|
14
|
+
|
15
|
+
#
|
16
|
+
# This module name was auto-generated from the cookbook name. This name is a
|
17
|
+
# single word that starts with a capital letter and then continues to use
|
18
|
+
# camel-casing throughout the remainder of the name.
|
19
|
+
#
|
20
|
+
|
21
|
+
module ChefWorkstationInitialize
|
22
|
+
module SelfBootstrap
|
23
|
+
module WithChef
|
24
|
+
module DefaultValuesHelpers
|
25
|
+
def generate_directory(dir_path)
|
26
|
+
directory get_path(dir_path) do
|
27
|
+
group workstation_resource[:group]
|
28
|
+
mode '0775'
|
29
|
+
recursive true
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def worklog(logstr)
|
34
|
+
Chef::Log.warn("\n\n(#{worklog_counter})WORKLOG:: #{logstr}\n\n")
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# name 'Helper file for chef_workstation_initialize'
|
2
|
+
# maintainer 'Jimbo Dragon'
|
3
|
+
# maintainer_email 'jimbo_dragon@hotmail.com'
|
4
|
+
# license 'MIT'
|
5
|
+
# description 'Helper file for chef_workstation_initialize'
|
6
|
+
# version '0.1.0'
|
7
|
+
# chef_version '>= 16.6.14'
|
8
|
+
# issues_url 'https://github.com/jimbodragon/chef_workstation_initialize/issues'
|
9
|
+
# source_url 'https://github.com/jimbodragon/chef_workstation_initialize'
|
10
|
+
#
|
11
|
+
# Chef Infra Documentation
|
12
|
+
# https://docs.chef.io/libraries/
|
13
|
+
#
|
14
|
+
|
15
|
+
#
|
16
|
+
# This module name was auto-generated from the cookbook name. This name is a
|
17
|
+
# single word that starts with a capital letter and then continues to use
|
18
|
+
# camel-casing throughout the remainder of the name.
|
19
|
+
#
|
20
|
+
|
21
|
+
require_relative 'commandline'
|
22
|
+
|
23
|
+
module ChefWorkstationInitialize
|
24
|
+
module SelfBootstrap
|
25
|
+
module WithChef
|
26
|
+
module GitHelpers
|
27
|
+
include ChefWorkstationInitialize::SelfBootstrap::WithChef::CommandlineHelpers
|
28
|
+
|
29
|
+
def get_git_submodule(git_name, git_info, action, compile_time)
|
30
|
+
# logger.warn("get_git_submodule of #{git_name} ==>\n#{git_info}")
|
31
|
+
worklog("get_git_submodule of #{git_name} ==>\n#{git_info}")
|
32
|
+
unless git_info.nil? || git_info['repository'].nil? || git_info['remote'].nil?
|
33
|
+
git_submodule git_name do
|
34
|
+
message "Get git_submodule #{git_name} for action #{action} at compile time #{compile_time} on remote '#{git_info['remote']}', repository #{git_info['repository']}, revision '#{git_info['revision']}', type '#{git_info['type']}', git_info '#{JSON.pretty_generate(git_info)}'"
|
35
|
+
# build_method build_method
|
36
|
+
destination (git_info['type'] == 'main_repo' || git_info['type'] == '' || git_info['type'].nil?) ? workstation_chef_repo_path : get_git_path(git_name)
|
37
|
+
repository git_info['repository']
|
38
|
+
revision git_info['revision']
|
39
|
+
remote git_info['remote']
|
40
|
+
checkout_branch "#{project_name}_#{workstation_resource[:environment]}"
|
41
|
+
additional_remotes git_info['additional_remotes'] if git_info['additional_remotes']
|
42
|
+
if git_info['submodules']
|
43
|
+
submodules generate_git_submodules(git_info['submodules'])
|
44
|
+
enable_submodules true
|
45
|
+
end
|
46
|
+
action action
|
47
|
+
compile_time compile_time
|
48
|
+
end ## end git
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def get_git_server(git_action)
|
53
|
+
git_server project_name do
|
54
|
+
repositories repository_list
|
55
|
+
userdatabag 'users'
|
56
|
+
secretdatabag cookbook_name
|
57
|
+
secretdatabagitem 'cookbook_secret_keys'
|
58
|
+
secretdatabagkey 'secret'
|
59
|
+
userdatabagkey 'decompose_public_key'
|
60
|
+
action git_action
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
#
|
69
|
+
# The module you have defined may be extended within the recipe to grant the
|
70
|
+
# recipe the helper methods you define.
|
71
|
+
#
|
72
|
+
# Within your recipe you would write:
|
73
|
+
#
|
74
|
+
# extend ChefWorkstationInitialize::ChefHelpers
|
75
|
+
#
|
76
|
+
# my_helper_method
|
77
|
+
#
|
78
|
+
# You may also add this to a single resource within a recipe:
|
79
|
+
#
|
80
|
+
# template '/etc/app.conf' do
|
81
|
+
# extend ChefWorkstationInitialize::ChefHelpers
|
82
|
+
# variables specific_key: my_helper_method
|
83
|
+
# end
|
84
|
+
#
|
85
|
+
|
86
|
+
# require_relative "../providers/git_resource"
|
@@ -0,0 +1,41 @@
|
|
1
|
+
#
|
2
|
+
# Chef Infra Documentation
|
3
|
+
# https://docs.chef.io/libraries/
|
4
|
+
#
|
5
|
+
|
6
|
+
#
|
7
|
+
# This module name was auto-generated from the cookbook name. This name is a
|
8
|
+
# single word that starts with a capital letter and then continues to use
|
9
|
+
# camel-casing throughout the remainder of the name.
|
10
|
+
#
|
11
|
+
|
12
|
+
require_relative 'workstationresource'
|
13
|
+
|
14
|
+
module ChefWorkstationInitialize
|
15
|
+
module SelfBootstrap
|
16
|
+
module WithChef
|
17
|
+
module SelfBootstrapHelpers
|
18
|
+
include ChefWorkstationInitialize::SelfBootstrap::WithChef::WorkstationResourceHelpers
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
#
|
25
|
+
# The module you have defined may be extended within the recipe to grant the
|
26
|
+
# recipe the helper methods you define.
|
27
|
+
#
|
28
|
+
# Within your recipe you would write:
|
29
|
+
#
|
30
|
+
# extend ChefWorkstationInitialize::WorkstationHelpers
|
31
|
+
#
|
32
|
+
# my_helper_method
|
33
|
+
#
|
34
|
+
# You may also add this to a single resource within a recipe:
|
35
|
+
#
|
36
|
+
# template '/etc/app.conf' do
|
37
|
+
# extend ChefWorkstationInitialize::WorkstationHelpers
|
38
|
+
# variables specific_key: my_helper_method
|
39
|
+
# end
|
40
|
+
#
|
41
|
+
|
@@ -0,0 +1,161 @@
|
|
1
|
+
# name 'Helper file for chef_workstation_initialize'
|
2
|
+
# maintainer 'Jimbo Dragon'
|
3
|
+
# maintainer_email 'jimbo_dragon@hotmail.com'
|
4
|
+
# license 'MIT'
|
5
|
+
# description 'Helper file for chef_workstation_initialize'
|
6
|
+
# version '0.1.0'
|
7
|
+
# chef_version '>= 16.6.14'
|
8
|
+
# issues_url 'https://github.com/jimbodragon/chef_workstation_initialize/issues'
|
9
|
+
# source_url 'https://github.com/jimbodragon/chef_workstation_initialize'
|
10
|
+
#
|
11
|
+
# Chef Infra Documentation
|
12
|
+
# https://docs.chef.io/libraries/
|
13
|
+
#
|
14
|
+
|
15
|
+
#
|
16
|
+
# This module name was auto-generated from the cookbook name. This name is a
|
17
|
+
# single word that starts with a capital letter and then continues to use
|
18
|
+
# camel-casing throughout the remainder of the name.
|
19
|
+
#
|
20
|
+
|
21
|
+
require_relative 'chefrepo'
|
22
|
+
|
23
|
+
module ChefWorkstationInitialize
|
24
|
+
module SelfBootstrap
|
25
|
+
module WithChef
|
26
|
+
module UsersHelpers
|
27
|
+
include ChefWorkstationInitialize::SelfBootstrap::WithChef::ChefRepoHelpers
|
28
|
+
|
29
|
+
def create_user(user, user_data)
|
30
|
+
user user do
|
31
|
+
extend Vbox::Helpers
|
32
|
+
extend UnixCrypt
|
33
|
+
debug_worklog("user_data = #{user_data[:password]}")
|
34
|
+
username user
|
35
|
+
gid workstation_resource[:group]
|
36
|
+
password UnixCrypt::SHA512.build(user_data[:password])
|
37
|
+
home user_data[:home]
|
38
|
+
shell user_data[:shell]
|
39
|
+
system user_data[:system]
|
40
|
+
manage_home user_data[:manage_home]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def create_group(groupname, groupcomment, users)
|
45
|
+
group groupname do
|
46
|
+
comment "#{groupname} #{groupcomment}"
|
47
|
+
action [:create, :modify]
|
48
|
+
append true
|
49
|
+
members users
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def generate_user_data(user, home = '')
|
54
|
+
extend ChefHelpers
|
55
|
+
|
56
|
+
if home.nil? || (home.is_a?(String) ? home.empty? : home)
|
57
|
+
home = ::File.join(::File.join('/', 'home'), user)
|
58
|
+
end
|
59
|
+
|
60
|
+
begin
|
61
|
+
user_data = get_databag(userdatabag, user, secretdatabagitem)
|
62
|
+
rescue Net::HTTPServerException => exception
|
63
|
+
user_data = nil
|
64
|
+
end
|
65
|
+
if user_data.nil?
|
66
|
+
node_user = node['infra_chef']['devops'][user]
|
67
|
+
user_data = {
|
68
|
+
name: user,
|
69
|
+
home: home,
|
70
|
+
password: SecureRandom.base64(16),
|
71
|
+
chefadmin: node_user.nil? == false ? !node_user['firstname'].empty? : false,
|
72
|
+
shell: ::File.join(::File.join('/', 'bin'), 'bash'),
|
73
|
+
system: true,
|
74
|
+
manage_home: true,
|
75
|
+
}
|
76
|
+
unless node_user.nil?
|
77
|
+
%w(name chefadmin shell system manage_home firstname lastname home email).each do |user_attr|
|
78
|
+
user_data[user_attr] = node_user[user_attr] if node_user[user_attr]
|
79
|
+
end
|
80
|
+
|
81
|
+
home = user_data['home'] if node_user['home']
|
82
|
+
end
|
83
|
+
generate_ssh_user_key(user, user_data)
|
84
|
+
|
85
|
+
sshdir = ::File.join(home, '.ssh')
|
86
|
+
privkey = ::File.join(sshdir, 'id_rsa')
|
87
|
+
pubkey = ::File.join(sshdir, 'id_rsa.pub')
|
88
|
+
authorisationkeysfile = ::File.join(sshdir, 'authorisation_keys')
|
89
|
+
knownhostfile = ::File.join(sshdir, 'known_host')
|
90
|
+
|
91
|
+
user_data.deep_merge({
|
92
|
+
decompose_public_key: {
|
93
|
+
key: file_read(pubkey).split(' ')[1],
|
94
|
+
keytype: file_read(pubkey).split(' ')[0],
|
95
|
+
comment: file_read(pubkey).split(' ')[2],
|
96
|
+
},
|
97
|
+
authorisation_keys: file_exist?(authorisationkeysfile) ? file_read(authorisationkeysfile) : '',
|
98
|
+
known_host: file_exist?(knownhostfile) ? file_read(knownhostfile) : '',
|
99
|
+
private_key: file_read(privkey),
|
100
|
+
public_key: file_read(pubkey),
|
101
|
+
})
|
102
|
+
else
|
103
|
+
user_data = user_data.raw_data
|
104
|
+
end
|
105
|
+
user_data
|
106
|
+
end
|
107
|
+
|
108
|
+
def generate_secret
|
109
|
+
chef_gem 'unix-crypt'
|
110
|
+
chef_gem 'ruby-shadow'
|
111
|
+
chef_gem 'securerandom'
|
112
|
+
|
113
|
+
require 'unix_crypt'
|
114
|
+
require 'shadow'
|
115
|
+
require 'securerandom'
|
116
|
+
|
117
|
+
ssh_known_hosts_entry 'localhost'
|
118
|
+
ssh_known_hosts_entry '127.0.0.1'
|
119
|
+
ssh_known_hosts_entry node['ipaddress']
|
120
|
+
ssh_known_hosts_entry node['fqdn']
|
121
|
+
ssh_known_hosts_entry 'github.com'
|
122
|
+
|
123
|
+
generate_databag(userdatabag, ENV['USER'], generate_user_data(ENV['USER'], ENV['HOME']), secretdatabagitem, :update) unless ENV['USER'] == 'root' && (ENV['HOME'] == '/home/vagrant' || ENV['HOME'] == '/root')
|
124
|
+
generate_databag(userdatabag, workstation_resource[:user], generate_user_data(workstation_resource[:user], workstation_resource[:home]), secretdatabagitem, :update)
|
125
|
+
node['infra_chef']['devops'].each_key do |chef_user|
|
126
|
+
generate_databag(userdatabag, chef_user, generate_user_data(chef_user), secretdatabagitem, :update)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def set_cookbook_user_secret_key
|
131
|
+
%w(chefserver virtualbox).each do |cookbook_attribute|
|
132
|
+
node.override[cookbook_attribute]['userdatabag'] = userdatabag
|
133
|
+
node.override[cookbook_attribute]['secretdatabag'] = secretdatabag
|
134
|
+
node.override[cookbook_attribute]['secretdatabagitem'] = secretdatabagitem
|
135
|
+
node.override[cookbook_attribute]['secretdatabagkey'] = secretdatabagkey
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
#
|
144
|
+
# The module you have defined may be extended within the recipe to grant the
|
145
|
+
# recipe the helper methods you define.
|
146
|
+
#
|
147
|
+
# Within your recipe you would write:
|
148
|
+
#
|
149
|
+
# extend ChefWorkstationInitialize::ChefHelpers
|
150
|
+
#
|
151
|
+
# my_helper_method
|
152
|
+
#
|
153
|
+
# You may also add this to a single resource within a recipe:
|
154
|
+
#
|
155
|
+
# template '/etc/app.conf' do
|
156
|
+
# extend ChefWorkstationInitialize::ChefHelpers
|
157
|
+
# variables specific_key: my_helper_method
|
158
|
+
# end
|
159
|
+
#
|
160
|
+
|
161
|
+
# require_relative "../providers/git_resource"
|