fixes to allow the provisioner container to run ansible on remote nodes
diff --git a/automation/state.go b/automation/state.go
index f4c1bf9..4e0dd1f 100644
--- a/automation/state.go
+++ b/automation/state.go
@@ -240,11 +240,12 @@
err)
} else {
defer resp.Body.Close()
- if resp.StatusCode == 202 {
+ if resp.StatusCode == http.StatusAccepted {
record.State = Provisioning
} else {
record.State = ProvisionError
}
+ record.Timestamp = time.Now().Unix()
options.ProvTracker.Set(node.ID(), record)
}
}
@@ -287,16 +288,18 @@
node.Hostname(), err)
} else {
switch resp.StatusCode {
- case 200: // OK - provisioning completed
+ case http.StatusOK: // provisioning completed
if options.Verbose {
log.Printf("[info] Marking node '%s' with ID '%s' as provisioned",
node.Hostname(), node.ID())
}
record.State = Provisioned
options.ProvTracker.Set(node.ID(), record)
- case 202: // Accepted - in the provisioning state
+ case http.StatusAccepted: // in the provisioning state
// Noop, presumably alread in this state
default: // Consider anything else an erorr
+ log.Printf("[warn] Node '%s' with ID '%s' failed provisioning, will retry",
+ node.Hostname(), node.ID())
record.State = ProvisionError
options.ProvTracker.Set(node.ID(), record)
}
diff --git a/provisioner/Dockerfile b/provisioner/Dockerfile
index a193758..cf4a86b 100644
--- a/provisioner/Dockerfile
+++ b/provisioner/Dockerfile
@@ -32,6 +32,9 @@
apt-get update -y -m && \
apt-get install -y git ansible
+RUN mkdir -p /root/.ssh
+COPY ssh-config /root/.ssh/config
+
RUN go get github.com/tools/godep
ADD . $GOPATH/src/github.com/ciena/cord-provisioner
diff --git a/provisioner/handlers.go b/provisioner/handlers.go
index 11df6ee..42946da 100644
--- a/provisioner/handlers.go
+++ b/provisioner/handlers.go
@@ -101,5 +101,15 @@
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
+
+ switch s.Status {
+ case Pending, Running:
+ w.WriteHeader(http.StatusAccepted)
+ case Complete:
+ w.WriteHeader(http.StatusOK)
+ default:
+ w.WriteHeader(http.StatusInternalServerError)
+ }
+
w.Write(bytes)
}
diff --git a/provisioner/ssh-config b/provisioner/ssh-config
new file mode 100644
index 0000000..990a43d
--- /dev/null
+++ b/provisioner/ssh-config
@@ -0,0 +1,3 @@
+Host *
+ StrictHostKeyChecking no
+ UserKnownHostsFile=/dev/null