How to remove or exclude an item in an Ansible template list?

前端 未结 1 1217
野趣味
野趣味 2021-02-13 15:56

I\'m writing an Ansible template that needs to produce a list of ip\'s in a host group, excluding the current hosts IP. I\'ve searched around online an

1条回答
  •  旧巷少年郎
    2021-02-13 16:16

    There is difference filter for that:

    - debug: var=item
      with_items: "{{ groups['my_group'] | difference([inventory_hostname]) }}"
    

    This will give you all items hosts from my_group without current host.

    0 讨论(0)
提交回复
热议问题