Ansible的新手,运行版本2.1.0。我写了一个Ansible playbook,它针对一组主机运行PostgreSQL查询。当我在shell命令中指定SQL DB密码时,它的工作原理是,但我希望针对一组主机运行该手册,并需要更好的方式来输入密码,因为它们都是唯一的。任何人都可以提出一个更好的方法来做到这一点在Ansible Playbook中指定PostgreSQL密码
---
- hosts: Test_Hosts
sudo: yes
sudo_user: root
gather_facts: yes
tasks:
- name: Login to DB and run command
shell: export PGPASSWORD='Password'; psql -U 'user' -d 'db' -c 'select * FROM table';
register: select_all_from_table
- name: Display table contents
debug: msg="{{ select_all_from_table.stdout }}"
我看到另一个线程的话题,但不知道如何实现的建议:Run a postgresql command with ansible playbook. Postgresql requires password
谢谢你的回复,我会t你的建议。 – Sysadmin1234