Class: ConfigAgent::Chpasswd
- Inherits:
-
ScriptAgent
- Object
- ScriptAgent
- ConfigAgent::Chpasswd
- Defined in:
- config_agent-passwd/lib/config_agent/chpasswd.rb
Constant Summary
Constant Summary
Constants included from Logger
Logger::AGENTS_LOGDIR, Logger::AGENTS_LOGFILE
Instance Method Summary (collapse)
Methods inherited from ScriptAgent
Methods included from Logger
Instance Method Details
- (Object) execute(params)
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'config_agent-passwd/lib/config_agent/chpasswd.rb', line 25 def execute(params) ret = {} # allow one hash with user+pass or array of values: # if "config_file" is present, it has to be list of hashes of type # [ { "user" => "user1", "pw" => "p1" }, { "user" => "user2", "pw" => "p2" }] config = params["config_file"] || [params] correct_data = config.all? {|i| !(i["user"]).empty? && !(i["pw"]).empty? } return ret unless correct_data #TODO exception f = Tempfile.new('pwchange','/root') begin config.each { |i| f.puts("#{i["user"]}:#{i["pw"]}") } f.close ret = run(["/usr/sbin/chpasswd"]+(params["exec_args"]||[])+[f.path]) ensure f.unlink end return ret end |