如何从Ansible获取postgresql_query结果 [英] How to get postgresql_query results from Ansible

查看:92
本文介绍了如何从Ansible获取postgresql_query结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试打印由Ansible运行的PostgreSQL查询的输出.不幸的是,我不确定如何获取返回值.

I'm trying to print the output of PostgreSQL query that is run by Ansible. Unfortunately I'm not sure how to get ahold of the return value.

    - name: Get specific tables
      postgresql_query:
        db: "{{ database_name }}"
        login_host: "{{ my_host }}"
        login_user: "{{ my_user }}"
        login_password: "{{ my_password }}"
        query: SELECT * FROM pg_tables t WHERE t.tableowner = current_user

谷歌搜索只是说要使用 register:,但是PostgreSQL ansible模块没有 register 参数:

Googling just says to use register:, but the PostgreSQL ansible module does not have a register param:

fatal: [xx.xxx.xx.xx]: FAILED! => {"changed": false, "msg": "Unsupported parameters for (postgresql_query) module: register Supported parameters include: ca_cert, db, login_host, login_password, login_unix_socket, login_user, named_args, path_to_script, port, positional_args, query, session_role, ssl_mode"}

Ansible docs 列出的返回值此模块,但没有有关如何使用它们的示例,我搜索的所有内容都可以直接回到 register: .

The Ansible docs list return values for this module but there are no examples on how to use them, and everything I search for leads right back to register:.

推荐答案

听起来像你的声音很近,但是 register 的缩进错误.这是任务本身的参数,而不是postgresql模块.

Sounds like you are very close, but have register at the wrong indentation. It's a parameter of the task itself, not the postgresql module.

尝试:

    - name: Get specific tables
      postgresql_query:
        db: "{{ database_name }}"
        login_host: "{{ my_host }}"
        login_user: "{{ my_user }}"
        login_password: "{{ my_password }}"
        query: SELECT * FROM pg_tables t WHERE t.tableowner = current_user
      register: result

    - debug:
        var: result

这篇关于如何从Ansible获取postgresql_query结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆