2016-05-14 10:31:43 +00:00
|
|
|
package models
|
|
|
|
|
|
|
|
type Ansible struct {
|
2016-05-14 11:21:10 +00:00
|
|
|
Nodes []string `json:"nodes"`
|
|
|
|
Meta struct {
|
|
|
|
HostVars []*AnsibleHostVars `json:"hostvars"`
|
|
|
|
} `json:"_meta"`
|
2016-05-14 10:31:43 +00:00
|
|
|
}
|
|
|
|
type AnsibleHostVars struct {
|
2016-05-14 11:21:10 +00:00
|
|
|
Address string `json:"ansible_ssh_host"`
|
|
|
|
Hostname string `json:"node_name"`
|
2016-05-14 10:31:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func GenerateAnsible(nodes *Nodes,aliases map[string]*Alias) *Ansible{
|
2016-05-14 11:21:10 +00:00
|
|
|
ansible := &Ansible{Nodes:make([]string,0)}
|
|
|
|
for nodeid,alias := range aliases{
|
|
|
|
if node := nodes.List[nodeid]; node != nil {
|
2016-05-14 10:31:43 +00:00
|
|
|
|
2016-05-14 11:21:10 +00:00
|
|
|
ansible.Nodes = append(ansible.Nodes,nodeid)
|
2016-05-14 10:31:43 +00:00
|
|
|
|
2016-05-14 11:21:10 +00:00
|
|
|
vars := &AnsibleHostVars{
|
|
|
|
Address: node.Nodeinfo.Network.Addresses[0],
|
|
|
|
Hostname: alias.Hostname,
|
|
|
|
}
|
|
|
|
ansible.Meta.HostVars = append(ansible.Meta.HostVars,vars)
|
2016-05-14 10:31:43 +00:00
|
|
|
|
2016-05-14 11:21:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ansible
|
2016-05-14 10:31:43 +00:00
|
|
|
}
|