As mentioned here, If you are using a cloud provider, you should not be managing your inventory in a static file. Instead use dynamic inventory
Ansible documentation only gives python boto sdk as dyamic inventories, as shown here.
ansible -i ec2.py -u ubuntu us-east-1d -m ping
Does ansible allow(-i
) executing dynamic inventories written using AWS Go sdk? instead of python boto sdk.
Yes, ansible will use any command that can produce the necessary JSON output, including just a shell script, as specified by the fine manual:
In previous versions you had to create a script or program that can output JSON in the correct format when invoked with the proper arguments. You can still use and write inventory scripts, as we ensured backwards compatibility via the script inventory plugin and there is no restriction on the programming language used.
as a concrete golang example:
package main
import (
"encoding/json"
"fmt"
)
func main() {
i := map[string]interface{}{
"_meta": map[string]interface{}{
"hostvars": map[string]interface{}{
"example.host": map[string]interface{}{
"ansible_host": "127.0.0.1",
"ansible_user": "ubuntu",
},
},
},
"all": map[string]interface{}{
"children": []string{"ungrouped"},
},
"ungrouped": map[string]interface{}{
"hosts": []string{"example.host"},
},
}
ba, err := json.Marshal(i)
if err != nil { panic(err) }
fmt.Println(string(ba))
}
Invoked via the usual mechanism:
go build -o sample-inv ./main.go
ansible -i ./sample-inv -m ping all