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

查看:152
本文介绍了使用ansible剧本运行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剧本运行postgresql命令. PostgreSQL需要密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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