Ansible 包含剧本与独立剧本应该有什么不同?

Ansible 包含剧本与独立剧本应该有什么不同?,ansible,ansible-playbook,Ansible,Ansible Playbook,我有两个针对远程主机启动的剧本(10.233.84.58)。当启动单机版(ansible playbook-i inventory.txt playbook.yml)时,它们工作正常 第一个剧本包括第二个剧本,第二个剧本完全相同,除了include: --- - hosts: all tasks: - debug: msg="hello form playbook1" # up to now the content is identical between playbook1

我有两个针对远程主机启动的剧本(
10.233.84.58
)。当启动单机版(
ansible playbook-i inventory.txt playbook.yml
)时,它们工作正常

第一个剧本包括第二个剧本,第二个剧本完全相同,除了
include

---
- hosts: all
  tasks:
    - debug: msg="hello form playbook1"
    # up to now the content is identical between playbook1.yaml and playbook2.yaml
    # without the next line the playbook runs fine
    - include: playbook2.yml
当我运行
playbook1.yml
时:

# ansible-playbook -i inventory.txt playbook1.yml                                                                (master✱)

PLAY [all] *********************************************************************

TASK [setup] *******************************************************************
ok: [10.233.84.58]

TASK [debug] *******************************************************************
ok: [10.233.84.58] => {
    "msg": "hello form playbook1"
}

TASK [include] *****************************************************************
fatal: [10.233.84.58]: FAILED! => {"failed": true, "reason": "no action detected in task. This often indicates a misspelled module name, or incorrect module path.\n\nThe error appears to have been in '/root/tests/playbook2.yml': line 2, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n---\n- hosts: all\n  ^ here\n\n\nThe error appears to have been in '/root/tests/playbook2.yml': line 2, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n---\n- hosts: all\n  ^ here\n"}

NO MORE HOSTS LEFT *************************************************************
        to retry, use: --limit @playbook1.retry

PLAY RECAP *********************************************************************
10.233.84.58               : ok=2    changed=0    unreachable=0    failed=1
我从上面的错误消息中提取了“原因”,使其更具可读性:

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

The error appears to have been in '/root/tests/playbook2.yml': line 2, column 3, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

---
- hosts: all
  ^ here

包含剧本与独立剧本有何不同?

包含有两种类型。您可以包括剧本或任务列表

---
- hosts: all
  tasks:
    - include: list_of_tasks.yml

- include: complete_playbook.yml
在您的示例中,您尝试将playbook2.yml包含为任务列表。

include
移动到与
-hosts
相同的缩进中,您会感觉很好。

有两种类型的include。您可以包括剧本或任务列表

---
- hosts: all
  tasks:
    - include: list_of_tasks.yml

- include: complete_playbook.yml
在您的示例中,您尝试将playbook2.yml包含为任务列表。

移动
包含在与
-hosts
相同的缩进中,您会很好。

谢谢您-就是这样。同时也感谢到目前为止我发现ansible的所有帮助。谢谢-就是这样。也感谢所有的帮助,直到我发现ansible。