美文网首页
ansible 不同role对应不同的host

ansible 不同role对应不同的host

作者: mini鱼 | 来源:发表于2021-08-03 11:25 被阅读0次

    有时候,在一个playbook中,我们希望不同的host group 可以对应不同的role,则可以使用以下方法:

    # applied to all hosts
    - hosts: all
      gather_facts: yes
      roles: 
        - prerequsites-for-all
    
    # only applied to 'myrole' group
    - hosts: myrole
      roles: 
        - role: echo
    

    也可以:

    - hosts: all
      gather_facts: yes
      roles: 
        - prerequisites-for-all
        - { role: echo, when: "'myrole' in group_names" }
    

    原文: Ansible: applying roles to certain groups in a single playbook

    官方参考:Patterns: targeting hosts and groups

    相关文章

      网友评论

          本文标题:ansible 不同role对应不同的host

          本文链接:https://www.haomeiwen.com/subject/mwasvltx.html