From 2e8d14a5e0c1403f0aec9bcf784712572b954abd Mon Sep 17 00:00:00 2001 From: Kevin Fenzi Date: Fri, 20 Nov 2015 23:04:17 +0000 Subject: [PATCH] Add a playbook implementation of list-vm's per host --- files/virthost-lists.j2 | 6 ++++++ playbooks/list-vms-per-host.yml | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 files/virthost-lists.j2 create mode 100644 playbooks/list-vms-per-host.yml diff --git a/files/virthost-lists.j2 b/files/virthost-lists.j2 new file mode 100644 index 0000000000..8d13ecffda --- /dev/null +++ b/files/virthost-lists.j2 @@ -0,0 +1,6 @@ +{% for key, value in virt_info.items() %} +{% if value and 'state' in value %} +{{inventory_hostname}}:{{key}}:{{value['state']}}:{{value['autostart']}}:{{value['nrVirtCpu']}}:{{value['memory']}} +{% else %} +{% endif %} +{% endfor %} diff --git a/playbooks/list-vms-per-host.yml b/playbooks/list-vms-per-host.yml new file mode 100644 index 0000000000..a7e4ef4b7f --- /dev/null +++ b/playbooks/list-vms-per-host.yml @@ -0,0 +1,20 @@ +# +# This playbook runs once per hour on batcave01 and generates a list of vms on virthosts +# +--- +- hosts: virtservers + user: root + gather_facts: True + + vars_files: + - /srv/web/infra/ansible/vars/global.yml + - "/srv/private/ansible/vars.yml" + - "/srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml" + + tasks: + + - virt: command=info + register: virt_info + + - template: src={{files}}/virthost-lists.j2 dest=/tmp/virthost-lists.out + delegate_to: localhost