2016-07-24 01:57:37 +02:00
|
|
|
#!/usr/bin/ansible-playbook
|
|
|
|
# localhost (aka 127.0.0.1) is the hypervisor (hard-coded)
|
|
|
|
|
|
|
|
- hosts: test-vms
|
|
|
|
#- hosts: local-test-vm.ffmwu.local
|
|
|
|
gather_facts: False
|
|
|
|
# remote_user: root
|
|
|
|
|
|
|
|
vars:
|
|
|
|
- vm_path: "{{ lookup('env','HOME') }}/tmp/ffmwu-loctevm"
|
|
|
|
|
|
|
|
tasks:
|
|
|
|
- name: ensure VM dir and vm image dir
|
2016-07-26 17:32:47 +02:00
|
|
|
file: path={{ vm_path }} state=directory mode=0755
|
2016-07-24 01:57:37 +02:00
|
|
|
delegate_to: 127.0.0.1 # local action
|
|
|
|
|
2016-08-31 15:51:14 +02:00
|
|
|
- name: remove old image file when asked to reset VM
|
|
|
|
file: path={{ vm_path }}/loctevm.img state=absent
|
|
|
|
when: vm_reset|default(False)
|
|
|
|
delegate_to: 127.0.0.1 # local action
|
|
|
|
|
2016-07-26 17:32:47 +02:00
|
|
|
- name: ensure image file # FIXME: change to rm + recreate
|
2016-08-12 00:39:25 +02:00
|
|
|
command: fallocate -l 5G {{ vm_path }}/loctevm.img # 15G? size?
|
2016-07-24 01:57:37 +02:00
|
|
|
args:
|
|
|
|
creates: "{{ vm_path }}/loctevm.img"
|
|
|
|
delegate_to: 127.0.0.1 # local action
|
|
|
|
|
2016-07-26 17:32:47 +02:00
|
|
|
- name: correct access rights of image file
|
|
|
|
file: mode=0666 path={{ vm_path }}/loctevm.img state=file
|
|
|
|
delegate_to: 127.0.0.1 # local action
|
|
|
|
|
2016-07-24 01:57:37 +02:00
|
|
|
- name: get and prepare debian image file
|
2016-12-07 15:30:52 +01:00
|
|
|
include: include/loctevm-provide-iso.inc.yml
|
2016-07-24 01:57:37 +02:00
|
|
|
|
2016-08-06 02:12:55 +02:00
|
|
|
- name: define Vnd activate Vnet (if not already)
|
2016-12-07 15:30:52 +01:00
|
|
|
include: include/loctevm-provide-net.inc.yml
|
2016-08-06 02:12:55 +02:00
|
|
|
|
2016-07-26 17:32:47 +02:00
|
|
|
- name: define VM (if not already)
|
2016-12-07 15:30:52 +01:00
|
|
|
include: include/loctevm-provide-vm.inc.yml
|
2016-07-26 17:32:47 +02:00
|
|
|
|
2016-08-31 15:51:14 +02:00
|
|
|
- name: create VM - should start OS installation - might take looong time
|
2016-07-24 01:57:37 +02:00
|
|
|
virt:
|
|
|
|
state: running
|
|
|
|
name: "{{ inventory_hostname }}"
|
2016-08-31 15:51:14 +02:00
|
|
|
register: virt_run
|
2016-07-24 01:57:37 +02:00
|
|
|
delegate_to: 127.0.0.1 # local action
|
2016-07-26 17:32:47 +02:00
|
|
|
|
2016-08-06 02:12:55 +02:00
|
|
|
- name: wait for port 80 to appear (after reboot after OS installation)
|
2016-08-31 12:15:31 +02:00
|
|
|
wait_for: host={{ansible_host}} port=80 state=started timeout=2500
|
2016-08-06 02:12:55 +02:00
|
|
|
delegate_to: 127.0.0.1 # local action
|
|
|
|
|
2016-08-31 15:51:14 +02:00
|
|
|
- block:
|
|
|
|
- name: ensure absence of outdated local known-hosts entry
|
|
|
|
known_hosts: host={{ansible_host}} state=absent
|
|
|
|
delegate_to: 127.0.0.1 # local action
|
|
|
|
|
|
|
|
- name: do dummy connect to ensure new local known host entry
|
|
|
|
command: ssh -o PasswordAuthentication=no -o StrictHostKeyChecking=no hein@{{ansible_host}} true
|
|
|
|
delegate_to: 127.0.0.1 # local action
|
|
|
|
changed_when: False
|
|
|
|
failed_when: False
|
|
|
|
|
|
|
|
when: virt_run.changed
|
|
|
|
# block end
|
|
|
|
|
2016-07-26 17:32:47 +02:00
|
|
|
- hosts: test-vms
|
|
|
|
remote_user: hein
|
2016-08-06 02:12:55 +02:00
|
|
|
gather_facts: False
|
2016-07-26 17:32:47 +02:00
|
|
|
# become: True
|
|
|
|
|
2016-08-06 02:12:55 +02:00
|
|
|
tasks:
|
2016-07-26 17:32:47 +02:00
|
|
|
- name: prepare VM (if not already)
|
2016-12-07 15:30:52 +01:00
|
|
|
include: include/loctevm-provide-prereq.inc.yml
|