Ansible playbook创建新目录失败
我使用以下playbook结构将数据从yml文件加载到Jinja2模板,然后生成具有相同结构的新yml文件 ansible-starter.ymlAnsible playbook创建新目录失败,ansible,yaml,Ansible,Yaml,我使用以下playbook结构将数据从yml文件加载到Jinja2模板,然后生成具有相同结构的新yml文件 ansible-starter.yml - name : Properties configuration - Jinja2 hosts: localhost vars_files: - ../data.yml tasks: - name: Creating config directory file: path: ../j2-
- name : Properties configuration - Jinja2
hosts: localhost
vars_files:
- ../data.yml
tasks:
- name: Creating config directory
file:
path: ../j2-resources/generated
state: directory
mode: '0755'
- name: Applying configuration template to data.yml
template:
src: ./template-files/template.yml.j2
dest: ./generated/updated.yml
但它不断给出以下错误:
Syntax Error while loading YAML.
mapping values are not allowed in this context
The error appears to be in '/j2-resources/ansible-starter.yml': line 17, column 11, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- name: Creating config directory
file:
^ here
似乎出现了一些缩进问题。确保在执行之前让yml文件通过yml格式化程序。有几个缩进错误: 应该是:
- name: Properties configuration - Jinja2
hosts: localhost
vars_files:
- ../data.yml
tasks:
- name: Creating config directory
file:
path: ../j2-resources/generated
state: directory
mode: '0755'
- name: Applying configuration template to data.yml
template:
src: ./template-files/template.yml.j2
dest: ./generated/updated.yml
检查
文件:
缩进。有一个额外的前导空格。已选中。不是这样的错误改变了吗?没有,还是一样的错误。已使用ansible.builtin.file进行检查:也是。我发现了这个错误。行-名称:应用配置…
缩进错误。有一个额外的前导空格,没错。编辑!