Skip to content

Commit

Permalink
Create a Ansible playbook for libvirt installation (#8)
Browse files Browse the repository at this point in the history
* Create install.libvirt

Allow for installation of netsim-tools and dependencies for the libvirt provider with Ansible.

* Update install.md

Document installation via Ansible
  • Loading branch information
Kircheneer authored May 2, 2021
1 parent e3ab7ec commit d19631b
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
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' }}"

0 comments on commit d19631b

Please sign in to comment.