我是ansible的新手,我正尝试从my_plybk.yml调用my_task.yml。
my_playbk.yml的内容如下:
---
- hosts: localhost
gather_facts: no
tasks:
- include my_tasks.yml
my_task.yml的内容如下。
- hosts: localhost
tasks:
- name: Run the below script
command: sh myscript.sh
myscript.sh的内容
echo "Hello"
下面是我得到的错误。
ERROR! A malformed block was encountered while loading a block
答案 0 :(得分:1)
我想问题可能出在您的my_plybk.yaml
文件中。
应这样安排:
---
- hosts: localhost
gather_facts: no
tasks:
- include: my_tasks.yml
此外,“ include”之后缺少冒号。
与my_tasks.yml
文件相同:
- name: Run the below script
command: sh myscript.sh
另外,请注意上面的文本中,您所包含的文件应仅包含任务列表,而不能包含“主机”或“任务”关键字。
请注意,通常Ansible和yaml文件对如何安排行和空格非常敏感。