【问题标题】:How to extract values from MySQL query in Ansible play如何在 Ansible 中从 MySQL 查询中提取值
【发布时间】:2020-03-10 19:24:33
【问题描述】:

在 Ansible 游戏中,我在 MySQL 数据库上运行了一个成功的 SQL 查询,它返回:

"result": [
        {
            "account_profile": "sbx"
        },
        {
            "account_profile": "dev"
        }
    ]

该结果被保存到一个名为 query_output 的变量中。我知道我可以通过

在 Ansible 中显示结果数组
- debug:
    var: query_output.result

但对于我来说,我无法弄清楚如何提取 2 个 account_profile 值。

我的最终目标是将它们提取到一个数组中。比如:

"aws_account_profiles": [ "sbx", "dev" ]

我知道我遗漏了一些非常明显的东西。

建议?

【问题讨论】:

    标签: mysql arrays json ansible


    【解决方案1】:

    你想要的是map filter's attribute= usage

    {{ query_output.result | map(attribute="account_profile") | list }}

    【讨论】:

    • 我很高兴这很简单。请将答案标记为已接受,以便其他人知道它对您有帮助
    猜你喜欢
    • 2021-03-08
    • 1970-01-01
    • 2010-11-01
    • 2020-09-14
    • 2015-03-29
    • 1970-01-01
    • 2012-06-16
    • 2020-10-06
    • 1970-01-01
    相关资源
    最近更新 更多