Running a SELECT Query with an Ansible Task

落爺英雄遲暮 提交于 2019-12-04 16:44:38

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/30605950/running-a-select-query-with-an-ansible-task

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!