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

filter_names does not document or gracefully handle spaces #362

Closed
jeffcpullen opened this issue Nov 15, 2022 · 4 comments · Fixed by #371
Closed

filter_names does not document or gracefully handle spaces #362

jeffcpullen opened this issue Nov 15, 2022 · 4 comments · Fixed by #371

Comments

@jeffcpullen
Copy link

SUMMARY

The _info modules provide a method of filtering names but will fail on names that contain a space. If the module does not gracefully handle names with spaces it should at least be documented how names should be written to be tolerated by the modules. Adding a '%20' in place of a space seems to make the module function as expected.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

vmware.vmware_rest.vcenter_datacenter_info

ANSIBLE VERSION
$ ansible --version
ansible [core 2.12.3]
  config file = /Users/jpullen/.ansible.cfg
  configured module search path = ['/Users/jpullen/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
  ansible collection location = /Users/jpullen/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.9.13 (main, May 24 2022, 21:28:31) [Clang 13.1.6 (clang-1316.0.21.2)]
  jinja version = 3.0.3
  libyaml = True
COLLECTION VERSION
Collection         Version
------------------ -------
vmware.vmware_rest 2.2.0 
CONFIGURATION
$ ansible-config dump --only-changed
DEFAULT_HOST_LIST(/Users/jpullen/.ansible.cfg) = ['/Users/jpullen/inventory/hosts']
HOST_KEY_CHECKING(/Users/jpullen/.ansible.cfg) = False
OS / ENVIRONMENT
STEPS TO REPRODUCE
vars:
  vcenter_config_datacenter: "Homelab DC"
tasks:
- name: List datacenters
  vmware.vmware_rest.vcenter_datacenter_info:
    filter_names:
      # fails to return any results
      - "{{ vcenter_config_datacenter }}"
      # Replace blank spaces with %20 to make this work (shown in line below)
      # - "{{ vcenter_config_datacenter | replace(' ', '%20') }}"
  register: my_datacenters

- name: Debug datacenter info
  ansible.builtin.debug:
    var: my_datacenters
EXPECTED RESULTS
TASK [create_vsphere_vm : Debug datacenter info] *******************************************
ok: [localhost] => {
    "my_datacenters": {
        "changed": false,
        "failed": false,
        "value": [
            {
                "datacenter": "datacenter-3",
                "name": "Homelab DC"
            }
        ]
    }
}
ACTUAL RESULTS

If the user leaves any values without spaces using a _info module it will fail to filter. Quotes and backslashes will not work. Only adding the '%20' to the variables will result in the expected results.

TASK [create_vsphere_vm : Debug datacenter info] *******************************************
ok: [localhost] => {
    "my_datacenters": {
        "changed": false,
        "failed": false,
        "value": []
    }
}
@rit001
Copy link

rit001 commented Nov 17, 2022

If someone does look at resolving this issue can they please make sure that they retain support for %20 being used instead of a space. Now that the current workaround/limitation/design feature is known I like others will be coding scripts using %20 and it will be a problem if a future update goes and breaks the scripts.

@jeffcpullen
Copy link
Author

By the way, my initial work around was fine for spaces but wouldn't handle other special characters that might cause issues with a url. I've switched to using the urlencode filter to be more comprehensive.

filter_names:
      - "{{ create_vsphere_vm_cluster | urlencode }}"

goneri added a commit to goneri/vmware_rest_code_generator that referenced this issue Nov 23, 2022
goneri added a commit to goneri/vmware.vmware_rest that referenced this issue Nov 23, 2022
goneri added a commit to goneri/vmware_rest_code_generator that referenced this issue Nov 24, 2022
softwarefactory-project-zuul bot added a commit to ansible-collections/vmware_rest_code_generator that referenced this issue Nov 24, 2022
goneri added a commit to goneri/vmware.vmware_rest that referenced this issue Nov 24, 2022
The modules are autogenerated by:
https://github.com/ansible-collections/vmware_rest_code_generator
version: f4bbe71330eab0684aee08ab3d2baf4463f93774

Closes: ansible-collections#362
softwarefactory-project-zuul bot pushed a commit that referenced this issue Dec 1, 2022
bump auto-generated modules

The modules are autogenerated by:
https://github.com/ansible-collections/vmware_rest_code_generator
version: f4bbe71330eab0684aee08ab3d2baf4463f93774
Closes: #362
@rit001
Copy link

rit001 commented Dec 1, 2022

As the person who first raised this, thanks to everyone for firstly a workaround and then secondly a final fix.

@rit001
Copy link

rit001 commented Apr 24, 2023

Just as a follow-up as I've just started to update systems. The old matching of %20 to a space has not been retained after a fix was put in place to allow the correct matching of spaces.

The result is a change to the historic way in which this works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants