amtega.select_hostvars

Ansible Select Hostvars Role

This is an Ansible role that creates a fact containing a list or dictionary of host variables (hostvars) that match a specific name pattern and include certain defined attributes.

Role Variables

You can find all the default variables for this role in the file defaults/main.yml.

The role creates a fact using the name specified in the variable select_hostvars_query.fact_name, containing the list/dictionary of hostvars that meet the specified criteria.

Example Playbook

Here is an example playbook:

---

- hosts: all
  roles:
    - role: amtega.select_hostvars
      vars:
        select_hostvars_query:
          pattern: "ansible_devices"
          attributes:
            - dm-0
        fact_name: devices_facts

With this inventory:

---
all:
  hosts:
    localhost:
      ansible_connection: local
      ansible_devices_example:
        aaa: 1
      ansible_devices_test:
        bbb: 2

This will create the following fact:

---
devices_facts:
  aaa: 1
  bbb: 2

Testing

Testing is done using Molecule with Docker containers.

cd amtega.select_hostvars

molecule test --all

License

Copyright (C) 2022 AMTEGA - Xunta de Galicia

This role is free software: you can share and/or change it under the terms of:

GNU General Public License version 3, or (if you prefer) any later version; or the European Union Public License, either Version 1.2 or any later versions that will be approved by the European Commission.

This role is shared with the hope that it will be helpful, but it comes WITHOUT ANY WARRANTY; including any implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License or European Union Public License for more details.

Author Information

  • Juan Antonio Valiño García.
Informazioni sul progetto

Setup a fact with hostvars that match a query

Installa
ansible-galaxy install amtega.select_hostvars
Licenza
gpl-3.0
Download
11.5k
Proprietario
Agency for Technological Modernization of Galicia