Merge "Move VM image build to remote DUT"
[yardstick.git] / ansible / install.yaml
1 # Copyright (c) 2018-2019 Intel Corporation.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #      http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 ---
15 - hosts: jumphost
16   become: yes
17   vars:
18     virtual_environment: "{{ VIRTUAL_ENVIRONMENT | default(False) }}"
19     nsb_dir: "{{ NSB_DIR | default('/opt/nsb_bin/') }}"
20
21   pre_tasks:
22
23     - name: Create NSB binaries directory, accessible to any user
24       file:
25         path: "{{ nsb_dir }}"
26         state: directory
27         owner: root
28         mode: 0777
29       when:
30         - installation_mode != inst_mode_container_pull
31
32   roles:
33     - add_repos_jumphost
34     - install_dependencies_jumphost
35     - { role: install_yardstick, when: installation_mode != inst_mode_container_pull }
36     - { role: configure_uwsgi, when: installation_mode != inst_mode_container_pull }
37     - { role: configure_nginx, when: installation_mode != inst_mode_container_pull }
38     - { role: configure_gui, when: installation_mode != inst_mode_container_pull }
39     - { role: download_trex, when: installation_mode != inst_mode_container_pull }
40     - { role: install_trex, when: installation_mode != inst_mode_container_pull }
41     - role: configure_rabbitmq
42       install_mode: "{{ installation_mode }}"
43
44
45   post_tasks:
46
47     - service:
48         name: nginx
49         state: restarted
50       when: installation_mode == inst_mode_baremetal
51
52     - shell: uwsgi -i /etc/yardstick/yardstick.ini
53       when: installation_mode == inst_mode_baremetal
54
55
56 - name: Prepare baremetal and standalone servers
57   hosts: yardstick-baremetal,yardstick-standalone
58   become: yes
59   vars_files:
60     - roles/download_dpdk/defaults/main.yml
61   environment: "{{ proxy_env }}"
62
63   roles:
64     - add_custom_repos
65     - role: set_package_installer_proxy
66       when: proxy_env is defined and proxy_env
67     # can't update grub in chroot/docker
68     - enable_hugepages_on_boot
69     - enable_iommu_on_boot
70     - enable_cpu_isolation_on_boot
71     # needed for collectd plugins
72     - increase_open_file_limits
73     - install_image_dependencies
74     - role: download_dpdk
75       dpdk_version: "{{ dpdk_version_for_PROX }}"
76     - role: install_dpdk
77       dpdk_version: "{{ dpdk_version_for_PROX }}"
78     - download_samplevnfs
79     - role: install_samplevnf
80       vnf_name: PROX
81     - download_dpdk
82     - install_dpdk
83     - download_trex
84     - install_trex
85     - download_civetweb
86     - install_civetweb
87     - role: install_samplevnf
88       vnf_name: UDP_Replay
89     - role: install_samplevnf
90       vnf_name: ACL
91     - role: install_samplevnf
92       vnf_name: FW
93     - role: install_samplevnf
94       vnf_name: CGNAPT
95     # build shared DPDK for collectd only, required DPDK downloaded already
96     - install_dpdk_shared
97     - install_rabbitmq
98     - download_intel_cmt_cat
99     - install_intel_cmt_cat
100     - download_pmu_tools
101     - install_pmu_tools
102     - download_collectd
103     - install_collectd
104     - docker
105     - barometer_collectd
106
107 - name: Prepare to build VM
108   hosts: yardstick-standalone
109   become: yes
110   vars:
111     img_prop_item: "{{ IMG_PROPERTY }}"
112     img_arch: "{{ YARD_IMG_ARCH }}"
113   environment: "{{ proxy_env }}"
114
115   tasks:
116     - file:
117         dest: /tmp/ansible
118         state: directory
119         mode: 0755
120
121     - name: Copy ansible folder to remote DUT
122       copy:
123         src: "."
124         dest: /tmp/ansible
125
126     - name: Install DUT related packages
127       apt:
128         name: "{{ packages }}"
129       vars:
130         packages:
131         - qemu-kvm
132         - libvirt-bin
133         - bridge-utils
134         - fping
135         - genisoimage
136
137     # There is a bug with the easy install ansible module in Ubuntu 16.04 linux.
138     # Refer https://github.com/ansible/ansible/issues/23534
139     - name: Install pip
140       shell: easy_install -U pip
141       when:
142         - ansible_distribution == 'Ubuntu'
143         - ansible_distribution_major_version|int <= 16
144
145     - name: Install python-pip
146       action: "{{ ansible_pkg_mgr }} name=python-pip state=present"
147       when:
148         - ansible_distribution == 'Ubuntu'
149         - ansible_distribution_major_version|int >= 17
150
151     - name: Update pip ansible docker
152       pip:
153         name: "ansible==2.5.5"
154
155     # This is used as workaround as ansible doesn't support chroot on remote server
156     - name: Run ansible on remote
157       shell: "ansible-playbook -e OS_RELEASE={{ OS_RELEASE  }} -e IMAGE_PROPERTY={{ IMAGE_PROPERTY }} -e YARD_IMAGE_ARCH={{ YARD_IMAGE_ARCH }} -i install-inventory.ini build_vm.yml -vv"
158       args:
159         chdir: "/tmp/ansible"
160
161
162 - name: Add OpenStack variables, image
163   hosts: jumphost
164   vars:
165     openrc_flag: false
166   vars_files:
167     - yardstick_config.yml
168
169   pre_tasks:
170     - name: Get information about external VM image
171       stat:
172         path: "{{ path_to_img }}"
173       register: image_file_stat
174       when:
175         - path_to_img is defined
176         - imgfile is not defined
177
178     - set_fact:
179         imgfile: "{{ path_to_img }}"
180       when:
181         - path_to_img is defined
182         - imgfile is not defined
183         - image_file_stat.stat.islnk is defined
184         - not image_file_stat.stat.islnk
185
186     - set_fact:
187         openrc_flag: true
188       when:
189         - openrc_file is defined
190         - imgfile is defined
191
192   roles:
193     - { role: convert_openrc, when: openrc_file is defined }
194     - { role: clean_images, when: openrc_flag }
195     - { role: clean_flavors, when: openrc_flag }
196     - { role: create_samplevnfs_image, when: openrc_flag }
197   environment:
198     "{{ openrc | default({}) }}"
199
200
201 - name: Start yardstick container on jumphost
202   hosts: jumphost
203
204   tasks:
205     - name: Install docker needed to pull Yardstick container
206       include_role:
207         name: docker
208       when: installation_mode == inst_mode_container_pull
209
210     - name: Start yardstick container
211       docker_container:
212         name: yardstick
213         pull: yes
214         recreate: yes
215         image: "{{ yardstick_docker_image|default('opnfv/yardstick:latest') }}"
216         state: started
217         restart_policy: always
218         privileged: yes
219         interactive: yes
220         volumes:
221           - "{{ openrc_file|default('/dev/null') }}:/etc/yardstick/openstack.creds:ro"
222           - /var/run/docker.sock:/var/run/docker.sock
223           - /etc/localtime:/etc/localtime:ro
224       when: installation_mode == inst_mode_container_pull