Vagrant-Ansible scripts for tutorial vm
Change-Id: I0481fa9c7df897812a765973440b6b1b2bf669f8
diff --git a/tools/dev/vagrant/ansible/roles/tutorial-common/tasks/main.yml b/tools/dev/vagrant/ansible/roles/tutorial-common/tasks/main.yml
new file mode 100644
index 0000000..a24be78
--- /dev/null
+++ b/tools/dev/vagrant/ansible/roles/tutorial-common/tasks/main.yml
@@ -0,0 +1,285 @@
+---
+#
+# Installs basic tutorial packages and configures common tutorial settings
+#
+- name: Downloading repo key
+ apt_key:
+ url: "{{ google_chrome_key_url }}"
+ state: present
+
+- name: Installing Google Chrome repo
+ apt_repository:
+ repo: "{{ google_chrome_repo }}"
+ state: present
+ filename: "google-chrome"
+
+- name: Installing Google Chrome
+ apt:
+ name: google-chrome-stable
+ force: yes
+ update_cache: yes
+
+- name: Creating reset scripts for 1 node cell
+ template:
+ src: templates/reset_one_node.j2
+ dest: "{{ reset_files[0] }}"
+ owner: ubuntu
+ group: ubuntu
+ mode: 0777
+
+- name: Creating reset scripts for 3 node cell
+ template:
+ src: templates/reset_three_node.j2
+ dest: "{{ reset_files[1] }}"
+ owner: ubuntu
+ group: ubuntu
+ mode: 0777
+
+- name: Creating tutorial users
+ user:
+ name: "{{ item.value.user }}"
+ groups: "wireshark"
+ append: yes
+ password: "{{ item.value.pass }}"
+ with_dict: "{{ tutorials }}"
+
+- name: Adding tutorial users to sudoers
+ lineinfile:
+ dest: "/etc/sudoers.d/{{ item.value.user }}"
+ line: "{{ item.value.user }} ALL=(ALL) NOPASSWD:ALL"
+ state: present
+ create: yes
+ with_dict: "{{ tutorials }}"
+
+- name: Creating .ssh folders
+ file:
+ path: "/home/{{ item.value.user }}/.ssh"
+ state: directory
+ owner: "{{ item.value.user }}"
+ group: "{{ item.value.user }}"
+ mode: 0700
+ with_dict: "{{ tutorials }}"
+
+- name: Copying .ssh keys
+ copy:
+ src: "/home/ubuntu/.ssh/id_rsa"
+ dest: "/home/{{ item.value.user }}/.ssh/id_rsa"
+ owner: "{{ item.value.user }}"
+ group: "{{ item.value.user }}"
+ mode: 0600
+ with_dict: "{{ tutorials }}"
+
+- name: Setting ONOS variables
+ blockinfile:
+ dest: "/home/{{ item.value.user }}/.bashrc"
+ create: yes
+ block: |
+ export ONOS_ROOT=/home/ubuntu/onos
+ export KARAF_ROOT=/home/ubuntu/Applications/apache-karaf-{{ karaf_version }}
+ export KARAF_TAR=/home/ubuntu/Applications/apache-karaf-{{ karaf_version }}.tar.gz
+ export M2_REPO=/home/ubuntu/.m2/repository
+ . /home/ubuntu/onos/tools/dev/bash_profile
+ cell {{ item.value.cell }} > /dev/null
+ with_dict: "{{ tutorials }}"
+
+- name: Creating .wireshark folders
+ file:
+ path: "/home/{{ item.value.user }}/{{ wireshark.plugins_dir }}"
+ state: directory
+ owner: "{{ item.value.user }}"
+ group: "{{ item.value.user }}"
+ mode: 0755
+ with_dict: "{{ tutorials }}"
+
+- name: Copying openflow.lua Wireshark plugin
+ copy:
+ src: "/home/ubuntu/openflow.lua"
+ dest: "/home/{{ item.value.user }}/{{ wireshark.plugins_dir }}"
+ owner: "{{ item.value.user }}"
+ group: "{{ item.value.user }}"
+ with_dict: "{{ tutorials }}"
+
+- name: Creating run_onos.sh script
+ template:
+ src: templates/run_onos.j2
+ dest: /home/ubuntu/run_onos.sh
+ owner: ubuntu
+ group: ubuntu
+ mode: 0777
+
+- name: Creating config Desktop folder
+ file:
+ path: "/home/{{ item.value.user }}/.config/pcmanfm/lubuntu/"
+ state: directory
+ owner: "{{ item.value.user }}"
+ group: "{{ item.value.user }}"
+ mode: 0777
+ with_dict: "{{ tutorials }}"
+
+- name: Loading ONOS Desktop background
+ template:
+ src: templates/gui_custom.j2
+ dest: "/home/{{ item.value.user }}/.config/pcmanfm/lubuntu/desktop-items-0.conf"
+ owner: "{{ item.value.user }}"
+ group: "{{ item.value.user }}"
+ mode: 0777
+ with_dict: "{{ tutorials }}"
+
+- name: Creating Desktop folders
+ file:
+ path: "/home/{{ item.value.user }}/Desktop"
+ state: directory
+ mode: 0755
+ with_dict: "{{ tutorials }}"
+
+- name: Creating ONOS CLI Desktop icons
+ blockinfile:
+ dest: "/home/{{ item.value.user }}/Desktop/ONOS CLI.desktop"
+ create: yes
+ owner: "{{ item.value.user }}"
+ group: "{{ item.value.user }}"
+ mode: 0777
+ block: |
+ [Desktop Entry]
+ Encoding=UTF-8
+ Type=Application
+ Name=ONOS
+ Name[en_US]=ONOS
+ Icon=konsole
+ Exec=/home/ubuntu/run_onos.sh
+ Comment[en_US]=
+ Terminal=true
+ X-KeepTerminal=true
+ with_dict: "{{ tutorials }}"
+
+- name: Creating Mininet Desktop icon
+ blockinfile:
+ dest: "/home/{{ item.value.user }}/Desktop/Mininet.desktop"
+ create: yes
+ owner: "{{ item.value.user }}"
+ group: "{{ item.value.user }}"
+ mode: 0777
+ block: |
+ [Desktop Entry]
+ Encoding=UTF-8
+ Type=Application
+ Name=Mininet
+ Name[en_US]=Mininet
+ Icon=konsole
+ Exec={{ item.value.mininet_exec }}
+ Comment[en_US]=
+ Terminal=true
+ X-KeepTerminal=true
+ with_dict: "{{ tutorials }}"
+
+- name: Creating Tutorial Desktop icons
+ blockinfile:
+ dest: "/home/{{ item.value.user }}/Desktop/Tutorial.desktop"
+ create: yes
+ owner: "{{ item.value.user }}"
+ group: "{{ item.value.user }}"
+ mode: 0777
+ block: |
+ [Desktop Entry]
+ Encoding=UTF-8
+ Type=Application
+ Name=ONOS Tutorial
+ Name[en_US]=ONOS Tutorial
+ Icon=internet-web-browser
+ Exec=/usr/bin/google-chrome-stable {{ item.value.url }}
+ Comment[en_US]=
+ with_dict: "{{ tutorials }}"
+
+- name: Creating GUI Desktop icons
+ blockinfile:
+ dest: "/home/{{ item.value.user }}/Desktop/ONOS GUI.desktop"
+ create: yes
+ owner: "{{ item.value.user }}"
+ group: "{{ item.value.user }}"
+ mode: 0777
+ block: |
+ [Desktop Entry]
+ Encoding=UTF-8
+ Type=Application
+ Name=ONOS GUI
+ Name[en_US]=ONOS GUI
+ Icon=internet-web-browser
+ Exec=/usr/bin/google-chrome-stable http://{{ lxc.lxc_one.ip }}:8181/onos/ui/index.html#topo
+ Comment[en_US]=
+ with_dict: "{{ tutorials }}"
+
+- name: Creating IntelliJ Desktop icons
+ blockinfile:
+ dest: "/home/{{ item.value.user }}/Desktop/IntelliJ.desktop"
+ create: yes
+ owner: "{{ item.value.user }}"
+ group: "{{ item.value.user }}"
+ mode: 0777
+ block: |
+ [Desktop Entry]
+ Encoding=UTF-8
+ Type=Application
+ Name=IntelliJ
+ Name[en_US]=IntelliJ
+ Icon=/home/ubuntu/{{ app_dir }}/{{ intellij.dir_name }}/bin/idea.png
+ Exec=/home/ubuntu/{{ app_dir }}/{{ intellij.dir_name }}/bin/idea.sh
+ Comment[en_US]=
+ with_dict: "{{ tutorials }}"
+
+- name: Creating Wireshark Desktop icons
+ blockinfile:
+ dest: "/home/{{ item.value.user }}/Desktop/Wireshark.desktop"
+ create: yes
+ owner: "{{ item.value.user }}"
+ group: "{{ item.value.user }}"
+ mode: 0777
+ block: |
+ [Desktop Entry]
+ Encoding=UTF-8
+ Type=Application
+ Name=Wireshark
+ Name[en_US]=Wireshark
+ Icon=wireshark
+ Exec=/usr/bin/wireshark
+ Comment[en_US]=
+ with_dict: "{{ tutorials }}"
+
+- name: Creating Terminal Desktop icon
+ blockinfile:
+ dest: "/home/{{ item.value.user }}/Desktop/Terminal.desktop"
+ create: yes
+ owner: "{{ item.value.user }}"
+ group: "{{ item.value.user }}"
+ mode: 0777
+ block: |
+ [Desktop Entry]
+ Encoding=UTF-8
+ Type=Application
+ Name=Terminal
+ Name[en_US]=Terminal
+ Icon=konsole
+ Exec=/bin/bash
+ Comment[en_US]=
+ Terminal=true
+ X-KeepTerminal=true
+ with_dict: "{{ tutorials }}"
+
+- name: Creating Reset Desktop icon
+ blockinfile:
+ dest: "/home/{{ item.value.user }}/Desktop/Reset.desktop"
+ create: yes
+ owner: "{{ item.value.user }}"
+ group: "{{ item.value.user }}"
+ mode: 0777
+ block: |
+ [Desktop Entry]
+ Encoding=UTF-8
+ Type=Application
+ Name=Reset
+ Name[en_US]=Reset
+ Icon=konsole
+ Exec={{ item.value.reset_exec }}
+ Comment[en_US]=
+ Terminal=true
+ X-KeepTerminal=true
+ with_dict: "{{ tutorials }}"
\ No newline at end of file
diff --git a/tools/dev/vagrant/ansible/roles/tutorial-common/templates/gui_custom.j2 b/tools/dev/vagrant/ansible/roles/tutorial-common/templates/gui_custom.j2
new file mode 100644
index 0000000..3e888d2
--- /dev/null
+++ b/tools/dev/vagrant/ansible/roles/tutorial-common/templates/gui_custom.j2
@@ -0,0 +1,15 @@
+[*]
+wallpaper_mode=center
+wallpaper_common=1
+wallpapers_configured=1
+wallpaper0=/usr/share/lubuntu/wallpapers/onos.png
+wallpaper=/usr/share/lubuntu/wallpapers/onos.png
+desktop_bg=#ffffff
+desktop_fg=#000000
+desktop_shadow=#000000
+desktop_font=Ubuntu 11
+show_wm_menu=0
+sort=mtime;ascending;
+show_documents=0
+show_trash=1
+show_mounts=1
\ No newline at end of file
diff --git a/tools/dev/vagrant/ansible/roles/tutorial-common/templates/reset_one_node.j2 b/tools/dev/vagrant/ansible/roles/tutorial-common/templates/reset_one_node.j2
new file mode 100644
index 0000000..1ab3b7a
--- /dev/null
+++ b/tools/dev/vagrant/ansible/roles/tutorial-common/templates/reset_one_node.j2
@@ -0,0 +1,25 @@
+#!/bin/bash
+
+sudo rm -rf /tmp/*
+
+export ONOS_ROOT=/home/ubuntu/onos
+export M2_REPO=/home/ubuntu/.m2/repository
+export KARAF_TAR=/home/ubuntu/{{ app_dir }}/apache-karaf-{{ karaf_version }}.tar.gz
+export KARAF_ROOT=/home/ubuntu/Applications/apache-karaf-{{ karaf_version }}
+source ${ONOS_ROOT}/tools/dev/bash_profile
+
+sudo mn -c
+
+sudo chmod -R 777 /home/ubuntu/onos
+sudo chmod -R 777 /home/ubuntu/.m2
+
+cell 3node
+onos-service --cell stop
+
+cell 1node
+
+if [ -n "$1" ]; then
+ export ONOS_APPS=$ONOS_APPS,$1
+fi
+
+onos-test
\ No newline at end of file
diff --git a/tools/dev/vagrant/ansible/roles/tutorial-common/templates/reset_three_node.j2 b/tools/dev/vagrant/ansible/roles/tutorial-common/templates/reset_three_node.j2
new file mode 100644
index 0000000..b6c5de5
--- /dev/null
+++ b/tools/dev/vagrant/ansible/roles/tutorial-common/templates/reset_three_node.j2
@@ -0,0 +1,22 @@
+#!/bin/bash
+
+sudo rm -rf /tmp/*
+
+export ONOS_ROOT=/home/ubuntu/onos
+export M2_REPO=/home/ubuntu/.m2/repository
+export KARAF_TAR=/home/ubuntu/{{ app_dir }}/apache-karaf-{{ karaf_version }}.tar.gz
+export KARAF_ROOT=/home/ubuntu/{{ app_dir }}/apache-karaf-{{ karaf_version }}
+source ${ONOS_ROOT}/tools/dev/bash_profile
+
+sudo mn -c
+
+sudo chmod -R 777 /home/ubuntu/onos
+sudo chmod -R 777 /home/ubuntu/.m2
+
+cell 3node
+
+if [ -n "$1" ]; then
+ export ONOS_APPS=$ONOS_APPS,$1
+fi
+
+onos-test
\ No newline at end of file
diff --git a/tools/dev/vagrant/ansible/roles/tutorial-common/templates/run_onos.j2 b/tools/dev/vagrant/ansible/roles/tutorial-common/templates/run_onos.j2
new file mode 100755
index 0000000..01265ae
--- /dev/null
+++ b/tools/dev/vagrant/ansible/roles/tutorial-common/templates/run_onos.j2
@@ -0,0 +1,11 @@
+#!/bin/bash
+
+export ONOS_ROOT=/home/ubuntu/onos
+export M2_REPO=/home/ubuntu/.m2/repository
+export KARAF_TAR=/home/ubuntu/"{{ app_dir }}"/apache-karaf-"{{ karaf_version }}".tar.gz
+export KARAF_ROOT=/home/ubuntu/"{{ app_dir }}"/apache-karaf-"{{ karaf_version }}"
+source ${ONOS_ROOT}/tools/dev/bash_profile
+
+cell 1node
+
+onos
\ No newline at end of file