Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---
- - 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 }}"
- - 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
- environment:
- PGPASSWORD: '{{ pgpassword }}'
- - name: set passwd file for PSQL
- copy:
- src: files/pgpass
- dest: ~/.pgpass
- mode: 0600 ### important: will not work with wrong permissions
- - name: PSQL command
- shell: "psql -U 'user' -d 'db' -c 'select * FROM table'"
- register: select_all_from_table
- hostname:port:database:username:password
- *:*:db1:user1:passwd1
- *:*:db2:user2:passwd2
Add Comment
Please, Sign In to add comment