Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a Ansible playbook for libvirt installation #8

Merged
merged 2 commits into from
May 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ Installing the tools:
* Within the **netsim-tools** directory, install PyYAML, Jinja2, netaddr and python-box Python libraries with **pip3 install -r requirements.txt**.
* Optional: install Ansible or use [ipSpace network automation container image](https://hub.docker.com/r/ipspace/automation). The tools were tested with Ansible 2.9 and 2.10.

Alternatively, there is a playbook called **install.libvirt** available for installation (tested on a Ubuntu 20.04 virtual machine) which you can use as follows:
```bash
$ ansible-playbook install.libvirt --ask-become
```
This does all of the following things:
- Set up all the dependencies required to use the *libvirt* Vagrant backend (including the *vagrant-libvirt* plugin)
- Configure the *vagrant-libvirt* network
- Clone the `netsim-tools` repository and assigns permissions to the current user
- Instantiate a new virtual Python environment and install the Python dependencies into it

## Building Your Lab

The current version of the **config-generate** tool contains templates needed to create a Vagrant topology containing Cisco IOSv, Cisco CSR 1000v, Cisco Nexus 9300v, and Arista vEOS devices with *vagrant-libvirt* or *virtualbox* provider. The tool also supports container-based network operating systems powered by *containerlab*.
Expand Down
61 changes: 61 additions & 0 deletions install.libvirt
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
- name: Install netsim-tools and dependencies for libvirt provider
hosts: localhost
connection: local
vars:
plugin_file: "{{ lookup('file','~/.vagrant.d/plugins.json', errors=False) | from_json }}"
clone_to: /opt/netsim-tools
vagrant_libvirt_version: 0.4.1
netsim_tools_version: release_0.6.1
vagrant_libvirt_installed: "{{ plugin_file.installed.vagrant_libvirt is not defined or plugin_file.installed.vagrant_libvirt.gem_version != vagrant_libvirt_version }}"
tasks:
- name: Install apt dependencies
apt:
pkg:
- libvirt-dev
- qemu-kvm
- vagrant
- virtinst
- ruby-libvirt
- qemu
- libvirt-daemon-system
- libvirt-clients
- ebtables
- dnsmasq-base
- libxslt-dev
- libxml2-dev
- zlib1g-dev
- ruby-dev
- python3-venv
- sshpass
- jq
become: yes
- name: Install vagrant-libvirt Vagrant plugin
shell: "vagrant plugin install vagrant-libvirt --plugin-version={{ vagrant_libvirt_version }}"
when: not vagrant_libvirt_installed
- name: Clone netsim-tools
git:
repo: https://github.com/ipspace/netsim-tools.git
version: "{{ netsim_tools_version }}"
dest: "{{ clone_to }}"
become: yes
- name: Change owner of netsim-tools folder to current user
file:
path: "{{ clone_to }}"
owner: "{{ ansible_effective_user_id }}"
group: "{{ ansible_effective_group_id }}"
recurse: yes
become: yes
- name: Create a python virtual environment and install requirements
shell:
cmd: python3 -m venv venv
chdir: "{{ clone_to }}"
creates: "{{ clone_to }}/venv"
- name: Install requirements.txt
shell:
cmd: "{{ clone_to }}/venv/bin/pip install -r requirements.txt"
chdir: "{{ clone_to }}"
- name: Delete existing vagrant-libvirt network
shell: virsh net-undefine vagrant-libvirt && virsh net-destroy vagrant-libvirt
failed_when: False
- name: Add vagrant-libvirt virtual network from netsim-tools template
shell: "virsh net-define {{ clone_to + '/netsim/templates/provider/libvirt/vagrant-libvirt.xml' }}"