Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
518 views
in Technique[技术] by (71.8m points)

ansible - How should an include playbook be different from a standalone one?

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.

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

When I run 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.

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


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
"}

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

How should an include playbook be different from a standalone one?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...