I just recently implemented this solution and I this this just a INFO post to make the group aware this is possible.
A command to install a application component requires the user to hit the RETURN key, even though supposedly the command is a “silent” installer.
AFAIK, Chef can execute a process or spawn a process but i dont know how to use chef to “send a return key” into the spawned process.
My solution (may not be the best):
- On the VM (Linux in my case), install TCL and expect packages (yum install tcl ; yum install expect)
- Create a .tcl script where it “expects the phrase Press enter to continue” and then presses enter for you (\r
File name: install.tcl (you can create this using Chef template)
package require Expect set timeout -1 spawn ./install.sh silent expect "Press enter to continue" send "\r"
- You invoke the tcl script like so…(of course you can do this via chef execute resource)
- The TCL script now can wait until it sees the phrase
Press enter to continueand then send a
returnkey. All good. But, the TCL script itself returns a success exit code back to Chef even though the install.sh script itself may have errored out. Not good.
After usual googling, figured we need to add a
timeout -1 so that it waits indefinitely and also add a
expect eof so that it continues to wait until install.sh itself has completed fully. Next, add a catch block to catch the exit status of the spawned process (in this case install.sh) and send the exit code back to the calling application (for example, a chef execute resource)
File name: install.tcl
package require Expect set timeout -1 spawn ./install.sh silent expect "Press enter to continue" send "\r" expect eof catch wait result exit [lindex $result 3]
With this, now I can automate any command line program which requires user input on Chef, with help from TCL/Expect.
Of course, there may be a way within Chef/Ruby to send responses to command line prompts - please do let me know if there’s a simpler solution.