vagrant-useradd 0.0.1
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
- data/.gitignore +34 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +55 -0
- data/Rakefile +2 -0
- data/lib/vagrant-useradd.rb +4 -0
- data/lib/vagrant-useradd/action.rb +55 -0
- data/lib/vagrant-useradd/config.rb +21 -0
- data/lib/vagrant-useradd/plugin.rb +17 -0
- data/lib/vagrant-useradd/version.rb +5 -0
- data/vagrant-useradd.gemspec +23 -0
- metadata +83 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ef5f12c8e4c9ad99e82d1752ec26ca176a12dc8c
|
4
|
+
data.tar.gz: e1afb08048b8d6adb24781f3b630747c54f545f3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 11d045bc162ad0ebc60ae4ecf2eaefbfa2c70c1c58cdafe118ab9b8e659c0feffd6538296b6494bea36494c45be52641bc6e997c930f15ab9a77dec1c2a750d2
|
7
|
+
data.tar.gz: 8039098ff280c46fef514c3ce1c4c3d2d6bcc48bc24871536cf5de46ccafabe43ead07075890585561061806648c144c61a9cb46e16b03e7c550df9b9bdfc204
|
data/.gitignore
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/test/tmp/
|
9
|
+
/test/version_tmp/
|
10
|
+
/tmp/
|
11
|
+
|
12
|
+
## Specific to RubyMotion:
|
13
|
+
.dat*
|
14
|
+
.repl_history
|
15
|
+
build/
|
16
|
+
|
17
|
+
## Documentation cache and generated files:
|
18
|
+
/.yardoc/
|
19
|
+
/_yardoc/
|
20
|
+
/doc/
|
21
|
+
/rdoc/
|
22
|
+
|
23
|
+
## Environment normalisation:
|
24
|
+
/.bundle/
|
25
|
+
/lib/bundler/man/
|
26
|
+
|
27
|
+
# for a library or gem, you might want to ignore these files since the code is
|
28
|
+
# intended to run in multiple environments; otherwise, check them in:
|
29
|
+
# Gemfile.lock
|
30
|
+
# .ruby-version
|
31
|
+
# .ruby-gemset
|
32
|
+
|
33
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
34
|
+
.rvmrc
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Jeff George
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# vagrant-useradd
|
2
|
+
|
3
|
+
_vagrant-useradd_ is a [Vagrant](http://vagrantup.com/) plugin that lets you inject arbitrary Unix users and groups into a Vagrant base box.
|
4
|
+
|
5
|
+
Why? Race conditions, mostly. I feel Vagrant boxes should just contain your environment and versionable configuration, not your actual application, data and state. So you should be able to completely blow out a Vagrant box, reload it, reprovision it, and be back to a steady-state.
|
6
|
+
|
7
|
+
I've accomplished this in the past by mounting key data directories like Apache docroots and MySQL data directories outside of the box, so they don't fill up virtual disks and survive a rebuild . . . but that requires quite a bit of juggling, convincing core services to run as the user "vagrant" and various other equally terrible things.
|
8
|
+
|
9
|
+
However, if you could mount a data directory as Apache or MySQL most of these problems would conveniently disappear, but vboxfs mounts don't work if the guest doesn't already have the user or group present. So we need some way to forcibly inject users and groups before mounting. Thus, this module.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
```
|
14
|
+
$ vagrant plugin install vagrant-useradd
|
15
|
+
```
|
16
|
+
|
17
|
+
### Or pull it from source
|
18
|
+
|
19
|
+
- Clone the repo.
|
20
|
+
- Build it
|
21
|
+
```
|
22
|
+
$ rake build
|
23
|
+
```
|
24
|
+
- Install the gem as a vagrant plugin
|
25
|
+
```
|
26
|
+
$ vagrant plugin install pkg/vagrant-useradd*.gem
|
27
|
+
```
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
_vagrant-useradd_ has two options for how you can define your userlist.
|
32
|
+
|
33
|
+
If you just need the default group matching the user's name, you can do:
|
34
|
+
|
35
|
+
```
|
36
|
+
config.useradd.users = ['apache','mysql']
|
37
|
+
```
|
38
|
+
|
39
|
+
If you need to define extra groups (like, Apache's 'www-data' group on Debian-based distros), you can build a hash:
|
40
|
+
|
41
|
+
```
|
42
|
+
config.useradd.users = {
|
43
|
+
'apache' => ['www-data'],
|
44
|
+
'mysql' => nil,
|
45
|
+
'somebody-else' => ['one','or-more','groups']
|
46
|
+
}
|
47
|
+
```
|
48
|
+
|
49
|
+
Note that extra groups are being added *destructively*. So if a provisioning run happens and modifies one of these users, when you reload it's going to be forcibly reset to what you've specified.
|
50
|
+
|
51
|
+
## Contributing
|
52
|
+
|
53
|
+
1. Fork it
|
54
|
+
2. Hack on a branch
|
55
|
+
3. Send a Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Useradd
|
3
|
+
# Action to add users & groups
|
4
|
+
class Action
|
5
|
+
include Vagrant::Action::Builtin
|
6
|
+
|
7
|
+
# Constructor
|
8
|
+
#
|
9
|
+
# @param app [Action] Next middleware to call
|
10
|
+
# @param env [Hash] Action environment
|
11
|
+
# @return nil
|
12
|
+
#
|
13
|
+
def initialize(app, env)
|
14
|
+
@app = app
|
15
|
+
@env = env
|
16
|
+
end
|
17
|
+
|
18
|
+
# Call method of this middleware
|
19
|
+
#
|
20
|
+
# @param env [Hash] Action environment
|
21
|
+
# @return nil
|
22
|
+
#
|
23
|
+
def call(env)
|
24
|
+
# Figure out if we should even try adding stuff
|
25
|
+
if @env[:machine] && @env[:machine].state.id != :poweroff && !@env[:machine].config.useradd.users.nil?
|
26
|
+
@env[:machine].config.useradd.users.each do |user,groups|
|
27
|
+
# Check and add any missing groups
|
28
|
+
if !groups.nil?
|
29
|
+
groups.each do |group|
|
30
|
+
if !@env[:machine].communicate.test("getent group #{group}")
|
31
|
+
@env[:ui].info "vagrant-useradd - Adding group '#{group}'..."
|
32
|
+
@env[:machine].communicate.sudo("groupadd #{group}")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
group_list = groups.nil? ? nil : " -G " + groups.join(",")
|
38
|
+
|
39
|
+
# Check to see if this user has already been added
|
40
|
+
if !@env[:machine].communicate.test("getent passwd #{user}")
|
41
|
+
@env[:ui].info "vagrant-useradd - Adding user '#{user}'..."
|
42
|
+
@env[:machine].communicate.sudo("useradd#{group_list} -M #{user}")
|
43
|
+
else
|
44
|
+
if !groups.nil?
|
45
|
+
@env[:ui].info "vagrant-useradd - Setting groups for user '#{user}'..."
|
46
|
+
@env[:machine].communicate.sudo("usermod#{group_list} #{user}")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
@app.call(env)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Useradd
|
3
|
+
# Configuration options
|
4
|
+
class Config < Vagrant.plugin("2", "config")
|
5
|
+
attr_accessor :users
|
6
|
+
|
7
|
+
# Initialize override, setting config options default values
|
8
|
+
# for merging
|
9
|
+
def initialize
|
10
|
+
super
|
11
|
+
|
12
|
+
@users = UNSET_VALUE
|
13
|
+
end
|
14
|
+
|
15
|
+
# finalize! override, unseting config options
|
16
|
+
def finalize!
|
17
|
+
@users = nil if @users == UNSET_VALUE
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Useradd
|
3
|
+
# Plugin definition
|
4
|
+
#
|
5
|
+
class Plugin < Vagrant.plugin("2")
|
6
|
+
name 'vagrant useradd'
|
7
|
+
|
8
|
+
config 'useradd' do
|
9
|
+
Config
|
10
|
+
end
|
11
|
+
|
12
|
+
action_hook :useradd_hook do |hook|
|
13
|
+
hook.after(Vagrant::Action::Builtin::WaitForCommunicator, Action)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'vagrant-useradd/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "vagrant-useradd"
|
8
|
+
spec.version = VagrantPlugins::Useradd::VERSION
|
9
|
+
spec.authors = ["Jeff George"]
|
10
|
+
spec.email = ["jeff.george@gmail.com"]
|
11
|
+
spec.summary = %q{Inject users & groups into a Vagrant box prior to mounting synced_folders.}
|
12
|
+
spec.description = %q{Inject users & groups into a Vagrant box prior to mounting synced_folders.}
|
13
|
+
spec.homepage = "https://github.com/jeffgeorge/vagrant-useradd"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vagrant-useradd
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jeff George
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: Inject users & groups into a Vagrant box prior to mounting synced_folders.
|
42
|
+
email:
|
43
|
+
- jeff.george@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- lib/vagrant-useradd.rb
|
54
|
+
- lib/vagrant-useradd/action.rb
|
55
|
+
- lib/vagrant-useradd/config.rb
|
56
|
+
- lib/vagrant-useradd/plugin.rb
|
57
|
+
- lib/vagrant-useradd/version.rb
|
58
|
+
- vagrant-useradd.gemspec
|
59
|
+
homepage: https://github.com/jeffgeorge/vagrant-useradd
|
60
|
+
licenses:
|
61
|
+
- MIT
|
62
|
+
metadata: {}
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 2.0.14
|
80
|
+
signing_key:
|
81
|
+
specification_version: 4
|
82
|
+
summary: Inject users & groups into a Vagrant box prior to mounting synced_folders.
|
83
|
+
test_files: []
|