variables - Ansible 中嵌套变量的语法错误
问题描述
我在我的剧本中包含了以下变量文件:
more vars/was_vars.yaml
::::::::::::::
10.9.12.112: "/was/IBM/WebSphere"
10.8.10.28: "/was/IBM/profiles"
10.7.120.129: "/app/tmp"
这是我的剧本:
- name: Configure nodes
hosts: dest_nodes
user: "{{ USER }}"
tasks:
- name: Construct File Path on "{{ inventory_hostname }}".
command: "touch {{ BASEPATH }}/{{ ( item | splitext)[1] }}/del.tmp"
when: "{{ Layer == 'APP' }}"
file: path="{{ "{{ inventory_hostname }}" }}/{{ App_List }}/{{ Rel_Path }}/del.tmp state=directory mode=u=rwx,g=rw,o=r"
when: "{{ Layer == 'WAS' }}"
"{{inventory_hostname }}" 被替换为 "10.9.12.112",然后应进一步替换为 "/was/IBM/WebSphere",如包含的 vars("was_vars.yaml") 文件中所述。
我的当前代码出现以下语法错误:
ERROR! conflicting action statements: command, file
The error appears to be in '/app/Ansible/deploy.yml': line 133, column 4, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
tasks:
- name: Construct File Path on "{{ inventory_hostname }}".
^ 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 }}"
我在ansible上的最新版本。
你能建议吗?
解决方案
你可以试试:
"{{vars[inventory_hostname]}}"
或者,如果您想要更多级别,请使用:
"{{vars[vars[inventory_hostname]]}}"
推荐阅读
- typescript - 如何对属性之一可能具有不同名称的对象进行类型安全?
- windows - git for windows中的cygheap不匹配错误
- python - 分类数据单独表示
- javascript - 为什么在产生 SyntaxError 之前带有 0 的十进制数?
- javascript - 支付成功时打开特定url-paypal按钮
- python - 无法使用请求从网站获取一些数字
- excel - 从 Excel 中的显示名称中检索别名
- flutter - 如何在颤动的屏幕中心创建一个标签栏?
- javascript - 如何使 JavaScript 代理的处理程序方法成为异步函数?
- angular - Angular/TypeScript:小吃店的单元测试调用