package kubespray import ( "context" "kube-forge/internal/config" "kube-forge/internal/logging" "kube-forge/internal/python" "os" "path/filepath" "github.com/apenella/go-ansible/v2/pkg/execute" "github.com/apenella/go-ansible/v2/pkg/execute/stdoutcallback" "github.com/apenella/go-ansible/v2/pkg/playbook" ) func runPlaybook(playbookPath string, tags string) { config := config.GetConfig() var callbackExecute execute.Executor epExec := python.NewPythonExec() envVars := map[string]string{ "ANSIBLE_DISPLAY_SKIPPED_HOSTS": "false", "ANSIBLE_DISPLAY_OK_HOSTS": "false", "ANSIBLE_FORCE_COLOR": "true", "ANSIBLE_HOST_KEY_CHECKING": "false", "ANSIBLE_FORKS": config.Forks, } playbookOptions := getPlaybookParameters(tags) playbookCmd := playbook.NewAnsiblePlaybookCmd( playbook.WithPlaybooks( filepath.Join(epExec.ResourcesFsPath, playbookPath), ), playbook.WithPlaybookOptions(&playbookOptions), playbook.WithBinary( filepath.Join(epExec.PythonLibFsPath, "bin", "ansible-playbook"), ), ) execute := execute.NewDefaultExecute( execute.WithCmd(playbookCmd), execute.WithErrorEnrich(playbook.NewAnsiblePlaybookErrorEnrich()), execute.WithExecutable(epExec), ) if config.Verbose { envVars["ANSIBLE_STDOUT_CALLBACK"] = "unixy" envVars["ANSIBLE_VERBOSITY"] = "3" envVars["ANSIBLE_DISPLAY_SKIPPED_HOSTS"] = "true" envVars["ANSIBLE_DISPLAY_OK_HOSTS"] = "true" } else { envVars["ANSIBLE_STDOUT_CALLBACK"] = "dense" envVars["ANSIBLE_ACTION_WARNINGS"] = "false" envVars["ANSIBLE_DEVEL_WARNING"] = "false" envVars["ANSIBLE_DEPRECATION_WARNINGS"] = "false" envVars["ANSIBLE_DUPLICATE_YAML_DICT_KEY"] = "ignore" envVars["ANSIBLE_HOST_PATTERN_MISMATCH"] = "ignore" envVars["ANSIBLE_SYSTEM_WARNINGS"] = "false" } callbackExecute = stdoutcallback.NewDefaultStdoutCallbackExecute(execute) for key, value := range envVars { os.Setenv(key, value) } err := callbackExecute.Execute(context.Background()) if err != nil { logging.Log.Fatal(err) } }