Назад | Перейти на главную страницу

Ansible и словарные ключи с переменными

Я пытаюсь создать шаблон задача в пьесе 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 не является параметром.

- 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 }}'" }