Useful shortcuts for vi editor

Friday 29 June 2018

How to run a SQL query/statement in a task?

You are able to run a SQL query/statement with "echo" command by shell module for the ansible task.

# an example task for sql query/statement
- name: set default schema for user
  shell: echo "ALTER ROLE alper SET SEARCH_PATH TO myschema" | psql
  become: yes
  become_user: postgres

benefit of "gather_facts: no" setting

If you do not need any facts for your variables, you can run your playbook more fast via gather_facts setting.

For this, just add following setting in your playbook:

# example playbook
- name: Run the role for me 
  hosts: my_nodes
  gather_facts: no
  roles:
  - example-role