Ansible脚本模块抛出语法错误

Ansible脚本模块抛出语法错误,ansible,Ansible,Ansible语法验证抛出错误消息,如下所示: ERROR! no action detected in task. This often indicates a misspelled module name, or incorrect module path. The error appears to have been in '/mgdbplybks/test.yml': line 16, column 5, but may be elsewhere in the file dependi

Ansible语法验证抛出错误消息,如下所示:

ERROR! no action detected in task. This often
indicates a misspelled module name, or incorrect module path.

The error appears to have been in '/mgdbplybks/test.yml': line 16,
column 5, but may be elsewhere in the file depending on the exact
syntax problem.

The offending line appears to be:

  tasks:
  - name: launch mongod replA
    ^ here
===================================================== 
如果我注释掉脚本模块,语法检查就可以了

在任务中未检测到任何操作。这通常表示模块名称拼写错误

正如错误所说,您有一个空的-name

tasks:
- name: launch mongod replA
- script:... 
脚本是第二项任务。第一个是空的

tasks:
- name: launch mongod replA
- script:... 
你是说这个吗

tasks:
- name: launch mongod replA
  script: /scripts/mgdbscripts/replsetA.sh

不能将两个操作模块添加到Ansible中的单个任务中


您需要将脚本和shell拆分为两个任务。

name不是空的。它将脚本模块作为操作。您拥有的剧本的附加图像-名称:…,然后-脚本:。。。贝壳:。。。-字符列出要完成的每个任务。由于您使用了-script,因此-name任务什么也没有做,因为错误表明在一个任务中使用了两个操作/模块。改变这一点解决了问题。关于-…的用法,可能没问题。YAML语法您最初的问题有一个空的命名任务和一个动作中的两个动作。我只解决了其中的第一个问题,请不要在文本足够时添加图像。这让问题变得难以探究。