amazon-web-services - 使用 AWS Go 开发工具包的动态 list

标签 amazon-web-services go ansible aws-sdk aws-sdk-go

如前所述here , 如果您使用的是云提供商,则不应在静态文件中管理您的库存。而是使用动态库存

Ansible 文档仅提供 python boto sdk 作为动态库存,如图 here .

     ansible -i ec2.py -u ubuntu us-east-1d -m ping

ansible 是否允许(-i)执行使用 AWS Go sdk 编写的动态 list ?而不是 python boto sdk。

最佳答案

是的,ansible 将使用任何可以产生必要的 JSON 输出的命令,包括一个 shell 脚本,由 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.



作为一个具体的 golang 示例:

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))
}

通过通常的机制调用:

go build -o sample-inv ./main.go
ansible -i ./sample-inv -m ping all

关于amazon-web-services - 使用 AWS Go 开发工具包的动态 list ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60554757/

相关文章:

go - 为什么我在此代码中的函数末尾缺少返回值?

go - 在 GCP Container-Optimized OS 上构建 go 可执行文件的 GOOS 和 GOARCH 值是多少

ansible - 如何在 list 文件中使用 ansible-vault 加密密码?

list - Ansible 将列表项连接到字符串中,包括引号

linux - Ansible 文件模块错误 - chown 失败 : failed to look up user

ios - 使用 S3TransferManager AWS iOS SDK 上传大文件

amazon-web-services - 提供的请求无效:AWS::ElasticLoadBalancingV2::ListenerRule 验证异常

java - AWS EC2 将无法使用静态访问凭证连接到 DynamoDB

amazon-web-services - Hadoop对云延迟的影响

go - 在 Go 中访问 map 接口(interface)值