Skip to content

Commit

Permalink
Merge pull request #1 from devan555/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
devan555 authored May 23, 2024
2 parents 89a8f49 + 3576cc2 commit aff87c1
Show file tree
Hide file tree
Showing 7 changed files with 171 additions and 0 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/containerlab-actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Containerlab test case execution
run-name: ${{ github.actor }} is running the Containerlab Action
on: [push]
jobs:
containerlab-testcase-execution:
runs-on: self-hosted
steps:
- uses: actions/checkout@v4
# - run: echo "REPO_NAME=${{ github.event.repository.name }}"

- name: Deploy devices in Containerlab and run the Playbook
run: ansible-playbook containerlab_test/deploy_containerlab.yml -i containerlab_test/ansible-inventory.yml

- name: Run the testcase1 on the Containerlab Devices
run: ansible-playbook containerlab_test/test_case1.yml -i containerlab_test/ansible-inventory.yml

- name: Destroy the Containerlab
if: always()
run: ansible-playbook containerlab_test/destroy_containerlab.yml
20 changes: 20 additions & 0 deletions containerlab_test/ansible-inventory.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
all:
children:
ceos:
vars:
ansible_become: 'true'
ansible_become_method: enable
ansible_become_password: admin
ansible_connection: ansible.netcommon.network_cli
ansible_network_os: eos
ansible_password: admin
ansible_user: admin
children:
group01:
hosts:
ceos1:
ansible_host: localhost
ansible_port: 23001
ceos2:
ansible_host: localhost
ansible_port: 23002
30 changes: 30 additions & 0 deletions containerlab_test/deploy_containerlab.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
- name: Run CLAB
hosts: localhost
become: yes
become_method: sudo
gather_facts: false
vars:
ansible_become_password: password
topology_file: /home/user1/actions-runner/_work/ceos_config/ceos_config/containerlab_test/topology.clab.yaml --reconfigure
tasks:

- name: Execute deploy
local_action: command sudo containerlab deploy --topo {{ topology_file }}
become: yes
register: deploy_out

- debug: msg="{{ deploy_out.stdout_lines }}"

- name: Wait for device01 to bootup
ansible.builtin.wait_for:
port: 23001
delay: 15

- name: Wait for device02 to bootup
ansible.builtin.wait_for:
port: 23002
delay: 15

- name: Import cEOS Playbook
ansible.builtin.import_playbook: "/home/user1/actions-runner/_work/ceos_config/ceos_config/playbook.yml"
33 changes: 33 additions & 0 deletions containerlab_test/destroy_containerlab.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
- name: Run CLAB
hosts: localhost
become: yes
become_method: sudo
gather_facts: false
vars:
ansible_become_password: password
topology_file: /home/user1/actions-runner/_work/ceos_config/ceos_config/containerlab_test/topology.clab.yaml
tasks:
- name: Execute destroy
local_action: command sudo containerlab destroy --topo {{ topology_file }}
become: yes
register: destroy_out
ignore_errors: true

- debug: msg="{{ destroy_out }}"
- name: Wait for 5 sec
wait_for:
timeout: 5

- name: Delete container file
local_action: command sudo rm -rf /home/user1/actions-runner/_work/ceos_config/ceos_config/containerlab_test/clab-ceos_simple/
become: yes
ignore_errors: true
register: delete_dir

# - debug: msg="{{ delete_dir }}"

# - name: Delete dir
# file:
# path: containerlab_test/clab-ceos_simple
# state: absent
25 changes: 25 additions & 0 deletions containerlab_test/test_case1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
- name: cEOS Config
hosts: ceos
gather_facts: no
tasks:
- name: Retrieve VLAN configuration
eos_command:
commands: show vlan
register: vlan_output

- name: Print output
debug: msg="{{ vlan_output.stdout[0] }}"
- name: Check if specific VLAN is present
set_fact:
vlan_present: "{{ 'VLAN0010' in vlan_output.stdout[0] }}"

- name: Fail if VLAN is not present
fail:
msg: "VLAN 10 is not present on the switch."
when: not vlan_present

- name: Debug message if VLAN is present
debug:
msg: "VLAN 10 is present on the switch."
when: vlan_present
16 changes: 16 additions & 0 deletions containerlab_test/topology.clab.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: ceos_simple
topology:
nodes:
ceos1:
kind: ceos
image: ceos:4.30.5M
ports:
- 23001:22
ceos2:
kind: ceos
image: ceos:4.30.5M
ports:
- 23002:22

links:
- endpoints: ["ceos1:eth1", "ceos2:eth1"]
28 changes: 28 additions & 0 deletions playbook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
- name: cEOS Config
hosts: ceos
gather_facts: yes
tasks:
- name: Print Device Facts
debug:
msg: "{{ ansible_facts }}"

- name: Configure VLAN 10
arista.eos.eos_vlans:
config:
- vlan_id: 10
state: active
register: vlan_conf

- name: Print VLAN Conf output
ansible.builtin.debug:
msg: "{{ vlan_conf }}"

- name: Gather VLAN config
arista.eos.eos_vlans:
state: gathered
register: gathered_vlan

- name: Print Gathered VLAN
ansible.builtin.debug:
msg: "{{ gathered_vlan }}"

0 comments on commit aff87c1

Please sign in to comment.