6f226fd54d6824975dd6928b972ede0573ace0e7
[csit.git] / resources / tools / vagrant / ansible / roles / csit / tasks / main.yml
1 ---
2 # file: csit/tasks/main.yml
3
4 # CentOS 8 specific
5 - name: CentOS - Install epel repositories
6   dnf:
7     name:
8       - 'epel-release'
9   when:
10     - ansible_distribution|lower == 'centos'
11
12 - name: CentOS - Enable PowerTools
13   command: >
14       dnf config-manager
15       --set-enabled PowerTools
16   when:
17     - ansible_distribution|lower == 'centos'
18
19 # NOTE: containerd.io >1.2.0-3 requirement disabled by RH
20 #       Unable to install current docker version as of now
21 #       Using docker-ce-3:18.09.1-3.el7
22 - name: CentOS - Add docker-ce repo
23   command: >
24       dnf config-manager
25       --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
26   when:
27     - ansible_distribution|lower == 'centos'
28
29 - name: CentOS - Install docker-ce
30   dnf:
31     name:
32       - 'docker-ce-3:18.09.1-3.el7'
33   when:
34     - ansible_distribution|lower == 'centos'
35
36 # Ubuntu specific
37 - name: Ubuntu - Add docker-ce GPG key
38   apt_key:
39     url: 'https://download.docker.com/linux/ubuntu/gpg'
40   when:
41     - ansible_distribution|lower == 'ubuntu'
42
43 - name: Ubuntu - Add docker-ce repo
44   apt_repository:
45     repo: 'deb https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} stable'
46     filename: 'docker'
47     mode: 644
48   when:
49       - ansible_distribution|lower == 'ubuntu'
50
51 - name: Ubuntu - Install docker-ce
52   apt:
53     name:
54       - 'docker-ce'
55       - 'containerd.io'
56       - 'docker-ce-cli'
57   when:
58     - ansible_distribution|lower == 'ubuntu'
59
60 # General
61 - name: Install required system tools and packages
62   package:
63     name: "{{ csit_packages | join(',') }}"
64     state: 'latest'
65     update_cache: 'yes'
66
67 - name: Adjust number of hugepages
68   sysctl:
69     name: 'vm.nr_hugepages'
70     value: '512'
71     state: 'present'
72     sysctl_file: '/etc/sysctl.d/90-csit.conf'
73     reload: 'yes'
74
75 - name: "Add user for running tests: {{ csit.test_user.name }}"
76   user:
77     name: '{{ csit.test_user.name }}'
78     password: '{{ csit.test_user.password }}'
79     home: '{{ csit.test_user.home }}'
80     shell: '{{ csit.test_user.shell }}'
81
82 - name: "Allow passwordless sudo for user: {{ csit.test_user.name }}"
83   lineinfile:
84     path: '/etc/sudoers.d/{{ csit.test_user.name }}'
85     line: '{{ csit.test_user.name }} ALL=(ALL) NOPASSWD:ALL'
86     create: 'yes'
87     mode: 660
88
89 - name: Add vagrant user to docker group
90   user:
91     name: 'vagrant'
92     groups:
93       - 'docker'
94
95 - name: Reload groups for current session
96   command: '/usr/bin/newgrp docker'
97
98 - name: Load required kernel modules
99   modprobe:
100     name: '{{ item }}'
101     state: 'present'
102   with_items:
103     - vfio-pci
104
105 - name: Enable required kernel modules on boot
106   lineinfile:
107     path: '/etc/modules'
108     line: '{{ item }}'
109     create: 'yes'
110     state: 'present'
111     insertafter: EOF
112   with_items:
113     - vfio-pci
114
115 - name: Clone CSIT repository
116   become_user: vagrant
117   git:
118     repo: '{{ csit.repository.url }}'
119     dest: '{{ csit.home }}'
120     accept_hostkey: yes
121     version: '{{ csit.repository.version }}'
122
123 - name: Prepare python virtual environmant for CSIT
124   become_user: vagrant
125   command: '/usr/bin/virtualenv --python=/usr/bin/python3 {{ csit.home }}/env'
126   args:
127     chdir: '{{ csit.home }}'
128     creates: '{{ csit.home }}/env/bin/activate'
129
130 - name: Install python dependencies (from {{ csit.home }}/requirements.txt)
131   become_user: vagrant
132   shell: |
133       source '{{ csit.home }}/env/bin/activate' &&
134       pip3 install --timeout 300 -r '{{ csit.home }}/requirements.txt'
135   args:
136     executable: '/bin/bash'
137
138 - name: Load csit docker image from local drive if it exists (/vagrant/csit-sut.tar)
139   shell: |
140     if [ -z "$(docker images -q `cat {{ csit.home }}/VPP_DEVICE_IMAGE`)" ] && [ -e /vagrant/csit-sut.tar ]; then
141       docker load -i /vagrant/csit-sut.tar;
142     fi;
143   ignore_errors: yes