New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vmware_guest dvs idempotency issue #34105

Closed
reversecipher opened this Issue Dec 20, 2017 · 4 comments

Comments

Projects
None yet
3 participants
@reversecipher
Copy link
Contributor

reversecipher commented Dec 20, 2017

ISSUE TYPE
  • Bug Report
COMPONENT NAME

vmware_guest

ANSIBLE VERSION
ansible 2.5.0 (devel b385e3d725) last updated 2017/12/19 21:47:59 (GMT +300)
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /root/ansible-dev/lib/ansible
  executable location = /root/ansible-dev/bin/ansible
  python version = 2.7.5 (default, Aug  4 2017, 00:39:18) [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)]
CONFIGURATION

N/A

OS / ENVIRONMENT

CentOS Linux release 7.4.1708 (Core)
VMware Vsphere 5.5

SUMMARY

After VM has been deployed, if I run the same task again with same arguments, Ansible returns the result as changed. Vcenter also shows that the VM has been reconfigured. This happens when VM is connected to DVS portgroup.

STEPS TO REPRODUCE
- name: Create vm
  vmware_guest:
    hostname: "{{ vcenter_host }}"
    username: "{{ vcenter_user }}"
    password: "{{ vcenter_password }}"
    validate_certs: no
    folder: /Datacenter/vm/Testing/
    name: test
    template: centos6-template
    state: present
    datacenter: Datacenter
    cluster: Cluster
    resource_pool: Center
    networks:
      - name: vm-internal
  delegate_to: localhost
EXPECTED RESULTS

Expected Ansible to return changed: false when run multiple times with same parameters.

ACTUAL RESULTS
{
    "invocation": {
        "module_args": {
            "resource_pool": "Center",
            "force": false,
            "hardware": {},
            "cluster": "Cluster",
            "customization": {},
            "disk": [],
            "networks": [{
                "name": "vm-internal"
            }],
            "wait_for_ip_address": false,
            "uuid": null,
            "customvalues": [],
            "hostname": "10.11.11.11",
            "state": "present",
            "template": "centos6-template",
            "linked_clone": false,
            "folder": "/Datacenter/vm/Testing",
            "username": "administrator@vsphere.local",
            "snapshot_src": null,
            "guest_id": null,
            "name_match": "first",
            "cdrom": {},
            "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "annotation": null,
            "datacenter": "Datacenter",
            "name": "test",
            "is_template": false,
            "esxi_hostname": null,
            "validate_certs": false
        }
    },
    "failed": false,
    "changed": true,
    "instance": {
        "hw_name": "test",
        "hw_power_status": "poweredOff",
        "snapshots": [],
        "guest_question": null,
        "hw_interfaces": ["eth0"],
        "hw_guest_id": null,
        "current_snapshot": null,
        "hw_folder": "/Datacenter/vm/Testing",
        "customvalues": {},
        "hw_files": ["[datastore-iscsi] test/test.vmx", "[datastore-iscsi] test/test.vmxf", "[datastore-iscsi] test/test.vmsd", "[datastore-iscsi] test/test.vmdk"],
        "ipv4": null,
        "ipv6": null,
        "hw_product_uuid": "421258c3-568a-6d56-630c-67eada8e22b6",
        "hw_is_template": false,
        "module_hw": true,
        "hw_guest_ha_state": null,
        "guest_consolidation_needed": false,
        "hw_guest_full_name": null,
        "guest_tools_status": "guestToolsNotRunning",
        "guest_tools_version": null,
        "annotation": "",
        "hw_processor_count": 1,
        "hw_memtotal_mb": 1024,
        "hw_datastores": ["datastore-iscsi"],
        "hw_esxi_host": "10.11.11.20",
        "hw_cores_per_socket": 1,
        "hw_eth0": {
            "macaddress": "00:50:56:92:60:4a",
            "addresstype": "assigned",
            "macaddress_dash": "00-50-56-92-60-4a",
            "label": "Network adapter 1",
            "ipaddresses": null,
            "summary": "DVSwitch: ef 85 12 50 28 7d db f3-5b 9f 6a 32 fa b7 29 01"
        }
    }
}

The issue could be resolved by creating the port connection only if nic is changed:

if nic_change_detected:
    dvs_port_connection = vim.dvs.PortConnection()
    dvs_port_connection.portgroupKey = pg_obj.key
    dvs_port_connection.switchUuid = pg_obj.config.distributedVirtualSwitch.uuid
    nic.device.backing = vim.vm.device.VirtualEthernetCard.DistributedVirtualPortBackingInfo()
    nic.device.backing.port = dvs_port_connection
    nic_change_detected = True

After this change when the VM is deployed and the play is run again, the result has changed: false.

@ansibot

This comment has been minimized.

Copy link
Contributor

ansibot commented Dec 20, 2017

Files identified in the description:

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

@ansibot

This comment has been minimized.

@Akasurde

This comment has been minimized.

Copy link
Member

Akasurde commented Dec 21, 2017

@reversecipher Thanks for reporting this issue. Would you like to raise a PR with your findings?

@Akasurde Akasurde changed the title vmware_guest idempotency issue vmware_guest dvs idempotency issue Dec 21, 2017

@reversecipher

This comment has been minimized.

Copy link
Contributor Author

reversecipher commented Dec 22, 2017

Sure, I'll create PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment