包含剧本与独立剧本有何不同? [英] How should an include playbook be different from a standalone one?

查看:22
本文介绍了包含剧本与独立剧本有何不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have two playbooks which are launched against a remote host (10.233.84.58). When launched standalone (ansible-playbook -i inventory.txt playbook.yml) they work fine.

第一个 playbook 包括第二个,除了 include 明显不同:

The first playbook includes the second one, which is identical, except obviously for the 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

我从上面的错误消息中提取了原因"并使其更具可读性:

I extracted the "reason" from the error message above and made it more readable:

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

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

推荐答案

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

There are two types of include. You can include playbook or list of tasks.

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

- include: complete_playbook.yml

在您的示例中,您尝试将 playbook2.yml 作为任务列表包含在内.
include 移动到与 -hosts 相同的缩进处,你会很好.

In your example you try to include playbook2.yml as a list of tasks.
Move include on the same indent as - hosts and you'll be good.

这篇关于包含剧本与独立剧本有何不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆