gpt4 book ai didi

ansible - blockinfile 模块中的 jinja 变量替换

转载 作者:行者123 更新时间:2023-12-04 09:11:47 25 4
gpt4 key购买 nike

我希望在 blockinfile block 中使用变量,所以我制作了这个剧本:

- 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 支持 block 模块内的 jinja 模板,我在任何文档中都找不到。
你有什么想法?

最佳答案

block 的缩进是错误的。见 examples并修复它

    - name: Add new user
blockinfile:
dest: /root/ansible/users.yml
backup: yes
block: |
'{{ nome_utente }}'@'{{ dominio }}':
gruppo: '{{ gruppo }}'

Popular Editors支持自动缩进和语法高亮。

关于ansible - blockinfile 模块中的 jinja 变量替换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63336834/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com