我正在尝试收集有关 mysql 集群的信息,以便在某些本地逻辑中使用。
我的问题是如果我在远程主机上运行我的命令,我将无法访问这些结果
- name: get uuids for existing cluster nodes
shell: mysql -N -B -u {{ db_user }} -p {{ db_user_password }} -e "SHOW GLOBAL STATUS LIKE 'wsrep_cluster_state_uuid';" | sed 's/\t/,/g' | cut -f2 -d','
register: maria_cluster_uuids
Run Code Online (Sandbox Code Playgroud)
这给了我我需要的数据,但我真正想要的是结果的组合列表/字典。
我可以尝试:
- name: get uuids for existing cluster nodes
run_once: true
shell: mysql -N -B -u {{ db_user }} -h {{ item }} -p {{ db_user_password }} -e "SHOW GLOBAL STATUS LIKE 'wsrep_cluster_state_uuid';" | sed 's/\t/,/g' | cut -f2 -d','
register: maria_cluster_uuids
with_items: play_hosts
delegate_to: 127.0.0.1
Run Code Online (Sandbox Code Playgroud)
但是,mysql 会发出警告,老实说,我不想强加安装 mysql 客户端的本地机器的要求。
令人讨厌的感觉我将不得不在这里写一些 python ......
yae*_*shi 10
使用set_fact
模块和hostvars
:
---
- hosts: all
vars:
uuids: |
{%- set o=[] %}
{%- for i in play_hosts %}
{%- if o.append(hostvars[i].uuid) %}
{%- endif %}
{%- endfor %}
{{ o }}
tasks:
- name: get uuids for existing cluster nodes
shell: mysql -N -B -u {{ db_user }} -p {{ db_user_password }} -e "SHOW GLOBAL STATUS LIKE 'wsrep_cluster_state_uuid';" | sed 's/\t/,/g' | cut -f2 -d','
register: maria_cluster_uuids
- set_fact:
uuid: "{{ maria_cluster_uuids.stdout }}"
- debug:
var: uuids
run_once: true
delegate_to: 127.0.0.1
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
10181 次 |
最近记录: |