blockinfile 模块中的 jinja 变量替换
jinja variable substitution inside blockinfile module
我想在 blockinfile 块中使用变量,所以我制作了这个剧本:
- name: New user
hosts: all
gather_facts: false
become: yes
become_user: root
vars:
nome_utente: pippo
dominio: pluto.it
gruppo: root
tasks:
- name: Add new user
blockinfile:
dest: /root/ansible/users.yml
backup: yes
block: |
'{{ nome_utente }}'@'{{ dominio }}':
gruppo: '{{ gruppo }}'
但我收到以下错误:
ERROR! Syntax Error while loading YAML.
found character that cannot start any token
The error appears to be in '/home/francesco/test.yml': line 16, column 27, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
block: |
'{{ nome_utente }}'@'{{ dominio }}':
^ here
We could be wrong, but this one looks like it might be an issue with
missing quotes. Always quote template expression brackets when they
start a value. For instance:
with_items:
- {{ foo }}
Should be written as:
with_items:
- "{{ foo }}"
抱歉,如果 blockinfile 支持块模块内的 jinja 模板,我在任何文档中都找不到。
你有什么想法吗?
块的缩进错误。查看 examples 并修复它
- name: Add new user
blockinfile:
dest: /root/ansible/users.yml
backup: yes
block: |
'{{ nome_utente }}'@'{{ dominio }}':
gruppo: '{{ gruppo }}'
参见支持 auto-indentation 和语法高亮显示的 Popular Editors。
我想在 blockinfile 块中使用变量,所以我制作了这个剧本:
- name: New user
hosts: all
gather_facts: false
become: yes
become_user: root
vars:
nome_utente: pippo
dominio: pluto.it
gruppo: root
tasks:
- name: Add new user
blockinfile:
dest: /root/ansible/users.yml
backup: yes
block: |
'{{ nome_utente }}'@'{{ dominio }}':
gruppo: '{{ gruppo }}'
但我收到以下错误:
ERROR! Syntax Error while loading YAML.
found character that cannot start any token
The error appears to be in '/home/francesco/test.yml': line 16, column 27, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
block: |
'{{ nome_utente }}'@'{{ dominio }}':
^ here
We could be wrong, but this one looks like it might be an issue with
missing quotes. Always quote template expression brackets when they
start a value. For instance:
with_items:
- {{ foo }}
Should be written as:
with_items:
- "{{ foo }}"
抱歉,如果 blockinfile 支持块模块内的 jinja 模板,我在任何文档中都找不到。
你有什么想法吗?
块的缩进错误。查看 examples 并修复它
- name: Add new user
blockinfile:
dest: /root/ansible/users.yml
backup: yes
block: |
'{{ nome_utente }}'@'{{ dominio }}':
gruppo: '{{ gruppo }}'
参见支持 auto-indentation 和语法高亮显示的 Popular Editors。