Ansible 按主机变量分组
如何缩短此代码,以便在按主机分组时不会重复?而不是重复rhel5、rhel6和rhel7块。我试过_项目,但没有运气Ansible 按主机变量分组,ansible,Ansible,如何缩短此代码,以便在按主机分组时不会重复?而不是重复rhel5、rhel6和rhel7块。我试过_项目,但没有运气 --- - hosts: "{{hosts}}" remote_user: root tasks: - group_by: key=rhel{{ansible_distribution_major_version}} - hosts: rhel5 tasks: - debug: msg="{{ansible_distribution}} {{a
---
- hosts: "{{hosts}}"
remote_user: root
tasks:
- group_by: key=rhel{{ansible_distribution_major_version}}
- hosts: rhel5
tasks:
- debug: msg="{{ansible_distribution}} {{ansible_distribution_release}} {{ansible_distribution_version}}"
- hosts: rhel6
tasks:
- debug: msg="{{ansible_distribution}} {{ansible_distribution_release}} {{ansible_distribution_version}}"
- hosts: rhel7
tasks:
- debug: msg="{{ansible_distribution}} {{ansible_distribution_release}} {{ansible_distribution_version}}"
您可以使用:
如果您只需要一些东西,您可以使用:
- hosts: rhel*:!rhel4
- hosts: rhel*:!rhel4