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