Esempio n. 1
0
func main() {
	var ini_cfg *ini.File
	var err error

	if _, err = isExists(ANSIBLE_CMD); err != nil {
		ANSIBLE_CMD = "ansible-playbook"
	}

	if *version {
		fmt.Printf("%s: %s\n", os.Args[0], VERSION)
		os.Exit(retOk)
	}

	if *operation_file == "" || *inventory_file == "" {
		fmt.Printf("[ERROR] Not supported action: %s\n", action)
		//gLogger.Error("operation and inventory file must provide.\n")
		flag.Usage()
		os.Exit(retFailed)
	} else {
		ret := checkExistFiles(*operation_file, *inventory_file)
		if !ret {
			fmt.Printf("[ERROR] check exists of operation and inventory file.\n")
			//gLogger.Error("check exists of operation and inventory file.\n")
			os.Exit(retInvaidArgs)
		}
	}

	if action == "" {
		fmt.Printf("[ERROR] action(check,update,deploy,rollback) must provide one.\n\n")
		//gLogger.Error("action(check,update,deploy,rollback) must provide one.\n")
		flag.Usage()
		os.Exit(retInvaidArgs)
	}

	if *retry_file != "" {
		if *retry_file, err = filepath.Abs(*retry_file); err != nil {
			panic(fmt.Errorf("get Abs path of %s failed: %s\n", *retry_file, err))
			//gLogger.Error("get Abs path of %s failed: %s\n", *retry_file, err)
			os.Exit(retInvaidArgs)
		}
	}

	if *inventory_file, err = filepath.Abs(*inventory_file); err != nil {
		panic(fmt.Errorf("get Abs path of %s failed: %s\n", *inventory_file, err))
	} else {
		ini_cfg, err = ini.Load(*inventory_file)
		if err != nil {
			panic(fmt.Errorf("ini load conf failed: %s\n", err))
		}
	}

	if *operation_file, err = filepath.Abs(*operation_file); err != nil {
		panic(fmt.Errorf("get Abs path of %s failed: %s\n", *operation_file, err))
	}

	fmt.Printf("[%s] action on [%s]\n", action, *operation_file)
	//gLogger.Info("[%s] action on [%s]\n", action, *operation_file)
	switch action {
	case "check":
		fmt.Printf("-------------Now doing in action: %s\n", action)
		//gLogger.Info("-------------Now doing in action: %s\n", action)
		fmt.Printf("inventory: %s\n", *inventory_file)
		ini_cfg.WriteTo(os.Stdout)
		fmt.Println("")
		opYamlSyntaxCheck(action, *inventory_file, *operation_file, *extra_vars, "all")
		displayYamlFile(*operation_file)
	case "update":
		fmt.Printf("-------------Now doing in action: %s\n", action)
		//gLogger.Info("-------------Now doing in action: %s\n", action)
		doUpdateAction(action, *inventory_file, *operation_file, *program_version, *concurrent)
	case "deploy":
		fmt.Printf("-------------Inventory file is: %s\n", *inventory_file)
		//gLogger.Info("-------------Inventory file is: %s\n", *inventory_file)
		fmt.Printf("inventory: %s\n", *inventory_file)
		ini_cfg.WriteTo(os.Stdout)
		fmt.Printf("-------------Now doing in action:[%s], single mode:[%t]\n", action, *single_mode)
		doDeployAction(action, *inventory_file, *operation_file, *single_mode, *concurrent, *retry_file, *extra_vars, *section)
	case "rollback":
		fmt.Printf("-------------Now doing in action: %s\n", action)
		//gLogger.Info("-------------Now doing in action: %s\n", action)
		fmt.Println("rollback action do nothing now.")
	default:
		fmt.Printf("Not supported action: %s\n", action)
		//gLogger.Info("Not supported action: %s\n", action)
		os.Exit(retFailed)
	}
}