Run task only if host does not belong to a group

前端 未结 2 1202
耶瑟儿~
耶瑟儿~ 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:29

    Here's another way to do this:

    - name: my command
      command: echo stuff
      when: "'groupname' not in group_names"
    

    group_names is a magic variable as documented here: https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html#accessing-information-about-other-hosts-with-magic-variables :

    group_names is a list (array) of all the groups the current host is in.

提交回复
热议问题