Skip to content

Instantly share code, notes, and snippets.

@swalberg
Created November 4, 2016 19:27
Show Gist options
  • Save swalberg/47f257b1c6dee0ba26f7b394bba30483 to your computer and use it in GitHub Desktop.
Save swalberg/47f257b1c6dee0ba26f7b394bba30483 to your computer and use it in GitHub Desktop.
Recipe: aspera::users
* chef_gem[vault] action install (up to date)
* aspera_user[sea] action create
- create sea
- set unix_user to "sea"
- create sea
- set password to "initial"failure
Missing User/Group data: User sea does not appear to exist on the computer (User not found)
- create sea
- set path to "/tmp/foo"
* linux_user[sea] action create
- create user sea
load_current_value do |desired|
users = Mixlib::ShellOut.new('/opt/aspera/bin/asnodeadmin -l -P').run_command.stdout.split(/\n/)
this_user = users.grep(/^\s*#{desired.name}\s/).first
current_value_does_not_exist! if this_user.nil?
params = this_user.lstrip.split /\s+/
unix_user params[2]
name params[0]
password hash_password(desired.password, params[1])
user_config = Mixlib::ShellOut.new("/opt/aspera/bin/asuserdata -x -u #{desired.unix_user}").run_command.stdout
doc = REXML::Document.new user_config
potential_path = REXML::XPath.first(doc, '//canonical_absolute')
path potential_path.nil? ? nil : potential_path.text
end
action :create do
# Also tried the user resource here
converge_if_changed :unix_user do
user unix_user do
shell '/bin/aspshell'
home path
end
puts Mixlib::ShellOut.new("/opt/aspera/bin/asnodeadmin -a -x #{unix_user} -u #{name} -p #{password}").run_command.stdout
end
converge_if_changed :password do
puts Mixlib::ShellOut.new("/opt/aspera/bin/asnodeadmin -m -u #{name} -p #{password}").run_command.stdout
end
converge_if_changed :path do
puts Mixlib::ShellOut.new("/opt/aspera/bin/asconfigurator -x \"set_user_data;user_name,#{unix_user};absolute,#{path}\"").run_command.stdout
end
end
def hash_password(password, from_pwent)
...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment