带shell模块的剧本中的Ansible命令

带shell模块的剧本中的Ansible命令,ansible,Ansible,我可以在ansible中使用以下内容吗: --- - hosts: webserver gather_facts: False tasks: - name: Check ping shell: ansible -i localhost.yml -m shell -a 'ping' 该本地主机包含所有主机,而playbook将在Web服务器上运行 实际需求是在webserver上运行,而在一个任务中,我需要在主机文件中指定的所有主机上运行命令 提前谢谢 只需添加以

我可以在ansible中使用以下内容吗:

---
- hosts: webserver
  gather_facts: False
  tasks:

    - name: Check ping
      shell: ansible -i localhost.yml  -m shell -a 'ping'
该本地主机包含所有主机,而playbook将在Web服务器上运行

实际需求是在webserver上运行,而在一个任务中,我需要在主机文件中指定的所有主机上运行命令

提前谢谢

只需添加以下错误:

 fatal: [webservice]: FAILED! => {
        "changed": true,
        "cmd": "ansible -i localhost.yml  -m shell -a 'ping'",
        "delta": "0:00:00.009121",
        "end": "2020-02-12 04:47:06.174390",
        "invocation": {
            "module_args": {
                "_raw_params": "ansible -i   localhost.yml -m shell -a 'ping'",
                "_uses_shell": true,
                "argv": null,
                "chdir": null,
                "creates": null,
                "executable": null,
                "removes": null,
                "stdin": null,
                "stdin_add_newline": true,
                "strip_empty_ends": true,
                "warn": true
            }
        },
        "msg": "non-zero return code",
        "rc": 127,
        "start": "2020-02-12 04:47:06.165269",
        "stderr": "ansible: not found",
        "stderr_lines": [
            "ansible: not found"
        ],
        "stdout": "",
        "stdout_lines": [] }

您想在服务器内运行ansible playbook或shell命令吗?
如果您想运行shell命令,那么不要提及playbook名称。如果要运行剧本,请不要提及
-mshell-a
shell参数。

是否尝试过?结果如何?它与您的期望有什么不同?它根本不起作用。找不到有关ansible的投诉。我在描述中添加了错误。错误中有什么不清楚的
ansible:notfound
?=>在远程服务器上安装ansible。确实如此。在playbook下运行此命令时,会引发错误。如果没有,它工作得很好。我不确定ansible命令是否可以在Playbook中使用任何命令都可以在
shell
ansible模块中使用,只要它安装在远程服务器上,并且安装在
$PATH
中,供在远程服务器上执行它的用户使用<代码>ansible也不例外。同时,我并不真正理解使用ansible来运行远程ansible命令的意义,但这是一个完全不同的故事。