ansible/tasks/virt_instance_create.yml

51 lines
1.6 KiB
YAML
Raw Normal View History

2014-07-07 17:17:39 +00:00
#
# This task is the thing that creates a vm for later use
#
2014-07-07 17:17:39 +00:00
- name: get vm list
2013-11-25 18:37:51 +00:00
delegate_to: "{{ vmhost }}"
virt: command=list_vms
register: result
always_run: yes
2014-07-07 17:17:39 +00:00
- name: ensure the lv for the guest is made
2013-11-25 18:33:35 +00:00
lvol: lv={{ inventory_hostname }} vg={{ volgroup }} size={{ lvm_size }} state=present
2013-11-25 18:37:51 +00:00
delegate_to: "{{ vmhost }}"
when: inventory_hostname not in result.list_vms
2014-07-07 17:17:39 +00:00
- name: run the virt-install
2013-11-25 18:33:35 +00:00
shell: "{{ virt_install_command }}"
2013-11-25 18:37:51 +00:00
delegate_to: "{{ vmhost }}"
when: inventory_hostname not in result.list_vms
2014-07-07 17:17:39 +00:00
- name: wait for the install to finish
virt: command=status name={{ inventory_hostname }}
register: vmstatus
until: vmstatus.status == 'shutdown'
2013-11-25 18:37:51 +00:00
delegate_to: "{{ vmhost }}"
2014-07-19 23:41:52 +00:00
retries: 1500
delay: 10
2013-06-11 16:46:07 +00:00
when: inventory_hostname not in result.list_vms
2014-07-07 17:17:39 +00:00
- name: start the vm up
2013-11-25 18:33:35 +00:00
action: virt state=running name={{ inventory_hostname }}
2013-11-25 18:37:51 +00:00
delegate_to: "{{ vmhost }}"
2013-06-11 16:46:07 +00:00
when: inventory_hostname not in result.list_vms
2014-07-07 17:17:39 +00:00
- name: set it to autostart
action: virt command=autostart name={{ inventory_hostname }}
delegate_to: "{{ vmhost }}"
when: inventory_hostname not in result.list_vms
- name: make sure there is no old ssh host key for the host still around
local_action: known_hosts path={{item}} host={{ inventory_hostname }} state=absent
ignore_errors: True
with_items:
- /root/.ssh/known_hosts
- /etc/ssh/ssh_known_hosts
when: inventory_hostname not in result.list_vms
- name: wait for ssh on the vm to start back
2013-11-25 18:33:35 +00:00
local_action: wait_for delay=10 host={{ inventory_hostname }} port=22 state=started timeout=1200
2013-06-11 16:46:07 +00:00
when: inventory_hostname not in result.list_vms