Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add group resource #70

Merged
merged 1 commit into from
Jan 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion itamae.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
spec.require_paths = ["lib"]

spec.add_runtime_dependency "thor"
spec.add_runtime_dependency "specinfra", "~> 2.1"
spec.add_runtime_dependency "specinfra", "~> 2.12"
spec.add_runtime_dependency "hashie"
spec.add_runtime_dependency "ansi"

Expand Down
1 change: 1 addition & 0 deletions lib/itamae/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
require 'itamae/resource/local_ruby_block'
require 'itamae/resource/git'
require 'itamae/resource/user'
require 'itamae/resource/group'

module Itamae
module Resource
Expand Down
42 changes: 42 additions & 0 deletions lib/itamae/resource/group.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
require 'itamae'

module Itamae
module Resource
class Group < Base
define_attribute :action, default: :create
define_attribute :groupname, type: String, default_name: true
define_attribute :gid, type: Integer

def set_current_attributes
current.exist = exist?

if current.exist
current.gid = run_specinfra(:get_group_gid, attributes.groupname).stdout.strip.to_i
end
end

def action_create(options)
if run_specinfra(:check_group_exists, attributes.groupname)
if attributes.gid && attributes.gid != current.gid
run_specinfra(:update_group_gid, attributes.groupname, attributes.gid)
updated!
end
else
options = {
gid: attributes.gid,
}

run_specinfra(:add_group, attributes.groupname, options)

updated!
end
end

private
def exist?
run_specinfra(:check_group_exists, attributes.groupname)
end
end
end
end