我正在尝试在 Ansible 剧本中创建一个模板任务,该任务迭代包含一些变量的字典:
- name: Task name
lineinfile:
path: /foo/bar
regexp: "{{ item.regexp }}"
line: "{{ item.line }}"
with_items:
- { regexp: "^(\/\/)?const NodeName", line: "const NodeName = '{{ inventory_hostname }}'" }
- { regexp: "^(\/\/)?const ZoneName", line: "const ZoneName = '{{ inventory_hostname }}'" }
- { regexp: "^(\/\/)?const {{ plugins_custom_dir_var_name }} =(.+)", line: "const {{ plugins_custom_dir_var_name }} = '{{ plugins_dest_dir }}'" }
此任务给了我以下语法错误:
The offending line appears to be:\n\n with_items:\n - { regexp: \"^(\\/\\/)?const NodeName\", line: \"const NodeName = '{{ inventory_hostname }}'\" }\n ^ here\nWe could be wrong, but this one looks like it might be an issue with\nmissing quotes. Always quote template expression brackets when they\nstart a value. For instance:\n\n with_items:\n - {{ foo }}\n\nShould be written as:\n\n with_items:\n - \"{{ foo }}\"\n"}
我无法理解我错在哪里。
你有一个错字, with_items 不是参数。