diff --git a/ansible/eos.yml b/ansible/eos.yml new file mode 100644 index 00000000000..a07b94d5275 --- /dev/null +++ b/ansible/eos.yml @@ -0,0 +1,7 @@ +--- +# This Playbook would deploy to all the devices. + +- hosts: eos + gather_facts: no + roles: + - role: eos diff --git a/ansible/roles/eos/tasks/main.yml b/ansible/roles/eos/tasks/main.yml index 9ff055ed587..cbc735c87b1 100644 --- a/ansible/roles/eos/tasks/main.yml +++ b/ansible/roles/eos/tasks/main.yml @@ -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 @@ -13,4 +41,3 @@ when: configuration is defined notify: - Restart the box - diff --git a/ansible/testbed-cli.sh b/ansible/testbed-cli.sh index 8d3c2d9abf4..bde9f42cfa7 100755 --- a/ansible/testbed-cli.sh +++ b/ansible/testbed-cli.sh @@ -7,6 +7,7 @@ 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" @@ -14,6 +15,7 @@ function usage 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 @@ -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 @@ -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 diff --git a/ansible/testbed_add_vm_topology.yml b/ansible/testbed_add_vm_topology.yml index 8cdcc5d7d43..9a007467c05 100644 --- a/ansible/testbed_add_vm_topology.yml +++ b/ansible/testbed_add_vm_topology.yml @@ -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_') }} @@ -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