64a48727770b2297b2fd5b1699756cc658ee237f
[csit.git] / resources / tools / vagrant / ansible / roles / csit / tasks / main.yml
1 ---
2 # file: csit/tasks/main.yml
3
4 # TODO: Temporarily disabling due to Centos8 not having netplan.
5 #       Finding better solution via udev requires some work and testing.
6 #- name: Upload config to rename network interfaces
7 #  copy:
8 #    src: 'files/99-vppdevice.yaml'
9 #    dest: '/etc/netplan/99-vppdevice.yaml'
10 #    owner: 'root'
11 #    group: 'root'
12 #    mode: 0644
13 #- name: Apply network config changes
14 #  command: '/usr/sbin/netplan apply'
15
16 - name: Centos8 install epel repositories
17   dnf:
18     name:
19       - 'epel-release'
20   when:
21     - ansible_distribution|lower == 'centos'
22
23 - name: Centos8 enable epel repositories
24   command: 'dnf config-manager --set-enabled PowerTools'
25   when:
26     - ansible_distribution|lower == 'centos'
27
28 - name: Install required system tools and packages
29   package:
30     name: "{{ csit_packages | join(',') }}"
31     state: 'latest'
32     update_cache: 'yes'
33
34 - name: Adjust number of hugepages
35   sysctl:
36     name: 'vm.nr_hugepages'
37     value: '512'
38     state: 'present'
39     sysctl_file: '/etc/sysctl.d/90-csit.conf'
40     reload: 'yes'
41
42 - name: Install docker-ce
43   command: |
44       curl -fsSL https://get.docker.com -o get-docker.sh &&
45       sudo sh get-docker.sh
46
47 - name: "Add user for running tests: {{ csit.test_user.name }}"
48   user:
49     name: '{{ csit.test_user.name }}'
50     password: '{{ csit.test_user.password }}'
51     home: '{{ csit.test_user.home }}'
52     shell: '{{ csit.test_user.shell }}'
53
54 - name: "Allow passwordless sudo for user: {{ csit.test_user.name }}"
55   lineinfile:
56     path: '/etc/sudoers.d/{{ csit.test_user.name }}'
57     line: '{{ csit.test_user.name }} ALL=(ALL) NOPASSWD:ALL'
58     create: 'yes'
59
60 - name: Add vagrant user to docker group
61   user:
62     name: 'vagrant'
63     groups:
64       - 'docker'
65
66 - name: Reload groups for current session
67   command: '/usr/bin/newgrp docker'
68
69 - name: Load required kernel modules
70   modprobe:
71     name: '{{ item }}'
72     state: 'present'
73   with_items:
74     - vfio-pci
75
76 - name: Enable required kernel modules on boot
77   lineinfile:
78     path: '/etc/modules'
79     line: '{{ item }}'
80     create: 'yes'
81     state: 'present'
82     insertafter: EOF
83   with_items:
84     - vfio-pci
85
86 - name: Clone CSIT repository
87   become_user: vagrant
88   git:
89     repo: '{{ csit.repository.url }}'
90     dest: '{{ csit.home }}'
91     accept_hostkey: yes
92     version: '{{ csit.repository.version }}'
93
94 - name: Install and update pip and virtualenv
95   pip:
96     name:
97       - 'virtualenv'
98     state: 'latest'
99
100 - name: Prepare python virtual environmant for CSIT
101   become_user: vagrant
102   command: '/usr/bin/virtualenv --python=/usr/bin/python3 {{ csit.home }}/env'
103   args:
104     chdir: '{{ csit.home }}'
105     creates: '{{ csit.home }}/env/bin/activate'
106
107 - name: Install python dependencies (from {{ csit.home }}/requirements.txt)
108   become_user: vagrant
109   shell: |
110       source '{{ csit.home }}/env/bin/activate' &&
111       pip3 install --timeout 300 -r '{{ csit.home }}/requirements.txt'
112   args:
113     executable: '/bin/bash'
114
115 - name: Load csit docker image from local drive if it exists (/vagrant/csit-sut.tar)
116   shell: |
117     if [ -z "$(docker images -q `cat {{ csit.home }}/VPP_DEVICE_IMAGE`)" ] && [ -e /vagrant/csit-sut.tar ]; then
118       docker load -i /vagrant/csit-sut.tar;
119     fi;
120   ignore_errors: yes