fix bugs, user ansibleHostGroup.Name split all and etcd and other;get configpath and hostspath from environment

This commit is contained in:
凡羊羊 2019-08-06 22:34:13 +08:00
parent 32b7f10128
commit eb2d2e6b46
2 changed files with 14 additions and 9 deletions

View File

@ -134,8 +134,16 @@ func (n *NodeService) writeHostsFile() error {
if err != nil {
return err.Err
}
// use default hosts file path and default install config file path
erro := ansibleUtil.WriteHostsFile("/opt/rainbond/rainbond-ansible/inventory/hosts", "/opt/rainbond/rainbond-ansible/scripts/installer/global.sh", hosts)
// use the value of environment if it is empty use default value
hostsFilePath := os.Getenv("HOSTS_FILE_PATH")
if hostsFilePath == "" {
hostsFilePath = "/opt/rainbond/rainbond-ansible/inventory/hosts"
}
installConfPath := os.Getenv("INSTALL_CONF_PATH")
if installConfPath == "" {
installConfPath = "/opt/rainbond/rainbond-ansible/scripts/installer/global.sh"
}
erro := ansibleUtil.WriteHostsFile(hostsFilePath, installConfPath, hosts)
if erro != nil {
return err
}

View File

@ -37,13 +37,7 @@ type AnsibleHost struct {
}
func (a *AnsibleHost) String() string {
if a.Role.HasRule("all") {
return fmt.Sprintf("%s ansible_host=%s ansible_port=%d ip=%s port=%d role=%s", a.HostID, a.AnsibleHostIP, a.AnsibleHostPort, a.AnsibleHostIP, a.AnsibleHostPort, a.Role)
} else if a.Role.HasRule("etcd") {
return fmt.Sprintf("%s ansible_host=%s NODE_NAME=etcd1", a.HostID, a.AnsibleHostIP)
} else {
return fmt.Sprintf("%s ansible_host=%s", a.HostID, a.AnsibleHostIP)
}
return fmt.Sprintf("%s ansible_host=%s ansible_port=%d ip=%s port=%d role=%s", a.HostID, a.AnsibleHostIP, a.AnsibleHostPort, a.AnsibleHostIP, a.AnsibleHostPort, a.Role)
}
type HostsList []*AnsibleHost
@ -82,6 +76,8 @@ func (a *AnsibleHostGroup) String() string {
for i := range a.HostList {
if a.Name == "all" {
rebuffer.WriteString(a.HostList[i].String() + "\n")
} else if a.Name == "etcd" {
rebuffer.WriteString(a.HostList[i].HostID + " NODE_NAME=etcd1" + "\n")
} else {
rebuffer.WriteString(a.HostList[i].HostID + "\n")
}
@ -108,6 +104,7 @@ func GetAnsibleHostConfig(name string) *AnsibleHostConfig {
"new-gateway": &AnsibleHostGroup{Name: "new-gateway"},
"compute": &AnsibleHostGroup{Name: "compute"},
"new-compute": &AnsibleHostGroup{Name: "new-compute"},
"etcd": &AnsibleHostGroup{Name: "etcd"},
},
}
}