Run task only if host does not belong to a group

前端 未结 2 1198
耶瑟儿~
耶瑟儿~ 2021-01-30 06:09

I\'d like to able to run an ansible task only if the host of the current playbook does not belong to a certain group. In semi pseudo code:

- nam         


        
2条回答
  •  执笔经年
    2021-01-30 06:50

    You can set a control variable in vars files located in group_vars/ or directly in hosts file like this:

    [vagrant:vars]
    test_var=true
    
    [location-1]
    192.168.33.10 hostname=apollo
    
    [location-2]
    192.168.33.20 hostname=zeus
    
    [vagrant:children]
    location-1
    location-2
    

    And run tasks like this:

    - name: "test"
      command: "echo {{test_var}}"
      when: test_var is defined and test_var
    

提交回复
热议问题