2017-05-23 3 views
0

ホスト別にグループ化するときに繰り返しがないようにこのコードを短縮するにはどうすればいいですか? rhel5、rhel6、rhel7ブロックを繰り返す代わりに。私はwith_itemsを試しましたが運はありませんか?Group_by hosts変数

--- 
- 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}}" 

答えて

0

あなたはpatternsを使用することができます。

--- 
- 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}}" 

あなたはすべての何かが必要な場合は、使用することができます。

- hosts: rhel*:!rhel4 
関連する問題