blob: 6bf07e3c6192ebfda2c1fe8dd72288b354b2ff84 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
- name: Generate oo_list_hosts group
hosts: localhost
connection: local
gather_facts: no
vars:
libvirt_uri: 'qemu:///system'
tasks:
- name: List VMs
virt:
command: list_vms
register: list_vms
- name: Collect MAC addresses of the VMs
shell: 'virsh -c {{ libvirt_uri }} dumpxml {{ item }} | xmllint --xpath "string(//domain/devices/interface/mac/@address)" -'
register: scratch_mac
with_items: '{{ list_vms.list_vms }}'
when: item|truncate(cluster_id|length+1, True) == '{{ cluster_id }}-...'
- name: Collect IP addresses of the VMs
shell: "awk '/{{ item.stdout }}/ {print $1}' /proc/net/arp"
register: scratch_ip
with_items: '{{ scratch_mac.results }}'
when: item.skipped is not defined
- name: Add hosts
add_host:
hostname: '{{ item[0] }}'
ansible_ssh_host: '{{ item[1].stdout }}'
ansible_ssh_user: root
groups: oo_list_hosts
with_together:
- '{{ list_vms.list_vms }}'
- '{{ scratch_ip.results }}'
when: item[1].skipped is not defined
- name: List Hosts
hosts: oo_list_hosts
tasks:
- debug:
msg: 'public:{{ansible_default_ipv4.address}} private:{{ansible_default_ipv4.address}}'
|