From 129af0fa17dcb608ce63cf9b5390d9482d7b3b1c Mon Sep 17 00:00:00 2001 From: Tokuhiro Matsuno Date: Thu, 30 Jun 2016 10:57:45 -0400 Subject: [PATCH] Added dry_run button. close #152 --- api/tasks/runner.go | 4 ++++ db/migrations/v1.8.0.sql | 1 + db/versionHistory.go | 1 + models/Task.go | 2 ++ public/html/projects/createTaskModal.jade | 1 + public/js/controllers/projects/taskRunner.js | 8 ++++++-- 6 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 db/migrations/v1.8.0.sql diff --git a/api/tasks/runner.go b/api/tasks/runner.go index 50632dc3..265137d3 100644 --- a/api/tasks/runner.go +++ b/api/tasks/runner.go @@ -258,6 +258,10 @@ func (t *task) runPlaybook() error { args = append(args, "-vvvv") } + if t.task.DryRun { + args = append(args, "--check") + } + if len(t.environment.JSON) > 0 { args = append(args, "--extra-vars", t.environment.JSON) } diff --git a/db/migrations/v1.8.0.sql b/db/migrations/v1.8.0.sql new file mode 100644 index 00000000..15cd484a --- /dev/null +++ b/db/migrations/v1.8.0.sql @@ -0,0 +1 @@ +ALTER TABLE task ADD dry_run tinyint(1) NOT NULL DEFAULT 0 AFTER debug; diff --git a/db/versionHistory.go b/db/versionHistory.go index 0784ddd0..17ca8922 100644 --- a/db/versionHistory.go +++ b/db/versionHistory.go @@ -64,5 +64,6 @@ func init() { {Minor: 1}, {Major: 1, Minor: 6}, {Major: 1, Minor: 7}, + {Major: 1, Minor: 8}, } } diff --git a/models/Task.go b/models/Task.go index 06d9e2f3..00037119 100644 --- a/models/Task.go +++ b/models/Task.go @@ -9,6 +9,8 @@ type Task struct { Status string `db:"status" json:"status"` Debug bool `db:"debug" json:"debug"` + DryRun bool `db:"dry_run" json:"dry_run"` + // override variables Playbook string `db:"playbook" json:"playbook"` Environment string `db:"environment" json:"environment"` diff --git a/public/html/projects/createTaskModal.jade b/public/html/projects/createTaskModal.jade index ca23b2a2..16b219c9 100644 --- a/public/html/projects/createTaskModal.jade +++ b/public/html/projects/createTaskModal.jade @@ -20,4 +20,5 @@ .modal-footer button.btn.btn-default.pull-left(ng-click="$dismiss()") Dismiss + button.btn.btn-primary(ng-click="run(task, true)") Dry Run button.btn.btn-success(ng-click="run(task)") Run! \ No newline at end of file diff --git a/public/js/controllers/projects/taskRunner.js b/public/js/controllers/projects/taskRunner.js index 75cd5f67..1356157b 100644 --- a/public/js/controllers/projects/taskRunner.js +++ b/public/js/controllers/projects/taskRunner.js @@ -3,10 +3,14 @@ define(function () { console.log(Template); $scope.task = {}; - $scope.run = function (task) { + $scope.run = function (task, dryRun) { task.template_id = Template.id; - $http.post(Project.getURL() + '/tasks', task).success(function (t) { + var params = angular.copy(task); + if (dryRun) { + params.dry_run = true; + } + $http.post(Project.getURL() + '/tasks', params).success(function (t) { $scope.$close(t); }).error(function (_, status) { swal('Error', 'error launching task: HTTP ' + status, 'error');