create multiple vlan port groups on 5 esxi servers

81 views
Skip to first unread message

Tony Wong

unread,
Dec 19, 2021, 4:12:36 PM12/19/21
to Ansible Project
i got following task to create mul;tiple vlan ports groups on a vswitch on 5 esxi hosts

task playbok is

---
- name: create_vss_vlan_PGs
  vmware_portgroup:
    hostname: '{{ vcenter_hostname }}'
    username: '{{ vcenter_username }}'
    password: '{{ vcenter_password }}'
    cluster_name: '{{ cluster_name }}'
    switch_name: '{{ vswitch_name }}'
    portgroup_name: '{{ portgroup_name }}'
    vlan_id: '{{ vlan_id }}'
  delegate_to: localhost


i have answer file like so


vcenter_hostname: "myvcenter.domain.com"
vcenter_username: "admini...@vsphere.local"
vcenter_password: "xxxxxxxx"
cluster_name: "cluster"
switch_name: "vSwitch0"
portgroup_name: "??????"
vlan_id: "?????"


my hosts file is

[esx]
esx1
esx2
esx3
esx4
esx5

[esx:vars]


any idea how i would create the portgroups with different vlan ids? which file would i put them in?


Tony Wong

unread,
Dec 20, 2021, 10:39:08 AM12/20/21
to Ansible Project
any idea?

Rodrigues

unread,
Dec 22, 2021, 4:11:10 PM12/22/21
to Ansible Project
The simplest way would be add the vlans and portgroup names as a list in vars
Then loop through them using with_items

Like this

vlans:
- portgroup_name: vlan 1
  vlan_id: 1
- portgroup_name: vlan 2
  vlan_id: 2
- portgroup_name: vlan 3
  vlan_id: 3
  


- name: create_vss_vlan_PGs
  vmware_portgroup:
    hostname: '{{ vcenter_hostname }}'
    username: '{{ vcenter_username }}'
    password: '{{ vcenter_password }}'
    cluster_name: '{{ cluster_name }}'
    switch_name: '{{ vswitch_name }}'
    portgroup_name: '{{ item.portgroup_name }}'
    vlan_id: '{{ item.vlan_id }}'
  delegate_to: localhost
  with_items: '{{ vlans }}'

Tony Wong

unread,
Dec 23, 2021, 6:21:23 PM12/23/21
to Ansible Project
does the vlan Ids need to be in separate vars file? which file should they be in?

Rodrigues

unread,
Dec 25, 2021, 7:01:58 AM12/25/21
to Ansible Project
Nope, you can put them directly in the playbook in the vars section. Similar to this: https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html

Tony Wong

unread,
Dec 29, 2021, 12:29:07 PM12/29/21
to Ansible Project
hi

Is it possible to override default failover NIC policy?

I need to have 2 active nics on each portgroup

Rodrigues -

unread,
Dec 30, 2021, 5:17:39 AM12/30/21
to ansible...@googlegroups.com
Yeah sure can.
Check this out, the last example has what you're looking for




--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/QeyoK02yLYw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/bc9dcdf1-daf8-4e94-a9a7-4d99cb1a9c4fn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages