Ansible - how to control the order of the hosts when playbook is ran

前端 未结 2 1624
礼貌的吻别
礼貌的吻别 2021-02-09 13:17

Let\'s say that we have defined two machines in our inventory file:

[db-server-preprod] 172.16.0.1 172.16.0.2

If I run a playbook against this gr

2条回答
  •  盖世英雄少女心
    2021-02-09 13:41

    You may place your master host into separate group, then apply common role to all servers at once, then apply master-roles only to master server, and slave-roles to all servers except master using excluding pattern.

    Inventory:

    [all-servers]
    host1
    host2
    host3
    host4
    
    [master-server]
    host2
    

    Playbook:

    ---
    - hosts: all-servers
      gather_facts: no
      tasks:
        - debug: msg=role-common
    
    - hosts: master-server
      gather_facts: no
      tasks:
        - debug: msg=role-master
    
    - hosts: all-servers:!master-server
      gather_facts: no
      tasks:
        - debug: msg=role-slave
    

提交回复
热议问题