complete ansible alias
This commit is contained in:
parent
e4a46e593b
commit
83dd82e6d2
|
@ -38,12 +38,14 @@ func (api *ApiAliases) cleaner() {
|
||||||
if alias.Hostname == nodeinfo.Hostname {
|
if alias.Hostname == nodeinfo.Hostname {
|
||||||
count -= 1
|
count -= 1
|
||||||
}
|
}
|
||||||
|
if alias.Location != nil && nodeinfo.Location != nil {
|
||||||
if alias.Location.Latitude == nodeinfo.Location.Latitude {
|
if alias.Location.Latitude == nodeinfo.Location.Latitude {
|
||||||
count -= 1
|
count -= 1
|
||||||
}
|
}
|
||||||
if alias.Location.Longtitude == nodeinfo.Location.Longtitude {
|
if alias.Location.Longtitude == nodeinfo.Location.Longtitude {
|
||||||
count -= 1
|
count -= 1
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
if alias.Freq24.TxPower == nodeinfo.Freq24.TxPower {
|
if alias.Freq24.TxPower == nodeinfo.Freq24.TxPower {
|
||||||
count -= 1
|
count -= 1
|
||||||
|
|
|
@ -11,14 +11,14 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Alias struct {
|
type Alias struct {
|
||||||
Hostname string `json:"hostname"`
|
Hostname string `json:"hostname,omitempty"`
|
||||||
Location *data.Location `json:"location"`
|
Location *data.Location `json:"location,omitempty"`
|
||||||
Freq24 *Frequence `json:"freq24"`
|
Freq24 *Frequence `json:"freq24,omitempty"`
|
||||||
Freq5 *Frequence `json:"freq5"`
|
Freq5 *Frequence `json:"freq5,omitempty"`
|
||||||
}
|
}
|
||||||
type Frequence struct {
|
type Frequence struct {
|
||||||
TxPower int `json:"txpower"`
|
TxPower int `json:"txpower,omitempty"`
|
||||||
Channel int `json:"channel"`
|
Channel int `json:"channel,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Nodes struct: cache DB of Node's structs
|
// Nodes struct: cache DB of Node's structs
|
||||||
|
|
|
@ -8,13 +8,13 @@ type Ansible struct {
|
||||||
}
|
}
|
||||||
type AnsibleHostVars struct {
|
type AnsibleHostVars struct {
|
||||||
Address string `json:"ansible_ssh_host"`
|
Address string `json:"ansible_ssh_host"`
|
||||||
Hostname string `json:"node_name"`
|
Hostname string `json:"node_name,omitempty"`
|
||||||
Channel24 int `json:"radio24_channel"`
|
Channel24 int `json:"radio24_channel,omitempty"`
|
||||||
TxPower24 int `json:"radio24_txpower"`
|
TxPower24 int `json:"radio24_txpower,omitempty"`
|
||||||
Channel5 int `json:"radio5_channel"`
|
Channel5 int `json:"radio5_channel,omitempty"`
|
||||||
TxPower5 int `json:"radio5_txpower"`
|
TxPower5 int `json:"radio5_txpower,omitempty"`
|
||||||
GeoLatitude float64 `json:"geo_latitude"`
|
GeoLatitude float64 `json:"geo_latitude,omitempty"`
|
||||||
GeoLongitude float64 `json:"geo_longitude"`
|
GeoLongitude float64 `json:"geo_longitude,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func GenerateAnsible(nodes *Nodes, aliases map[string]*Alias) *Ansible {
|
func GenerateAnsible(nodes *Nodes, aliases map[string]*Alias) *Ansible {
|
||||||
|
@ -27,12 +27,18 @@ func GenerateAnsible(nodes *Nodes, aliases map[string]*Alias) *Ansible {
|
||||||
vars := &AnsibleHostVars{
|
vars := &AnsibleHostVars{
|
||||||
Address: node.Nodeinfo.Network.Addresses[0],
|
Address: node.Nodeinfo.Network.Addresses[0],
|
||||||
Hostname: alias.Hostname,
|
Hostname: alias.Hostname,
|
||||||
Channel24: alias.Freq24.Channel,
|
}
|
||||||
Channel5: alias.Freq5.Channel,
|
if alias.Freq24 != nil {
|
||||||
TxPower24: alias.Freq24.TxPower,
|
vars.Channel24 = alias.Freq24.Channel
|
||||||
TxPower5: alias.Freq5.TxPower,
|
vars.TxPower24 = alias.Freq24.TxPower
|
||||||
GeoLatitude: alias.Location.Latitude,
|
}
|
||||||
GeoLongitude: alias.Location.Longtitude,
|
if alias.Freq5 != nil {
|
||||||
|
vars.Channel5 = alias.Freq5.Channel
|
||||||
|
vars.TxPower5 = alias.Freq5.TxPower
|
||||||
|
}
|
||||||
|
if alias.Location != nil {
|
||||||
|
vars.GeoLatitude = alias.Location.Latitude
|
||||||
|
vars.GeoLongitude = alias.Location.Longtitude
|
||||||
}
|
}
|
||||||
ansible.Meta.HostVars = append(ansible.Meta.HostVars, vars)
|
ansible.Meta.HostVars = append(ansible.Meta.HostVars, vars)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue