Hey-
Here is a task I use to add users and set their passwords:
task :new_user, :roles => :slice do
run "adduser rcreasy"
run "passwd rcreasy" do |ch, stream, out|
ch.send_data 'xxxxxxx'+"\n" if out =~ /New UNIX password:/
ch.send_data 'xxxxxxx'+"\n" if out =~ /Retype new UNIX password:/
end
end
Cheers-
-Ezra
On Mar 15, 2007, at 11:57 AM, rcreasey wrote:
>
> I've been trying to extend Capistrano into more than just a web
> application deployment framework and into the realm of system
> administration.
>
> I wanted to write a recipe file that would include common tasks, such
> as adding and deleting system users, but realized that it would only
> really work if I were able to actually get STDIN from the user after
> running cap with the recipe.
>
> I'm thinking of something like this:
>
> desc "Add a user to the specified host"
> task :adduser do
> puts "Username: "
> gets username
> puts "Password: "
> gets password
>
> run "/usr/sbin/adduser #{username}"
> run "/usr/bin/passwd --stdin #{password} | /bin/echo #{password}"
> end
>
> This is a simple kind of example, but you can see what I mean.
> Unfortunately, since (I think) the tasks are Erb templates doing
> methods such as 'gets' doesn't work for variable assignment, and when
> you try to execute a task similar to the one above, it will just skip
> over the 'gets' and complain about the variable not being defined when
> trying to reference it in the following 'puts'.
>
> Any thoughts?
>
> --
> Ryan C. Creasey
> [EMAIL PROTECTED]
>
>
> >
-- Ezra Zygmuntowicz
-- Lead Rails Evangelist
-- [EMAIL PROTECTED]
-- Engine Yard, Serious Rails Hosting
-- (866) 518-YARD (9273)
--~--~---------~--~----~------------~-------~--~----~
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/capistrano
-~----------~----~----~----~------~----~------~--~---