Skip to content
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
7 changes: 7 additions & 0 deletions ansible/eos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
# This Playbook would deploy to all the devices.

- hosts: eos
gather_facts: no
roles:
- role: eos
29 changes: 28 additions & 1 deletion ansible/roles/eos/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
- name: Load topo variables
include_vars: "vars/topo_{{ topo }}.yml"

- name: Include server vars
include_vars: "{{ host_var_file }}"

- name: Find current server group
set_fact: current_server={{ group_names | extract_by_prefix('server_') }}

- name: Extract VM names from the inventory
set_fact: VM_hosts={{ groups[current_server] | filter_by_prefix('VM') }}

- name: Generate hostname for target VM
set_fact: hostname={{ VM_hosts | extract_hostname(topology['VMs'], VM_base, inventory_hostname) }}
when: topology['VMs'] is defined

- fail:
msg: "cannot find {{ inventory_hostname }} in the topology"
when: hostname == "hostname not found"

- name: Set properties list to default value, when properties are not defined
set_fact: properties_list=[]
when: configuration is not defined or configuration[hostname] is not defined or configuration[hostname]['properties'] is not defined

- name: Set properties list to values, when they're defined
set_fact: properties_list="{{ configuration[hostname]['properties'] }}"
when: configuration and configuration[hostname] and configuration[hostname]['properties'] is defined

- name: copy boot-config
copy: src=boot-config
dest=/mnt/flash/boot-config
Expand All @@ -13,4 +41,3 @@
when: configuration is defined
notify:
- Restart the box

15 changes: 15 additions & 0 deletions ansible/testbed-cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ function usage
echo "testbed-cli. Interface to testbeds"
echo "Usage : $0 { start-vms | stop-vms } server-name vault-password-file"
echo "Usage : $0 { add-topo | remove-topo | renumber-topo } topo-name vault-password-file"
echo "Usage : $0 { config-vm } topo-name vm-name vault-password-file"
echo "Usage : $0 { gen-mg | deploy-mg } topo-name vault-password-file"
echo
echo "To start VMs on a server: $0 start-vms 'server-name' ~/.password"
echo "To stop VMs on a server: $0 stop-vms 'server-name' ~/.password"
echo "To deploy a topology on a server: $0 add-topo 'topo-name' ~/.password"
echo "To remove a topology on a server: $0 remove-topo 'topo-name' ~/.password"
echo "To renumber a topology on a server: $0 renumber-topo 'topo-name' ~/.password" , where topo-name is target topology
echo "To configure a VM on a server: $0 config-vm 'topo-name' 'vm-name' ~/.password"
echo "To generate minigraph for DUT in a topology: $0 gen-mg 'topo-name' ~/.password"
echo "To deploy minigraph to DUT in a topology: $0 deploy-mg 'topo-name' ~/.password"
echo
Expand Down Expand Up @@ -129,6 +131,17 @@ function deploy_minigraph
echo Done
}

function config_vm
{
echo "Configure VM $2"

read_file $1

ansible-playbook -i veos eos.yml --vault-password-file="$3" -l "$2" -e topo="$topo" -e VM_base="$vm_base"

echo Done
}

if [ $# -lt 3 ]
then
usage
Expand All @@ -145,6 +158,8 @@ case "$1" in
;;
renumber-topo) renumber_topo $2 $3
;;
config-vm) config_vm $2 $3 $4
;;
gen-mg) generate_minigraph $2 $3
;;
deploy-mg) deploy_minigraph $2 $3
Expand Down
19 changes: 2 additions & 17 deletions ansible/testbed_add_vm_topology.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,12 @@
fail: msg="Define topo variable with -e topo=something"
when: topo is not defined or topo not in topologies

- name: Load topo variables
include_vars: "vars/topo_{{ topo }}.yml"

- name: Check that variable VM_base is defined
fail: msg="Define VM_base variable with -e VM_base=something"
when: VM_base is not defined

- name: Include server vars
include_vars: "{{ host_var_file }}"
- name: Load topo variables
include_vars: "vars/topo_{{ topo }}.yml"

- name: Find current server group
set_fact: current_server={{ group_names | extract_by_prefix('server_') }}
Expand All @@ -99,18 +96,6 @@
set_fact: VM_targets={{ VM_hosts | filter_vm_targets(topology['VMs'], VM_base) }}
when: topology['VMs'] is defined

- name: Generate hostname for target VM
set_fact: hostname={{ VM_hosts | extract_hostname(topology['VMs'], VM_base, inventory_hostname) }}
when: topology['VMs'] is defined

- name: Set properties list to default value, when properties are not defined
set_fact: properties_list=[]
when: configuration is not defined or configuration[hostname] is not defined or configuration[hostname]['properties'] is not defined

- name: Set properties list to values, when they're defined
set_fact: properties_list="{{ configuration[hostname]['properties'] }}"
when: configuration and configuration[hostname] and configuration[hostname]['properties'] is defined

roles:
- { role: eos, when: topology.VMs is defined and inventory_hostname in VM_targets } # role eos will be executed in any case, and when will evaluate with every task

Expand Down