Ansible 循环遍历库存

Ansible loops throught inventory

我正在寻找一种循环使用 ansible 库存的方法

库存

[deployer]
ceph-node0

[mons]
ceph-node0
ceph-node1
ceph-node2

task.yml

- hosts: deployer
  become: true
  tasks:
    - name: create monitor node
      command: ceph orch apply mon {{ item.0 }},{{ item.1 }},{{ item.2 }}, {{ itemN }}
      with_items: 
        - "{{ groups['mons'] }}"

我希望只执行一次就能得到这样的结果

ceph orch apply mon ceph-node0,ceph-node1,ceph-node2,..ceph-nodeN

使用 join 过滤器。

- debug:
    msg: "ceph orch apply mon {{ groups['mons'] | join(',') }}"