首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Group_by主机变量

Group_by主机变量
EN

Stack Overflow用户
提问于 2017-05-23 15:17:40
回答 1查看 343关注 0票数 0

如何缩短这段代码,使我按主机分组时不会重复?而不是重复rhel5、rhel6和rhel7块。我试过with_items,但没有运气?

代码语言:javascript
复制
---
- 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}}"
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-05-23 15:53:30

您可以使用模式

代码语言:javascript
复制
---
- hosts: "{{hosts}}"
  remote_user: root
  tasks:
    - group_by: key=rhel{{ansible_distribution_major_version}}    

- hosts: rhel5:rhel6:rhel7
  tasks:
    - debug: msg="{{ansible_distribution}} {{ansible_distribution_release}} {{ansible_distribution_version}}"

如果你只需要一些东西,你可以使用:

代码语言:javascript
复制
- hosts: rhel*:!rhel4
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44138854

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档