【问题标题】:Is there a way to put complex (nested) variables in ansible inventory有没有办法将复杂(嵌套)变量放入 ansible 库存中
【发布时间】:2019-09-07 14:44:41
【问题描述】:

我有一个代理的环境变量

proxy_env:
    http_proxy: myproxy
    https_proxy: myproxy
    ftp_proxy: myproxy
    no_proxy: localhost,127.0.0.1
    proxy_host: myproxy
    proxy_port: 80

现在我想在不需要代理的机器上部署相同的东西(因此我想在清单中移动这个变量)。

但是,如果我只移动库存中的方块

[machinegroup:vars]
proxy_env:
    http_proxy: myproxy
    https_proxy: myproxy
    ftp_proxy: myproxy
    no_proxy: localhost,127.0.0.1
    proxy_host: myproxy
    proxy_port: 80

我收到一个错误:“无法解析库存...”

如果我把它放在一行中,它也不会被考虑在内......

proxy_env http_proxy=myproxy ..

谢谢!

【问题讨论】:

    标签: ansible inventory ansible-inventory


    【解决方案1】:

    问:有没有办法将嵌套变量放入 ansible 库存中?

    答:是的。这是。使用YAML 格式。

    all:
        hosts:
            test1:
            test2:
                proxy_env:
                    http_proxy: myproxy
                    https_proxy: myproxy
                    ftp_proxy: myproxy
                    no_proxy: localhost,127.0.0.1
                    proxy_host: myproxy
                    proxy_port: 80
    


    INI 格式也是可能的,但在这种情况下不太实用。
    test2 proxy_env={{http_proxy: myproxy},{https_proxy: myproxy}, ... }
    

    【讨论】:

    猜你喜欢
    • 2017-10-10
    • 1970-01-01
    • 2021-02-28
    • 1970-01-01
    • 2022-01-26
    • 2020-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多