ansible - 使用 Ansible 显示 MQ 侦听器状态不工作
问题描述
---
- hosts: all
become_user: mqm
become_method: sudo
tasks:
- name: Execute a MQ Command
shell:
cmd: "echo 'DISPLAY LSSTATUS(TCP) STATUS' | runmqsc QMGR"
chdir: /opt/mqm/bin/runmqsc
register: mqstat
- debug:
var: mqstat.stdout_lines
**错误: **
TASK [Execute a MQ Command] ****************************************************************************************************************************************
fatal: [QMGR]: FAILED! => {"changed": false, "module_stderr": "Shared connection to xyz.pqr.com closed.\r\n", "module_stdout": "Traceback (most recent call last):\r\n File \"/tmp/ansible_UASQnG/ansible_module_command.py\", line 213, in <module>\r\n main()\r\n File \"/tmp/ansible_UASQnG/ansible_module_command.py\", line 152, in main\r\n os.chdir(chdir)\r\nOSError: [Errno 20] Not a directory: '/opt/mqm/bin/runmqsc'\r\n", "msg": "MODULE FAILURE", "rc": 0}
解决方案
chdir:/opt/mqm/bin/runmqsc
如果这应该是执行命令的目录,runmqsc 不是目录名,所以它不应该只是 chdir:/opt/mqm/bin。此外,请记住,如果您通过管道连接到 runmqsc,则 runmqsc 必须在路径上。如果不是,那么您需要完全限定它,这意味着尝试:
shell: cmd: "echo 'DISPLAY LSSTATUS(TCP) STATUS' | ./runmqsc QMGR" chdir: /opt/mqm/bin
或者
shell: cmd: "echo 'DISPLAY LSSTATUS(TCP) STATUS' | /opt/mqm/bin/runmqsc QMGR" chdir: /opt/mqm/bin
推荐阅读
- python - 在没有 sudo 的 virtualenv 中安装具有二进制依赖项的 Python 库时出现问题
- php - 带有点和运算符的正则表达式 PHP 十进制数
- javascript - 在获取期间无法在 try-catch 中捕获 403
- java - 了解新的 Intent 崩溃
- java - 我可以在 filebeat 中使用 apache2 模块摄取 apache tomcat ser 日志吗
- maven - maven如何将依赖项jar中的多个文件按特定顺序连接起来?
- python - 通过几年迭代日期来创建一个 url 列表
- matlab - 将矩阵转换为结构时出错?
- java - 单击 ListView 中的项目时在另一个活动中显示列表
- algorithm - 计算船上所有部件离开所需步数的算法