This example shows how to configure a hostname and create VLANs for a leaf-spine fabric by using the os10_config
module.
Home > Networking Solutions > Enterprise/Data Center Networking Solutions > SmartFabric OS10 Networking Solutions > Guides > Ansible for SmartFabric OS10 - Technical Note > Set hostnames and configure VLANs by using the Ansible OS10 module
This example shows how to configure a hostname and create VLANs for a leaf-spine fabric by using the os10_config
module.
Create an inventory file with the IP addresses of the switches to be configured.
vim inventory.yaml
[os10] leaf1 ansible_host=192.168.1.210 ansible_network_os=dellemc.os10.os10 leaf2 ansible_host=192.168.1.211 ansible_network_os=dellemc.os10.os10 spine1 ansible_host=192.168.1.212 ansible_network_os=dellemc.os10.os10
:wq
Create variable files for leaf1, leaf2, leaf3, spine1, and spine2.
vim host_vars/leaf1.yaml
i
to edit the file, and then enter the following commands:
hostname: Leaf1
ansible_ssh_user: admin
ansible_ssh_pass: admin
:wq
vim host_vars/leaf2.yaml
i
to edit the file, and then enter the following commands:
hostname: Leaf2
ansible_ssh_user: admin
ansible_ssh_pass: admin
:wq
vim host_vars/leaf3.yaml
i
to edit the file, and then enter the following commands:
hostname: Leaf3
ansible_ssh_user: admin
ansible_ssh_pass: admin
:wq
vim host_vars/spine1.yaml
i
to edit the file, and then enter the following commands:
hostname: Spine1
ansible_ssh_user: admin
ansible_ssh_pass: admin
:wq
vim host_vars/spine2.yaml
i
to edit the file, and then enter the following commands:
hostname: Spine2
ansible_ssh_user: admin
ansible_ssh_pass: admin
:wq
Create and run an Ansible playbook for setting the hostname and configuring VLANs.
vim hostname_vlan.yaml
i
to edit the file, and enter the following commands:
---
- hosts: datacenter
gather_facts: false
connection: network_cli
collections:
- dellemc.os10
tasks:
- name: "Set hostname and configure VLAN 10"
os10_config:
commands:
- hostname {{hostname}}
- interface vlan 10
register: set_hostname_vlan
- debug: var=set_hostname_vlan
:wq
ansible-playbook -i inventory.yaml hostname_vlan.yaml