Files
cloudpods/pkg/util/ansiblev2/offline_session.go
T
rainzm f8f99365a2 feat(ansibleserver): add reference and instance
Reference is a reference to a local or remote playbook without certain inventory
and its location is determined by playbookPath.
Instance is a complete playbook that can be executed directly, it is filled with inventory and config.
Instance ensures that the playbook is executed successfully as far as
possible without exceeding the maximum number of attempts
2021-04-07 17:01:08 +08:00

82 lines
1.9 KiB
Go

// Copyright 2019 Yunion
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package ansiblev2
import (
"context"
"io"
)
type OfflineSession struct {
PlaybookSessionBase
playbookPath string
proxy string
user string
hostIp string
hostName string
configs map[string]interface{}
}
func NewOfflineSession() *OfflineSession {
sess := &OfflineSession{
PlaybookSessionBase: NewPlaybookSessionBase(),
configs: map[string]interface{}{},
}
return sess
}
func (sess *OfflineSession) PrivateKey(s string) *OfflineSession {
sess.privateKey = s
return sess
}
func (sess *OfflineSession) PlaybookPath(s string) *OfflineSession {
sess.playbookPath = s
return sess
}
func (sess *OfflineSession) Inventory(s string) *OfflineSession {
sess.inventory = s
return sess
}
func (sess *OfflineSession) OutputWriter(w io.Writer) *OfflineSession {
sess.outputWriter = w
return sess
}
func (sess *OfflineSession) KeepTmpdir(keep bool) *OfflineSession {
sess.keepTmpdir = keep
return sess
}
func (sess *OfflineSession) Configs(configs map[string]interface{}) *OfflineSession {
sess.configs = configs
return sess
}
func (sess *OfflineSession) GetPlaybookPath() string {
return sess.playbookPath
}
func (sess *OfflineSession) GetConfigs() map[string]interface{} {
return sess.configs
}
func (sess *OfflineSession) Run(ctx context.Context) (err error) {
return runnable{sess}.Run(ctx)
}