Ansible role which sets host variables useful when interacting with libvirt
The role presently supports one specific scenario:
- Given a list of domain names, find MAC addresses using Ansible's virt module.
- Query the virthost's ARP table with python_arptable to find domain IP addresses.
- Set facts/variables that can be used in subsequent roles/tasks (eg get IP for domain)
This is useful for the tripleo-quickstart project, an Ansible based project for setting up TripleO environments in openstack CI.
- python_arptable must be installed on the target machine
- libvirtd should be installed and running
- virtvars_node_list (input, required) list of libvirt domains
"virtvars_node_list": [
"tiny0",
"tiny2"
]
These variables are generated with set_fact, and can be used after invoking this role.
- virtvars_domain_list
"virtvars_domain_list": [
{
"domain": "tiny0",
"mac": "52:54:00:ee:d3:61"
},
{
"domain": "tiny2",
"mac": "52:54:00:2a:e5:c1"
}
]
- virtvars_mac_dict
"virtvars_mac_dict": {
"tiny0": "52:54:00:ee:d3:61",
"tiny2": "52:54:00:2a:e5:c1"
}
- virtvars_ip_dict
"virtvars_ip_dict": {
"tiny0": "192.168.122.249",
"tiny2": "192.168.122.44"
}
- No other galaxy roles are required.
- http://docs.ansible.com/ansible/latest/modules/virt_module.html
- https://docs.ansible.com/ansible/2.4/xml_module.html
- https://pypi.org/project/python_arptable
Run the following:
ANSIBLE_ROLES_PATH=../
ansible-playbook -i tests/inventory tests/local-test.yml
---
- hosts: localhost
gather_facts: no
connection: local
# note: this assumes these domains are created!
vars:
virtvars_node_list:
- tiny0
- tiny2
roles:
- ansible-role-virtvars
Travis CI definition: (.travis.yml)
Apache 2.0
Matt Young (@halcyondude)