Search code examples
ansibleansible-inventory

Ansible - How to match against hosts with certain bool variable?


Small context:

Certain hosts in my inventory need nginx access restriction. To achieve that I've implemented a bool restrict_access: yes and now I need to re-run my nginx setup role.

Is there a way to match only the hosts which have this flag set to true? Thanks!


Solution

  • you can implement that on the task level

    for example:

    # roles/webserver/tasks/main.yml  
    - import_tasks: configure-nginx.yml
      when: restrict_access
    
    - import_tasks: do-not-configure-nginx.yml
      when: not restrict_access