我有这样的字典
customers:
abc:
id: 1
status: active
def:
id: 2
status: inactive
ghi:
id: 3
status: active
jkl:
id: 4
status: active
构建像以下活跃客户的字符串的最佳方法是什么?
abc,ghi,jkl
答案 0 :(得分:3)
例如:
---
- hosts: localhost
gather_facts: no
vars:
customers:
abc:
id: 1
status: active
def:
id: 2
status: inactive
ghi:
id: 3
status: active
jkl:
id: 4
status: active
tasks:
- debug:
msg: "{{ customers | dictsort | selectattr('1.status','equalto','active') | map(attribute='0') | join(',') }}"
答案 1 :(得分:0)
并非完全符合您的要求,但我认为这可能会增加问题的价值。
就我而言,我需要使用空格将项目列表连接起来。
默认值/main.yml
Caused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.springframework.transaction.PlatformTransactionManager] is defined: expected single matching bean but found 2: txManager,transactionManager
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:365)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:331)
at org.springframework.transaction.interceptor.TransactionAspectSupport.determineTransactionManager(TransactionAspectSupport.java:366)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:271)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:653)
at com.mypackage.services.MyClassService$$EnhancerBySpringCGLIB$$9e8bf16f.registryEvents(<generated>)
at com.mypackage.controllers.MyClassSearchView.init(MyClassSearchView.java:75)
... 168 more
vars / main.yml
---
backup_dev_strip:
- "@stripped"
- "@development"
结果
---
backup_dev_strip_merged: "{{ backup_dev_strip | join(' ') }}"