使用 ansible playbook 运行 postgresql 命令.Postgresql 需要密码 [英] Run a postgresql command with ansible playbook. Postgresql requires password

查看:57
本文介绍了使用 ansible playbook 运行 postgresql 命令.Postgresql 需要密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一个 Ansible 剧本来尝试处理一些 postgresql 命令.我之前做了一个类似的剧本,但在那种情况下 Postgresql 不需要密码.

I would like to write an Ansible playbook which tries to handle some postgresql command. I did earlier a similar playbook, but in that case Postgresql didn't need password.

我以为我可以使用我的旧剧本,效果很好,但我错了.该数据库需要密码.我知道 Ansible 有 postgresql 支持,这很好(postgresql_db、postgresql_ext、postgresql_lang、postgresql_privs、postgresql_user),有了它们我可以完成一半的工作并且它处理密码很好,但我不知道如何发送一个简单的sql 命令到我的数据库.在我的旧剧本中,我使用shell"命令发送这些请求(例如:shell: "psql {{ databases.name }} --username {{ admin_user}} -c 'DROP SCHEMA public CASCADE;'").

I thought I could use my old playbook, which works fine, but I was wrong. This database requires password. I know that Ansible has postgresql support which is fine (postgresql_db, postgresql_ext, postgresql_lang, postgresql_privs, postgresql_user) and with them I can do half of the work and it handles password just fine, BUT I can't figure out how to send a simple sql commands to my database. In my old playbook I used "shell" command to send those requests (eg: shell: "psql {{ databases.name }} --username {{ admin_user}} -c 'DROP SCHEMA public CASCADE;'").

我还想上传一个 db_dump.早些时候我为此使用了 psql,但是这个新数据库需要密码...

And also I would like to upload a db_dump. Earlier I used psql for this, but this new database requires password...

有人可以给我提示如何处理这种情况吗?我使用的是 ansible 2.0,并且只能从特定的远程主机访问数据库.

Can someone give me tips how to handle this situation? I'm using ansible 2.0 and the database can be reached only from a specific remote host.

谢谢

推荐答案

您可以使用提供四个新模块的新角色:

You can use a new role that provides four new modules:

  • postgresql_table:确保数据库中存在(或不存在)表
  • postgresql_row:确保表中存在(或不存在)一行
  • postgresql_query:在数据库中执行任意查询并返回结果
  • postgresql_command:在数据库中执行任意查询

在此处查找文档:https://github.com/rtshome/ansible_pgsql

这篇关于使用 ansible playbook 运行 postgresql 命令.Postgresql 需要密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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