如何从其他文件调用ansible yml文件?

时间:2019-07-30 06:30:15

标签: ansible yaml

我是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

1 个答案:

答案 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文件对如何安排行和空格非常敏感。