如何从其他文件调用ansible yml文件?
我是ansible的新手,我正在尝试从我的plybk.yml调用我的任务.yml my_playbk.yml的内容如下:如何从其他文件调用ansible yml文件?,ansible,yaml,Ansible,Yaml,我是ansible的新手,我正在尝试从我的plybk.yml调用我的任务.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 comm
---
- 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
我想问题可能是您的
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文件通常对行和空格的排列方式非常敏感。@Vivek请使用新的更改重试
任务:
我的任务中的行。yml缩进太多。应直接位于主机下