【问题标题】:Executing commands in mysqlsh using ansible playbooks使用 ansible playbook 在 mysqlsh 中执行命令
【发布时间】:2021-04-01 09:59:19
【问题描述】:

我在下面尝试了类似 sn-p 的操作,但第二个任务在主机的 shell 终端上执行,而不是在 mysql shell 上执行。如何在第一个任务中对打开的 mysqlsh 执行命令? 例如:我想登录到 shell 并检查 mysql 集群的状态。

tasks:
- name: "connect as clusteradmin"
shell: mysqlsh --uri admin@host1 -p'pass'
- name: "get cluster"
shell: var cluster=dba.getCluster('cluster')
- name: "check status of cluster"
shell: cluster.status()
register: Clustersts

【问题讨论】:

    标签: mysql shell yaml


    【解决方案1】:

    尝试将您的请求与参数“--execute=command”放在一行中。 这是对我有用的东西:

    mysqlsh -uUSER -pPASSWORD -P 3306 --execute='util.checkForServerUpgrade()'

    你的可能如下所示:

    - name: "connect as clusteradmin and get cluster"

    shell: mysqlsh --uri admin@host1 -p'pass' --execute='var cluster=dba.getCluster('cluster')'

    然后:

    - name: "connect as clusteradmin and check status of cluster"

    shell: mysqlsh --uri admin@host1 -p'pass' --execute='cluster.status()'

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-12-09
      • 2017-09-16
      • 1970-01-01
      • 2020-06-02
      • 1970-01-01
      • 2016-06-18
      • 2019-11-21
      相关资源
      最近更新 更多