首页 > 解决方案 > 使用 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}

标签: ansibleibm-mqansible-facts

解决方案


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

推荐阅读