gpt4 book ai didi

ansible - 在ansible playbook中连接多个变量和字符串

转载 作者:行者123 更新时间:2023-12-02 03:46:08 27 4
gpt4 key购买 nike

在为目标部分执行 with_items 时,我正在尝试多重串联。

现在看起来像这样:

- name: create app except+lookup
copy: content="" dest="{{ dir.comp ~ '/config/con2dd/' ~ item.name ~ 'File.txt' }}" force=no group=devops owner=devops mode: 0755
with_items:
...

我得到:

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

尝试了几种方法,但没有一个有效。

是否可以将变量与字符串连接起来?

最佳答案

不要将纯 YAML 和 key=value 语法混合用于参数。并且始终对复杂参数使用 YAML 语法:

- name: create app except+lookup
copy:
content: ""
dest: "{{ dir.comp }}/config/con2dd/{{ item.name }}File.txt"
force: no
group: devops
owner: devops
mode: 0755
with_items:
...

关于ansible - 在ansible playbook中连接多个变量和字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45400851/

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