Ansible |如何从字典构造csv字符串

Ansible |如何从字典构造csv字符串,ansible,Ansible,我有一本这样的字典 customers: abc: id: 1 status: active def: id: 2 status: inactive ghi: id: 3 status: active jkl: id: 4 status: active 最好的方法是什么来构造一个字符串,就像下面的活动客户一样 abc,ghi,jkl 例如: --- - hosts: localhost gather_fact

我有一本这样的字典

customers:
  abc:
    id: 1
    status: active
  def:
    id: 2
    status: inactive
  ghi:
    id: 3
    status: active
  jkl:
    id: 4
    status: active
最好的方法是什么来构造一个字符串,就像下面的活动客户一样

abc,ghi,jkl
例如:

---
- 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(',') }}"

这不完全是你想要的,但我认为这可能会增加这个问题的价值

在我的例子中,我需要使用空格连接一个项目列表

默认值/main.yml

vars/main.yml

因此

TASK [... : debug] 
ok: [...] => {
    "backup_dev_strip_merged": "@stripped @development"
}

还有一个问题,我怎样才能附加一个字符串(例如cust_),使输出看起来像这样<代码>客户abc、客户ghi、客户jkl添加
map('regex_替换'、'^'、'cust')
加入之前
---
backup_dev_strip_merged: "{{ backup_dev_strip | join(' ') }}"
TASK [... : debug] 
ok: [...] => {
    "backup_dev_strip_merged": "@stripped @development"
}