本文介紹了使用 Ansible 任務運行 SELECT 查詢的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
在 this 的 Ansbile mysql 數據庫模塊列表中,有一個用于創建數據庫,或者創建用戶等
In this list of mysql db modules for Ansbile, there's one for creating a db, or creating a user, etc.
我想對預先存在的表運行查詢,并使用該查詢的結果來填充 Ansible 變量(IP 地址列表和節點類型),我將根據節點類型運行不同的任務.
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.
在 Ansible 中如何做到這一點?
How can that be done in Ansible?
推薦答案
這大概是怎么做的(但未經測試):
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
記錄在此處.
這篇關于使用 Ansible 任務運行 SELECT 查詢的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!