[Python] How can I get a list of hosts from an Ansible inventory file?

Discussão em 'Python' iniciado por Stack, Fevereiro 20, 2025.

  1. Stack

    Stack Membro Participativo

    Is there a way to use the Ansible Python API to get a list of hosts from a given inventory file / group combination?

    For example, our inventory files are split up by service type:

    [dev:children]
    dev_a
    dev_b

    [dev_a]
    my.host.int.abc.com

    [dev_b]
    my.host.int.xyz.com


    [prod:children]
    prod_a
    prod_b

    [prod_a]
    my.host.abc.com

    [prod_b]
    my.host.xyz.com


    Can I use ansible.inventory in some way to pass in a specific inventory file, and the group I want to act on, and have it return a list of hosts that match?

    Continue reading...

Compartilhe esta Página