Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running a SELECT Query with an Ansible Task

Tags:

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 use the results of that query to populate an Ansible variable (list of IP addresses, and node type) upon which I would run different tasks, depending on node type.

How can that be done in Ansible?

like image 568
Sam Hammamy Avatar asked Jun 02 '15 20:06

Sam Hammamy


1 Answers

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.

like image 102
Antonis Christofides Avatar answered Sep 25 '22 12:09

Antonis Christofides