@@ -84,6 +84,7 @@ def bootstrap_node(node):
8484 # write out private key and prepare to `knife bootstrap`
8585 try :
8686 _ , pk_path = tempfile .mkstemp ()
87+ _ , output_path = tempfile .mkstemp ()
8788 with open (pk_path , 'w' ) as f :
8889 f .write (node ['ssh_private_key' ])
8990 # build knife bootstrap command
@@ -96,18 +97,25 @@ def bootstrap_node(node):
9697 args .extend (['--no-host-key-verify' ])
9798 args .extend (['--run-list' , _construct_run_list (node )])
9899 print (' ' .join (args ))
100+ # tee the command's output to a tempfile
101+ args .extend (['|' , 'tee' , output_path ])
99102 # TODO: figure out why home isn't being set correctly for knife exec
100103 env = os .environ .copy ()
101104 env ['HOME' ] = '/opt/deis'
102105 # execute knife bootstrap
103- p = subprocess .Popen (args , env = env , stderr = subprocess . PIPE )
106+ p = subprocess .Popen (' ' . join ( args ) , env = env , shell = True )
104107 rc = p .wait ()
108+ # always print knife output
109+ with open (output_path ) as f :
110+ output = f .read ()
111+ print (output )
112+ # raise an exception if bootstrap failed
105113 if rc != 0 :
106- print (p .stderr .read ())
107114 raise RuntimeError ('Node Bootstrap Error' )
108- # remove private key from fileystem
115+ # remove temp files from filesystem
109116 finally :
110- pass # os.remove(pk_path)
117+ os .remove (pk_path )
118+ os .remove (output_path )
111119
112120
113121def _construct_run_list (node ):
0 commit comments