Skip to content
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_drs_group_manager: Unable to add VM/Hosts to DRS rule #1415

Closed
ErikVenema opened this issue Jul 28, 2022 · 4 comments
Closed

vmware_drs_group_manager: Unable to add VM/Hosts to DRS rule #1415

ErikVenema opened this issue Jul 28, 2022 · 4 comments
Labels
needs_info This issue requires further information. Please answer any outstanding questions

Comments

@ErikVenema
Copy link

SUMMARY

I'm unable to add any vm's or hosts to an existing affinity/drs rule with the error "Error: 'Nonetype' object has no attribute 'vm" for adding vm's and for hosts it's: "Error: 'Nonetype' object has no attribute 'host"

ISSUE TYPE
  • Bug Report
COMPONENT NAME

vmware_drs_group_manager

ANSIBLE VERSION
ansible-playbook [core 2.12.5.post0]
  config file = None
  configure module search path = ['home/runner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = '/usr/local/lib/python3.8/site-packages/ansible
  ansible collection location = /runner/requirements_collections:/home/runner/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible-playbook
  python version = 3.8.13 (default, Jun 24 2022, 15:27:57) [GCC 8.5.0 20210514 (Red Hat 8.5.0-13)]
  jinja version = 2.11.3
  libyaml = True
COLLECTION VERSION
community.vmware 2.7.0
CONFIGURATION
ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True
COLLECTIONS_PATHS(env: ANSIBLE_COLLECTIONS_PATHS) = /runner/requirements_collections, /home/runner/.ansible/collections, /usr/share/ansible/collections
DEFAULT_CALLBACK_PLUGIN_PATH(env: ANSIBLE_CALLBACK_PLUGINS) = /usr/local/lib/python3.8/site-packages/ansible_runner/callbacks
DEFAULT_ROLES_PATH(env: ANSIBLE_ROLES_PATH) = /runner/requirements_roles, /home/runner/.ansible/roles, /usr/share/ansible/roles, /etc/ansible/roles
DEFAULT_STDOUT_CALLBACK(env: ANSIBLE_STDOUT_CALLBACK) = awx_display
HOST_KEY_CHECKING(env: ANSIBLE_HOST_KEY_CHECKING) = False
INVENTORY_UNPARSED_IS_FAILED(env: ANSIBLE_INVENTORY_UNPARSED_FAILED) = True
RETRY_FILES_ENABLED(env: ANSIBLE_RETRY_FILES_ENABLED) = False
OS / ENVIRONMENT
VMware vSphere version 7.0.3
STEPS TO REPRODUCE
- name: Add Hosts in an existing DRS Host group
  delegate_to: localhost
  community.vmware.vmware_drs_group_manager:
    hostname: "{{ vcenter_hostname }}"
    username: "{{ vcenter_username }}"
    password: "{{ vcenter_password }}"

    cluster: "{{ vcenter_cluster }}"
    datacenter: "{{ vcenter_datacenter }}"
    group_name: "{{ affinity_rule }}"
    vms:
      - ansiblewin1
      - ansiblewin2
    state: present
EXPECTED RESULTS

The vms/hosts should be added to the affinity drs group.

ACTUAL RESULTS
{
  "msg": "Error: 'NoneType' object has no attribute 'vm'",
  "invocation": {
    "module_args": {
      "hostname": "REMOVED",
      "username": "REMOVED",
      "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
      "cluster": "REMOVED",
      "datacenter": "REMOVED",
      "group_name": "affinity_rule",
      "vms": [
        "ansiblewin1",
        "ansiblewin2"
      ],
      "state": "present",
      "port": 443,
      "proxy_host": null,
      "proxy_port": null,
      "hosts": null
    }
  },
  "_ansible_no_log": false,
  "changed": false,
  "_ansible_delegated_vars": {
    "ansible_host": "localhost",
    "ansible_port": null,
    "ansible_user": "root",
    "ansible_connection": "local"
  }
}

To test further I've used VM's that didn't exist and came up with an error that the VM's indeed didn't exist. When I use VM's that do exist it doesn't and gives above error. When using a rule that doesn't exist it also gives the above error, so I'm assuming it doesn't even get to the step that checks if the rule exists.

@ErikVenema
Copy link
Author

After some further testing it looks to be caused on line 414 for the VM's

VMs output:

{
  "module_stdout": "",
  "module_stderr": "Traceback (most recent call last):\n  File \"/root/.ansible/tmp/ansible-tmp-1659089295.7209122-130-208605871620236/AnsiballZ_vmware_drs_group_manager.py\", line 107, in <module>\n    _ansiballz_main()\n  File \"/root/.ansible/tmp/ansible-tmp-1659089295.7209122-130-208605871620236/AnsiballZ_vmware_drs_group_manager.py\", line 99, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/root/.ansible/tmp/ansible-tmp-1659089295.7209122-130-208605871620236/AnsiballZ_vmware_drs_group_manager.py\", line 47, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.community.vmware.plugins.modules.vmware_drs_group_manager', init_globals=dict(_module_fqn='ansible_collections.community.vmware.plugins.modules.vmware_drs_group_manager', _modlib_path=modlib_path),\n  File \"/usr/lib64/python3.8/runpy.py\", line 207, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib64/python3.8/runpy.py\", line 97, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/usr/lib64/python3.8/runpy.py\", line 87, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_community.vmware.vmware_drs_group_manager_payload_p6a2uyoz/ansible_community.vmware.vmware_drs_group_manager_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_drs_group_manager.py\", line 522, in <module>\n  File \"/tmp/ansible_community.vmware.vmware_drs_group_manager_payload_p6a2uyoz/ansible_community.vmware.vmware_drs_group_manager_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_drs_group_manager.py\", line 505, in main\n  File \"/tmp/ansible_community.vmware.vmware_drs_group_manager_payload_p6a2uyoz/ansible_community.vmware.vmware_drs_group_manager_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_drs_group_manager.py\", line 475, in manage_drs_group_members\n  File \"/tmp/ansible_community.vmware.vmware_drs_group_manager_payload_p6a2uyoz/ansible_community.vmware.vmware_drs_group_manager_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_drs_group_manager.py\", line 414, in _manage_vm_group\nAttributeError: 'NoneType' object has no attribute 'vm'\n",
  "exception": "Traceback (most recent call last):\n  File \"/root/.ansible/tmp/ansible-tmp-1659089295.7209122-130-208605871620236/AnsiballZ_vmware_drs_group_manager.py\", line 107, in <module>\n    _ansiballz_main()\n  File \"/root/.ansible/tmp/ansible-tmp-1659089295.7209122-130-208605871620236/AnsiballZ_vmware_drs_group_manager.py\", line 99, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/root/.ansible/tmp/ansible-tmp-1659089295.7209122-130-208605871620236/AnsiballZ_vmware_drs_group_manager.py\", line 47, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.community.vmware.plugins.modules.vmware_drs_group_manager', init_globals=dict(_module_fqn='ansible_collections.community.vmware.plugins.modules.vmware_drs_group_manager', _modlib_path=modlib_path),\n  File \"/usr/lib64/python3.8/runpy.py\", line 207, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib64/python3.8/runpy.py\", line 97, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/usr/lib64/python3.8/runpy.py\", line 87, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_community.vmware.vmware_drs_group_manager_payload_p6a2uyoz/ansible_community.vmware.vmware_drs_group_manager_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_drs_group_manager.py\", line 522, in <module>\n  File \"/tmp/ansible_community.vmware.vmware_drs_group_manager_payload_p6a2uyoz/ansible_community.vmware.vmware_drs_group_manager_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_drs_group_manager.py\", line 505, in main\n  File \"/tmp/ansible_community.vmware.vmware_drs_group_manager_payload_p6a2uyoz/ansible_community.vmware.vmware_drs_group_manager_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_drs_group_manager.py\", line 475, in manage_drs_group_members\n  File \"/tmp/ansible_community.vmware.vmware_drs_group_manager_payload_p6a2uyoz/ansible_community.vmware.vmware_drs_group_manager_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_drs_group_manager.py\", line 414, in _manage_vm_group\nAttributeError: 'NoneType' object has no attribute 'vm'\n",
  "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
  "rc": 1,
  "_ansible_no_log": false,
  "changed": false,
  "_ansible_delegated_vars": {
    "ansible_host": "localhost",
    "ansible_port": null,
    "ansible_user": "root",
    "ansible_connection": "local"
  }
}

def _manage_vm_group(self):
# Check if anything has changed when editing
if self._check_if_vms_hosts_changed():
need_reconfigure = False
group = vim.cluster.VmGroup()
group.name = self._group_name
group.vm = self._group_obj.vm or []

Hosts output:

{
  "module_stdout": "",
  "module_stderr": "Traceback (most recent call last):\n  File \"/root/.ansible/tmp/ansible-tmp-1659089818.0389547-131-75400439795310/AnsiballZ_vmware_drs_group_manager.py\", line 107, in <module>\n    _ansiballz_main()\n  File \"/root/.ansible/tmp/ansible-tmp-1659089818.0389547-131-75400439795310/AnsiballZ_vmware_drs_group_manager.py\", line 99, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/root/.ansible/tmp/ansible-tmp-1659089818.0389547-131-75400439795310/AnsiballZ_vmware_drs_group_manager.py\", line 47, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.community.vmware.plugins.modules.vmware_drs_group_manager', init_globals=dict(_module_fqn='ansible_collections.community.vmware.plugins.modules.vmware_drs_group_manager', _modlib_path=modlib_path),\n  File \"/usr/lib64/python3.8/runpy.py\", line 207, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib64/python3.8/runpy.py\", line 97, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/usr/lib64/python3.8/runpy.py\", line 87, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_community.vmware.vmware_drs_group_manager_payload_tm7xis17/ansible_community.vmware.vmware_drs_group_manager_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_drs_group_manager.py\", line 522, in <module>\n  File \"/tmp/ansible_community.vmware.vmware_drs_group_manager_payload_tm7xis17/ansible_community.vmware.vmware_drs_group_manager_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_drs_group_manager.py\", line 505, in main\n  File \"/tmp/ansible_community.vmware.vmware_drs_group_manager_payload_tm7xis17/ansible_community.vmware.vmware_drs_group_manager_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_drs_group_manager.py\", line 473, in manage_drs_group_members\n  File \"/tmp/ansible_community.vmware.vmware_drs_group_manager_payload_tm7xis17/ansible_community.vmware.vmware_drs_group_manager_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_drs_group_manager.py\", line 379, in _manage_host_group\nAttributeError: 'NoneType' object has no attribute 'host'\n",
  "exception": "Traceback (most recent call last):\n  File \"/root/.ansible/tmp/ansible-tmp-1659089818.0389547-131-75400439795310/AnsiballZ_vmware_drs_group_manager.py\", line 107, in <module>\n    _ansiballz_main()\n  File \"/root/.ansible/tmp/ansible-tmp-1659089818.0389547-131-75400439795310/AnsiballZ_vmware_drs_group_manager.py\", line 99, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/root/.ansible/tmp/ansible-tmp-1659089818.0389547-131-75400439795310/AnsiballZ_vmware_drs_group_manager.py\", line 47, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.community.vmware.plugins.modules.vmware_drs_group_manager', init_globals=dict(_module_fqn='ansible_collections.community.vmware.plugins.modules.vmware_drs_group_manager', _modlib_path=modlib_path),\n  File \"/usr/lib64/python3.8/runpy.py\", line 207, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib64/python3.8/runpy.py\", line 97, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/usr/lib64/python3.8/runpy.py\", line 87, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_community.vmware.vmware_drs_group_manager_payload_tm7xis17/ansible_community.vmware.vmware_drs_group_manager_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_drs_group_manager.py\", line 522, in <module>\n  File \"/tmp/ansible_community.vmware.vmware_drs_group_manager_payload_tm7xis17/ansible_community.vmware.vmware_drs_group_manager_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_drs_group_manager.py\", line 505, in main\n  File \"/tmp/ansible_community.vmware.vmware_drs_group_manager_payload_tm7xis17/ansible_community.vmware.vmware_drs_group_manager_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_drs_group_manager.py\", line 473, in manage_drs_group_members\n  File \"/tmp/ansible_community.vmware.vmware_drs_group_manager_payload_tm7xis17/ansible_community.vmware.vmware_drs_group_manager_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_drs_group_manager.py\", line 379, in _manage_host_group\nAttributeError: 'NoneType' object has no attribute 'host'\n",
  "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
  "rc": 1,
  "_ansible_no_log": false,
  "changed": false,
  "_ansible_delegated_vars": {
    "ansible_host": "localhost",
    "ansible_port": null,
    "ansible_user": "root",
    "ansible_connection": "local"
  }
}

def _manage_host_group(self):
# Check if anything has changed when editing
if self._check_if_vms_hosts_changed(host_group=True):
need_reconfigure = False
group = vim.cluster.HostGroup()
group.name = self._group_name
group.host = self._group_obj.host or []

@mariolenz
Copy link
Collaborator

I think the module doesn't really test if the group exists. I can reproduce your issue if I run the playbook with a non-existing group_name.

Are you sure the group really exists? Either it doesn't, or the account you're using in your playbook doesn't have permissions on DRS groups. I can't think of any other explanation at the moment.

softwarefactory-project-zuul bot pushed a commit that referenced this issue Sep 6, 2022
vmware_drs_group_manager: Improve error handling

SUMMARY
vmware_drs_group_manager raises exceptions instead of calling  fail_json().
Additionally, if the DRS group doesn't exist the module fails with 'NoneType' object has no attribute 'vm' or 'NoneType' object has no attribute 'host' which isn't really helpful.
ISSUE TYPE

Feature Pull Request

COMPONENT NAME
vmware_drs_group_manager
ADDITIONAL INFORMATION
#1415
@mariolenz
Copy link
Collaborator

@ErikVenema Could you please test again with community.vmware 2.9.0 or later?

@mariolenz mariolenz added the needs_info This issue requires further information. Please answer any outstanding questions label Oct 24, 2022
@mariolenz
Copy link
Collaborator

Since I didn't get the information that the problem still exist wit 2.9.0 and later, I consider this issue fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs_info This issue requires further information. Please answer any outstanding questions
Projects
None yet
Development

No branches or pull requests

2 participants