Filter hosts based on facts

Hi,
can humbly ask someone to provide me some example how to filter list of servers with facts ? I probably miss something in documentation, I need something like this:

ansible -i /usr/local/src/ansible/plugins/inventory/vmware.py ‘~web.*’ -m shell -a ‘filter=facter_operatingsystem_CentOS’ -a “some fancy command”

and in playbook this:

  • name: Test
    script: ./script.sh
    register: command_result
    failed_when: “‘FAILED’ in command_result.stdout”
    when: facter_operatingsystem|CentOS

Thanks a lot

Vasek

Hi Vasek

You can declare dynamic groups based on arbitrary facts, and then apply tasks or roles to those groups. There is an example at http://docs.ansible.com/playbooks_best_practices.html#operating-system-and-distribution-variance which seems to do exactly what you want.

Regards
Tom

Of course, this approach applies to playbooks. I’m not sure how to (best) accomplish this with the standalone ansible command.

Regards
Tom