在Ansible中添加列表周围的单引号
我有一个项目服务列表,每个项目都需要用单个引号包裹以配置某些参数。
我看到的最简单的解决方案是:
"{{services | match('quote') | join(' OR ')}}"
这仅在单个报价中包裹了列表中的第一个元素,而不是剩下的。
我还尝试了Match Regex的一些变体。
最后,我尝试在数据源中手动添加单个报价,然后加入。第一个元素保留了单个报价,但随后被剥夺了吗?这里发生了什么?
现在,它们从库存中静止不动 IE:
---
inventory:
hosts:
host1:
procs:
- splunkd.*
services:
- 'some service name'
- 'another service name'
- 'SplunkForwarder'
我需要最终结果,
"Name='some service name' OR Name='another service name'"
目前是在变量中引用的单一引用的服务。引号被剥离或忽略。
结果
Name=some service or Name=another service
I have a list of items services and each needs to be wrapped in single quotes to configure some parameters.
The simplest solution I saw posted was:
"{{services | match('quote') | join(' OR ')}}"
This only wrapped the first element in the list in a single quote but not the remaining.
I also tried some variations of match regex.
Finally I tried adding the single quote manually in the data source, then joining. The first element retained the single quotes but subsequent were stripped off? What is going on here?
Right now they are static from the inventory
i.e.:
---
inventory:
hosts:
host1:
procs:
- splunkd.*
services:
- 'some service name'
- 'another service name'
- 'SplunkForwarder'
I need the end result to be
"Name='some service name' OR Name='another service name'"
Currently with the services single quoted in variable the quotes are stripped or ignored.
Result
Name=some service or Name=another service
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用循环来切除问题:
结果:
与您的VAR:
you could cut your problem by using loop:
result:
with your vars: