summaryrefslogtreecommitdiffstats
path: root/tasks/virt_instance_create.yml
blob: 0046e36abaf0a58eadac190d5d505f9565ab7ec3 (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#
# This task is the thing that creates a vm for later use
#

- name: get vm list
  delegate_to: "{{ vmhost }}"
  virt: command=list_vms
  register: result
  check_mode: no

- name: ensure the lv for the guest is made
  lvol: lv={{ inventory_hostname }} vg={{ volgroup }} size={{ lvm_size }} state=present
  delegate_to: "{{ vmhost }}"
  when: inventory_hostname not in result.list_vms

- name: run the virt-install
  shell: "{{ virt_install_command }}"
  delegate_to: "{{ vmhost }}"
  when: inventory_hostname not in result.list_vms

- name: wait for the install to finish
  virt: command=status name={{ inventory_hostname }}
  register: vmstatus
  until: vmstatus.status == 'shutdown'
  delegate_to: "{{ vmhost }}"
  retries: 1500
  delay: 10
  when: inventory_hostname not in result.list_vms

- name: ARMv7 copy the kernel out
  shell: "virt-builder --get-kernel {{ volgroup }}/{{ inventory_hostname }} --output /var/lib/libvirt/images/  | awk -F/ '{print $NF}' > /var/lib/libvirt/images/{{ inventory_hostname }}-details.txt"
  delegate_to: "{{ vmhost}}"
  when: inventory_hostname.startswith('buildvm-armv7') and ( inventory_hostname not in result.list_vms or armv7kernelupdate is defined )
  tags:
    - armv7-kernel

- name: ARMv7 extract the kernel details
  command: "head -n1 /var/lib/libvirt/images/{{ inventory_hostname }}-details.txt"
  delegate_to: "{{ vmhost}}"
  register: host_armv7kernel
  when: inventory_hostname.startswith('buildvm-armv7') and ( inventory_hostname not in result.list_vms or armv7kernelupdate is defined )
  tags:
    - armv7-kernel

- name: ARMv7 extract the initrd details
  command: "tail -n1 /var/lib/libvirt/images/{{ inventory_hostname }}-details.txt"
  delegate_to: "{{ vmhost}}"
  register: host_armv7initrd
  when: inventory_hostname.startswith('buildvm-armv7') and ( inventory_hostname not in result.list_vms or armv7kernelupdate is defined )
  tags:
    - armv7-kernel

- name: ARMv7 copy the cmdline out
  shell: "virt-cat -a {{ volgroup }}/{{ inventory_hostname }} /boot/extlinux/extlinux.conf | grep -m1 append | sed -e 's/append //'"
  delegate_to: "{{ vmhost}}"
  register: host_cmdline
  when: inventory_hostname.startswith('buildvm-armv7') and ( inventory_hostname not in result.list_vms or armv7kernelupdate is defined )
  tags:
    - armv7-kernel

- name: ARMv7 update the virt parameters
  virt_boot: domain={{ inventory_hostname }} kernel=/var/lib/libvirt/images/{{ host_armv7kernel.stdout }} initrd=/var/lib/libvirt/images/{{ host_armv7initrd.stdout }} cmdline={{ host_cmdline.stdout }}
  delegate_to: "{{ vmhost }}"
  when: inventory_hostname.startswith('buildvm-armv7') and ( inventory_hostname not in result.list_vms or armv7kernelupdate is defined )
  tags:
    - armv7-kernel

- name: start the vm up and set it to autostart
  virt: state=running name={{ inventory_hostname }} autostart=True
  delegate_to: "{{ vmhost }}"
  when: inventory_hostname not in result.list_vms

- name: ARMv7 pause while VM updates
  pause: seconds=5
  when: inventory_hostname.startswith('buildvm-armv7') and ( inventory_hostname not in result.list_vms or armv7kernelupdate is defined )
  tags:
    - armv7-kernel

- 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
  when: inventory_hostname not in result.list_vms

- name: (osbs-control01.stg) make sure there is no old ssh host key for the host still around
  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 and inventory_hostname in groups['osbs-masters-stg']+groups['osbs-nodes-stg']
  delegate_to: osbs-control01.stg.phx2.fedoraproject.org

- name: (osbs-control01) make sure there is no old ssh host key for the host still around
  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 and inventory_hostname in groups['osbs-masters']+groups['osbs-nodes']
  delegate_to: osbs-control01.phx2.fedoraproject.org

- name: wait for ssh on the vm to start back
  local_action: wait_for delay=10 host={{ inventory_hostname }} port=22 state=started timeout=1200
  when: inventory_hostname not in result.list_vms

- name: gather ssh host key from new instance
  local_action: command ssh-keyscan -t rsa {{ inventory_hostname }}
  ignore_errors: True
  register: hostkey
  when: inventory_hostname not in result.list_vms

- name: add new ssh host key (until we can sign it)
  local_action: known_hosts path={{item}} key="{{ hostkey.stdout }}" host={{ inventory_hostname }} state=present
  ignore_errors: True
  with_items:
  - /root/.ssh/known_hosts
  when: inventory_hostname not in result.list_vms

- name: (osbs-control01.stg) add new ssh host key
  known_hosts: path={{item}} key="{{ hostkey.stdout }}" host={{ inventory_hostname }} state=present
  ignore_errors: True
  with_items:
  - /root/.ssh/known_hosts
  - /etc/ssh/ssh_known_hosts
  when: inventory_hostname not in result.list_vms and inventory_hostname in groups['osbs-masters-stg']+groups['osbs-nodes-stg']
  delegate_to: osbs-control01.stg.phx2.fedoraproject.org

- name: (osbs-control01) add new ssh host key
  known_hosts: path={{item}} key="{{ hostkey.stdout }}" host={{ inventory_hostname }} state=present
  ignore_errors: True
  with_items:
  - /root/.ssh/known_hosts
  - /etc/ssh/ssh_known_hosts
  when: inventory_hostname not in result.list_vms and inventory_hostname in groups['osbs-masters']+groups['osbs-nodes']
  delegate_to: osbs-control01.phx2.fedoraproject.org