Add vagrant setup for testing VPP device locally
[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       - wget
19       - curl
20       - python-pip
21       - virtualenv
22       - libpcap-dev
23     state: present
24
25 - name: Adjust number of hugepages
26   sysctl:
27     name: vm.nr_hugepages
28     value: 512
29     state: present
30     sysctl_file: /etc/sysctl.d/90-csit.conf
31     reload: yes
32
33 - name: Add an Apt signing key, for docker-ce repository
34   apt_key:
35     url: https://download.docker.com/linux/ubuntu/gpg
36     state: present
37
38 - name: Add docker-ce apt repository if not present
39   apt_repository:
40     repo: "deb https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} stable"
41     state: present
42
43 - name: Install docker-ce if it's not already installed
44   apt:
45     name: docker-ce
46     state: present
47
48 - name: "Add user for running tests: {{ csit.test_user.name }}"
49   user:
50     name: "{{ csit.test_user.name }}"
51     password: "{{ csit.test_user.password }}"
52     home: "{{ csit.test_user.home }}"
53     shell: "{{ csit.test_user.shell }}"
54
55 - name: "Allow passwordless sudo for user: {{ csit.test_user.name }}"
56   lineinfile:
57     path: "/etc/sudoers.d/{{ csit.test_user.name }}"
58     line: "{{ csit.test_user.name }} ALL=(ALL) NOPASSWD:ALL"
59     create: yes
60
61 - name: Add vagrant user to docker group
62   user:
63     name: vagrant
64     groups:
65       - docker
66
67 - name: Reload groups for current session
68   command: /usr/bin/newgrp docker
69
70 - name: Load required kernel modules
71   modprobe:
72     name: "{{ item }}"
73     state: present
74   with_items:
75     - vfio-pci
76
77 - name: Enable required kernel modules on boot
78   lineinfile:
79     path: /etc/modules
80     line: "{{ item }}"
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   become_user: vagrant
96   pip:
97     name:
98       - pip
99       - virtualenv
100     state: latest
101
102 - name: Prepare python virtual environmant for CSIT
103   become_user: vagrant
104   command: "/usr/bin/virtualenv {{ csit.home }}/env"
105   args:
106     chdir: "{{ csit.home }}"
107     creates: "{{ csit.home }}/env/bin/activate"
108
109 - name: Install python dependencies (from {{ csit.home }}/requirements.txt)
110   become_user: vagrant
111   shell: source {{ csit.home }}/env/bin/activate && pip 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