Running a SELECT Query with an Ansible Task

后端 未结 1 670
梦如初夏
梦如初夏 2020-12-30 23:12

In this list of mysql db modules for Ansbile, there\'s one for creating a db, or creating a user, etc.

I would like to run a query against a pre-existing table and u

相关标签:
1条回答
  • 2020-12-31 00:14

    This is approximately how to do it (but it is untested):

    - name: Retrieve stuff from mysql
      command: >
        mysql --user=alice --password=topsecret dbname
        --host=147.102.160.1 --batch --skip-column-names
        --execute="SELECT stuff from stuff_table"
      register: stuff
      check_mode: no
      changed_when: False
    
    - name: Do something with stuff
      debug: "{{ item }}"
      with_items: stuff.stdout_lines
    

    Documented here.

    0 讨论(0)
提交回复
热议问题