我是使用Ansible的新手,并且希望了解如何编写一个Ansible Playbook,它将对postgres SQL数据库实例作为特定用户运行查询并显示终端中的输出。Ansible Playbook将在Postgres SQL数据库实例上运行查询
例如:
SELECT * FROM example_db;
可能有人提供了一个简单的例子?
我是使用Ansible的新手,并且希望了解如何编写一个Ansible Playbook,它将对postgres SQL数据库实例作为特定用户运行查询并显示终端中的输出。Ansible Playbook将在Postgres SQL数据库实例上运行查询
例如:
SELECT * FROM example_db;
可能有人提供了一个简单的例子?
这是一个未经测试的例子,它显示了要领。它可能需要调整,具体取决于您的设置。
- name: Select all from example table
sudo: yes
sudo_user: postgres
command: psql -c "SELECT * FROM example_table" example_db
register: select_all_from_example
- name: Display example table contents
debug: msg="{{ select_all_from_example.stdout }}"
基于@Christofides的例子。我做了一些修改和测试。
这个工程:
- hosts: all
sudo: yes
sudo_user: postgres
tasks:
- name: Select all from example table
command: psql -c "SELECT * FROM example_table" example_db
register: select_all_from_example
- name : Display example table contents
debug: msg="{{ select_all_from_example.stdout }}"
您可以使用提供了四个新模块一个新的角色:
不错!谢谢yantaq!这确实有效。我只需要在格式上工作,但它看起来很有希望 – Sysadmin1234
很高兴为你工作:) – yantaq