-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathinstall.yml
152 lines (118 loc) · 4.73 KB
/
install.yml
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
---
- name: Ugly workaround for delegate_to bug in Ansible v1.8.4
hosts: hypervisor
remote_user: root
gather_facts: no
tasks:
- setup:
- name: Create virtual images for Workshop
hosts: vm-noname
remote_user: root
gather_facts: no
vars:
os_name: centos
os_version: 6
os_arch: i386
centos_mirror: http://centos.cu.be/
image_dir: /var/lib/libvirt/images
tasks:
- name: Revoke old keys
command: ssh-keygen -R {{ ansible_ssh_host }}
transport: local
- name: Create temporary directory
command: mktemp -d /tmp/workshop.XXXXXXXXXX
transport: local
register: tempdir
- name: Template kickstart file
template: src=templates/ks-{{ os_name }}-{{ os_version }}.cfg dest={{ tempdir.stdout }}/ks.cfg
transport: local
- name: Template syslinux bootloader config
template: src=templates/isolinux.cfg dest={{ tempdir.stdout }}/isolinux.cfg
transport: local
- name: Download boot images
get_url: url={{ centos_mirror }}/{{ os_version }}/os/{{ os_arch }}/{{ item }} dest={{ tempdir.stdout }}
transport: local
with_items:
- images/pxeboot/vmlinuz
- images/pxeboot/initrd.img
- isolinux/isolinux.bin
- name: Create ISO boot image
command: mkisofs -r -N -allow-leading-dots -d -J -T -b isolinux.bin -c boot.cat -no-emul-boot -V "Ansible workshop" -boot-load-size 4 -boot-info-table -o boot.iso {{ tempdir.stdout }}
transport: local
- name: Copy boot.iso to hypervisor
copy: src=boot.iso dest={{ image_dir }}/vm-noname.iso
delegate_to: hypervisor
- name: Template VM configuration
template: src=templates/vm.xml dest={{ tempdir.stdout }}/{{ inventory_hostname }}.xml
delegate_to: hypervisor
- name: Allocate storage
qemu_img: dest={{ image_dir }}/{{ inventory_hostname }}.qcow2 size=3072 format=qcow2
delegate_to: hypervisor
- name: Create the VM
virt_guest: guest={{ inventory_hostname }} src={{ tempdir.stdout }}/{{ inventory_hostname }}.xml
delegate_to: hypervisor
- name: Enable ip_forward on hypervisor
sysctl: name="net.ipv4.ip_forward" value=1 sysctl_set=yes
delegate_to: hypervisor
- name: Boot VM using boot ISO
virt_boot: guest={{ inventory_hostname }} boot=cdrom image={{ image_dir }}/vm-noname.iso
delegate_to: hypervisor
- name: Clean up temporary directory
file: dest={{ tempdir.stdout }} state=absent
transport: local
- name: Wait for the kickstart to finish
wait_for: host={{ ansible_ssh_host }} port=22 state=started timeout=600
delegate_to: hypervisor
- name: Configure CentOS mirror
template: src=templates/etc/yum.repos.d/CentOS-Base.repo dest=/etc/yum.repos.d/
- name: Install EPEL
shell: rpm -ivh http://epel.mirror.nucleus.be/{{ os_version }}/{{ os_arch }}/epel-release-6-8.noarch.rpm
- name: Install packages
yum: pkg={{ item }} enablerepo=epel-testing state=installed
with_items:
- ansible
- git
# - name: Update system
# yum: pkg=* state=latest
- name: Clone the workshop repository
git: repo=https://github.com/ansible-provisioning/workshop-deployment-participant.git
dest=/root/workshop
- name: Clone the complete workshop repository
git: repo=https://github.com/ansible-provisioning/ansible-workshop-v2.git
dest=/root/complete
- name: Copy SSH key to root
copy: src=ssh-keys/id_rsa.workshop dest=/root/.ssh/id_rsa mode=0600
- name: Configure DHCP
copy: src=templates/etc/sysconfig/network-scripts/ifcfg-eth0
dest=/etc/sysconfig/network-scripts/ifcfg-eth0
mode=0644
- name: Remove persistent udev rules
copy: src=templates/etc/udev/rules.d/70-persistent-net.rules
dest=/etc/udev/rules.d/70-persistent-net.rules
mode=0644
- name: Disable persistent udev rules generator
file: src=/dev/null
dest=/etc/udev/rules.d/75-persistent-net-generator.rules
state=link
mode=0644
- name: Copy Workshop configurator
copy: src=workshop-config
dest=/sbin/workshop-config
mode=0755
- name: Configure Workshop configurator
copy: src=templates/etc/init/workshop.conf
dest=/etc/init/workshop.conf
mode=0644
- name: Shut down system
file: dest=/tmp/poweroff-ready state=touch
- name: Wait for the system to shut down
wait_for: host={{ ansible_ssh_host }} port=22 state=stopped
delegate_to: hypervisor
- name: Grace time for poweroff
pause: seconds=10
- name: Download VM Qcow2 image
fetch: src={{ image_dir }}/{{ inventory_hostname }}.qcow2 dest={{ inventory_hostname }}.qcow2.img flat=yes
delegate_to: hypervisor
- name: Convert Qcow2 image to VMDK
command: qemu-img convert -f qcow2 -O vmdk {{ inventory_hostname}}.qcow2.img {{ inventory_hostname}}.vmdk.img
transport: local