Ansible shell模块在AiX系统上出现故障和错误

Ansible shell模块在AiX系统上出现故障和错误,shell,ansible,runtime-error,Shell,Ansible,Runtime Error,下面是我的剧本,其中有一个shell模块: 注意:mypid变量是在目标主机上运行的进程的进程id - shell: | if [ -z {{tm}} ]; then mypid="wrongpid"; else mypid= {{tm}}; fi; if [ ! -e /proc/$mypid/status ]; then exit 1; fi istat {{fn}} | grep -i Modif | cut -d' ' -f3,4,5,6 vars:

下面是我的剧本,其中有一个shell模块:

注意:mypid变量是在目标主机上运行的进程的进程id

- shell: |
    if [ -z {{tm}} ]; then mypid="wrongpid"; else mypid= {{tm}}; fi;
    if [ ! -e /proc/$mypid/status ]; then exit 1; fi
    istat {{fn}} | grep -i Modif  | cut -d' ' -f3,4,5,6
  vars:
    fn: "/proc/{{ mypid }}/status"
    tm: "{{ mypid }}"
  tags: always
  ignore_errors: yes
  register: starttime
这在Linux系统上运行良好。在AiX上,尽管此shell模块失败,但出现以下错误:

 TASK [shell] *******************************************************************
[1;30mtask path: /app/playbook/startstop.yml:318[0m
[0;31mfatal: [10.9.9.131]: FAILED! => {"changed": true, "cmd": "if [ -z 12386652 ]; then mypid=\"wrongpid\"; else mypid= 12386652; fi;\nif [ ! -e /proc/$mypid/status ]; then exit 1; fi\nistat /proc/12386652/status | grep -i Modif  | cut -d' ' -f3,4,5,6\n", "delta": "0:00:00.108227", "end": "2019-11-21 14:09:35.064768", "msg": "non-zero return code", "rc": 1, "start": "2019-11-21 14:09:34.956541", "stderr": "/bin/sh: 12386652:  not found.", "stderr_lines": ["/bin/sh: 12386652:  not found."], "stdout": "", "stdout_lines": []}[0m
[0;36m...ignoring[0m
我添加了以下shell参数,但仍然存在错误:

  args:
     executable: /bin/ksh
在目标服务器上作为shell脚本运行shell也可以正常工作。不知道为什么在ansible剧本中失败了


请建议

您的shell变量赋值表达式中有一个额外的空格,导致sh尝试执行命令,而不是赋值变量:

else mypid= {{tm}} => else mypid={{tm}}
此外,您应该稍微保护整个表达式,以确保不会出现其他意外情况(例如,使用空参数…)


您的shell变量赋值表达式中有一个额外的空间,导致sh尝试执行命令,而不是赋值变量:

else mypid= {{tm}} => else mypid={{tm}}
此外,您应该稍微保护整个表达式,以确保不会出现其他意外情况(例如,使用空参数…)


这就解决了问题@Zeitounator感谢您指出。这解决了问题@Zeitounator感谢您指出。