Guest User

Untitled

a guest
Mar 6th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. ---
  2.  
  3. - hosts: Test_Hosts
  4. sudo: yes
  5. sudo_user: root
  6. gather_facts: yes
  7. tasks:
  8. - name: Login to DB and run command
  9. shell: export PGPASSWORD='Password'; psql -U 'user' -d 'db' -c 'select * FROM table';
  10. register: select_all_from_table
  11.  
  12. - name: Display table contents
  13. debug: msg="{{ select_all_from_table.stdout }}"
  14.  
  15. - name: Login to DB and run command
  16. shell: export PGPASSWORD='Password'; psql -U 'user' -d 'db' -c 'select * FROM table';
  17. register: select_all_from_table
  18. environment:
  19. PGPASSWORD: '{{ pgpassword }}'
  20.  
  21. - name: set passwd file for PSQL
  22. copy:
  23. src: files/pgpass
  24. dest: ~/.pgpass
  25. mode: 0600 ### important: will not work with wrong permissions
  26.  
  27. - name: PSQL command
  28. shell: "psql -U 'user' -d 'db' -c 'select * FROM table'"
  29. register: select_all_from_table
  30.  
  31. hostname:port:database:username:password
  32.  
  33. *:*:db1:user1:passwd1
  34. *:*:db2:user2:passwd2
Add Comment
Please, Sign In to add comment