chefenv 0.1.0 → 0.2.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.
- data/CHANGELOG.md +10 -0
- data/README.md +12 -8
- data/lib/chefenv.rb +38 -37
- data/lib/chefenv/version.rb +1 -1
- metadata +3 -2
data/CHANGELOG.md
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# 0.2.0
|
2
|
+
|
3
|
+
*Replaces shell outs with ruby code
|
4
|
+
*Allows setting your environments directory with CHEFENV_DIR
|
5
|
+
*Defaults environments directory to ~/.chefenv instead of ~/chef
|
6
|
+
|
7
|
+
# 0.1.0
|
8
|
+
|
9
|
+
*Basic functionality
|
10
|
+
*Allows switching between manually created environments
|
data/README.md
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
Manages multiple chef server/organization environments
|
4
4
|
|
5
|
+
|
5
6
|
## Installation
|
6
7
|
|
7
8
|
Add this line to your application's Gemfile:
|
@@ -18,30 +19,33 @@ Or install it yourself as:
|
|
18
19
|
|
19
20
|
## Usage
|
20
21
|
|
22
|
+
Environments are stored under CHEFENV_DIR/environments.
|
23
|
+
You can set the CHEFENV_DIR environment variable if you like. The default value is ~/.chefenv
|
24
|
+
|
25
|
+
Upgrade Note: This is different from version 0.1.0 - You should move your environment folders from
|
26
|
+
~/chef to ~/.chefenv/environments
|
27
|
+
|
21
28
|
Execute:
|
22
29
|
|
30
|
+
WARNING: If you have data stored under ~/.chef the init command will DELETE it!
|
31
|
+
|
23
32
|
$ chefenv init
|
24
33
|
|
25
|
-
This will
|
34
|
+
This will setup CHEFENV_DIR/environments and clear the current environment.
|
26
35
|
|
27
|
-
Create a directory under
|
36
|
+
Create a directory under CHEFENV_DIR/environments for each of your environments.
|
28
37
|
Put your knife.rb, .pem and any other files you need for that organization
|
29
38
|
under that folder. For example, for my hosted chef organization, I create
|
30
39
|
~/chef/hosted and put my knife.rb and .pem files in there. Additionally, this is
|
31
40
|
a reasonable place to put secret key files.
|
32
41
|
|
33
|
-
Once you have at least one folder
|
42
|
+
Once you have at least one environment folder you can
|
34
43
|
|
35
44
|
$ chefenv list
|
36
|
-
|
37
|
-
or
|
38
|
-
|
39
45
|
$ chefenv use ENVNAME
|
40
46
|
|
41
47
|
## Future Work
|
42
48
|
|
43
|
-
1. Allow using a different directory than ~/chef
|
44
|
-
1. Read the ~/.chef symlink to get the current env instead of using ~/chef/current file
|
45
49
|
1. Add tasks for creating/destroying organizations
|
46
50
|
|
47
51
|
## Contributing
|
data/lib/chefenv.rb
CHANGED
@@ -4,30 +4,27 @@ require "chefenv/version"
|
|
4
4
|
require 'pathname'
|
5
5
|
|
6
6
|
module ChefEnv
|
7
|
-
# Your code goes here...
|
8
7
|
class Tasks < Thor
|
9
8
|
|
10
9
|
desc "list", "list the available chef environments"
|
11
10
|
def list
|
12
11
|
current = current_environment
|
13
12
|
available_environments.each do |env|
|
14
|
-
puts "#{(env ==
|
13
|
+
puts "#{(env == current) ? '*' : ' '} #{env}"
|
15
14
|
end
|
16
|
-
if available_environments.
|
15
|
+
if available_environments.empty?
|
17
16
|
puts "No Environments Available"
|
18
17
|
end
|
19
18
|
end
|
20
19
|
|
21
20
|
desc "use ENV", "use a particular environment"
|
22
21
|
def use(env="")
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
puts "#{env} is not a known environment"
|
28
|
-
list
|
29
|
-
end
|
22
|
+
if available_environments.include?(env)
|
23
|
+
select_environment(env)
|
24
|
+
else
|
25
|
+
puts "'#{env}' is not a known environment."
|
30
26
|
end
|
27
|
+
list
|
31
28
|
end
|
32
29
|
|
33
30
|
desc "current", "display the name of the current environment"
|
@@ -37,47 +34,51 @@ module ChefEnv
|
|
37
34
|
|
38
35
|
desc "init", "initialize the environment"
|
39
36
|
def init()
|
40
|
-
FileUtils.mkdir_p(
|
41
|
-
|
37
|
+
FileUtils.mkdir_p(chefenv_dir) unless File.directory?(chefenv_dir)
|
38
|
+
FileUtils.mkdir_p(environments_dir) unless File.directory?(environments_dir)
|
39
|
+
FileUtils.safe_unlink(chef_dir)
|
40
|
+
list
|
41
|
+
end
|
42
42
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
puts "No environments are available"
|
48
|
-
else
|
49
|
-
puts "Trying to use '#{available.first}'"
|
50
|
-
use(available.first)
|
51
|
-
end
|
52
|
-
current = current_environment
|
53
|
-
list
|
54
|
-
return
|
43
|
+
no_tasks do
|
44
|
+
|
45
|
+
def chef_dir
|
46
|
+
File.expand_path("~/.chef")
|
55
47
|
end
|
56
48
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
list
|
62
|
-
return
|
49
|
+
def chefenv_dir
|
50
|
+
dir = ENV['CHEFENV_DIR'].to_s
|
51
|
+
dir = File.expand_path("~/.chefenv") if dir.empty?
|
52
|
+
dir
|
63
53
|
end
|
64
54
|
|
65
|
-
|
55
|
+
def environments_dir
|
56
|
+
File.expand_path('environments', chefenv_dir)
|
57
|
+
end
|
58
|
+
|
59
|
+
def environment_dir(environment)
|
60
|
+
File.expand_path(environment, environments_dir)
|
61
|
+
end
|
66
62
|
|
67
|
-
no_tasks do
|
68
63
|
def available_environments
|
69
|
-
Pathname.new(
|
64
|
+
Pathname.new(environments_dir).children.select { |c| c.directory? }.map { |d| d.basename.to_s }
|
65
|
+
end
|
66
|
+
|
67
|
+
def environment_available?(env)
|
68
|
+
available_environments.include?(env)
|
70
69
|
end
|
71
70
|
|
72
71
|
def select_environment(env)
|
73
|
-
|
74
|
-
|
75
|
-
|
72
|
+
unless current_environment == env
|
73
|
+
File.write(File.expand_path("#{chefenv_dir}/current"), env)
|
74
|
+
FileUtils.safe_unlink(chef_dir)
|
75
|
+
FileUtils.symlink(File.join(environments_dir, env), chef_dir)
|
76
|
+
end
|
76
77
|
end
|
77
78
|
|
78
79
|
def current_environment
|
79
80
|
begin
|
80
|
-
File.
|
81
|
+
Pathname.new(File.readlink(File.expand_path('~/.chef'))).split.last.to_s
|
81
82
|
rescue Errno::ENOENT
|
82
83
|
nil
|
83
84
|
end
|
data/lib/chefenv/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chefenv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-07-
|
12
|
+
date: 2013-07-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thor
|
@@ -36,6 +36,7 @@ extensions: []
|
|
36
36
|
extra_rdoc_files: []
|
37
37
|
files:
|
38
38
|
- .gitignore
|
39
|
+
- CHANGELOG.md
|
39
40
|
- Gemfile
|
40
41
|
- LICENSE.txt
|
41
42
|
- README.md
|