ansible-collections / community.vmware

Ansible Collection for VMware
GNU General Public License v3.0
348 stars 334 forks source link

Module to configure TCP/IP Stack Settings (including Gateway) #654

Closed luischanu closed 3 years ago

luischanu commented 3 years ago
SUMMARY

It would be very helpful to have an Ansible module which can be used to configure TCP/IP Stacks on an ESXi server, including the configuration of its gateway. I could not find such a module as part of the current Community.VMware modules.

ISSUE TYPE
COMPONENT NAME

vmware_host_tcpip_stacks

ADDITIONAL INFORMATION

I did find a module which Christian Kotte created a while ago, but it didn't seem to work for me when I tried it. His module was called vmware_host_tcpip_stacks, and the module that I referenced above can be found HERE. I think that Christian Kotte has done some great work, and don't think it would take too much effort by a talented individual to get it working. I think it would be a very useful module to have as part of the Community.VMware modules.

To get around this, I'm currently configuring the vMotion TCP/IP Stack gateway directly on the ESXi host via the CLI with the play below, but it would be nice if this could be accomplished via a TCP/IP Stack specific Ansible module.

    - name: Configure vMotion TCP/IP stack gateway address on Nested_ESXi hosts
      vmware_vm_shell:
        hostname: "{{ Target.FQDN }}"
        username: "{{ Target.User }}"
        password: "{{ Target.Password }}"
        cluster: "{{ Target.Cluster }}"
        datacenter: "{{ Target.DataCenter }}"
        folder: "{{ Target.VMFolder }}"
        validate_certs: false
        vm_id: "{{ item.value.VMName }}"
        vm_username: "{{ item.value.User }}"
        vm_password: "{{ item.value.Password }}"
        vm_shell: /bin/esxcli
        vm_shell_args: "network ip route ipv4 add --netstack vmotion --network default --gateway {{ item.value.vmk.vmk1.Address.IPv4.Gateway }}"
      loop: "{{ Nested_ESXi.Host | dict2items }}"
      when:
        - Nested_Clusters[item.value.Cluster]['DeployHosts'] == true
ansibullbot commented 3 years ago

Files identified in the description: None

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

sky-joker commented 3 years ago

Thanks, @luischanu for the feature idea.

I made the vmware_host_tcpip_stacks module you're requested.
Could you please check the module works well in your environment?
And let me know the result.

How to test the module

(venv)$ git clone https://github.com/ansible-collections/vmware.git collections/ansible_collections/community/vmware
(venv)$ cd collections/ansible_collections/community/vmware/
(venv)$ git fetch origin pull/811/head:add_new_module_tcpip_stacks && git checkout add_new_module_tcpip_stacks
(venv)$ cd ../../../../
(venv)$ vi test_playbook.yml
---
- name: test playbook
  hosts: localhost
  gather_facts: false
  tasks:
    - name: xxxx
      community.vmware.vmware_host_tcpip_stacks:
      (snip)
sky-joker commented 3 years ago

resolved_by_pr https://github.com/ansible-collections/community.vmware/pull/811

luischanu commented 3 years ago

@sky-joker , I'm very sorry for my delay. This request rolled off my e-mail, I'll give it a test. Thank you!

luischanu commented 3 years ago

@sky-joker , I found some time to test the module, and there are a few things I noticed that I wanted to bring to your attention.

1) In vSphere 7, the "vxlan" stack shows up in the GUI as "nsx-overlay". Granted, under the covers it's still referenced as "vxlan", but someone new may not know that. I tried using "nsx-overlay" as a test, and it (as expected) failed. I thought it might be good to maybe mention that in the documentation in the vxlan section.

2) In the original link I provided above, Christian Kotte had a very useful "Cluster_Name" option which would apply the settings to all of the hosts in the cluster. Would it be possible to include that functionality in your module as well?

3) Some of the labs that I deploy are dual stacked, but I noticed that the module didn't have IPv6 support. Would it be possible to also have IPv6 support added to the module?

Beyond the items mentioned above, my quick and simple test was able to successfully set the IPv4 Gateways on the vMotion and vxlan TCP/IP stacks.

Thank you for your efforts! Greatly appreciated...

Sincerely,

Luis

sky-joker commented 3 years ago

Thanks, @luischanu for your feedback and checking the module works.
I'm glad to be for the module works well in your environment.
Ok, I'll try implementing the requested as a new feature to the module.

sky-joker commented 3 years ago

After confirming the module code, I can implement most likely the No1, 3 features.
Unfortunately, maybe the No2 is difficult because the module is designed to handle just one ESXi now.

sky-joker commented 3 years ago

Hi @luischanu

First of all, I implemented easy No1 and 3 you have been requested to the module.
Could you please check the module works well in your environment?
And let me know the result.

resolved_by_pr https://github.com/ansible-collections/community.vmware/pull/834

luischanu commented 3 years ago

@sky-joker , I just tested the module, and I was able to set the IPv6 Gateway... Thank you!

sky-joker commented 3 years ago

Thanks, @luischanu for checking the module works!