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

Image module can only create but not update or delete vmware images #927

Closed
tux93 opened this issue Aug 17, 2020 · 2 comments · Fixed by #938
Closed

Image module can only create but not update or delete vmware images #927

tux93 opened this issue Aug 17, 2020 · 2 comments · Fixed by #938

Comments

@tux93
Copy link

tux93 commented Aug 17, 2020

SUMMARY

It is currently not possible to update / modify or delete vmware images created by the Image module

# rpm -q ansible-collection-theforeman-foreman
ansible-collection-theforeman-foreman-0.7.0
ISSUE TYPE
  • Bug Report
ANSIBLE VERSION
ansible 2.9.10
  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 = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.5 (default, Apr  2 2020, 13:16:51) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
KATELLO/FOREMAN VERSION
tfm-rubygem-katello-3.14.1
foreman-1.24.3
STEPS TO REPRODUCE

Generating an image on the first run works fine, a second run ends in failed state

- hosts: all
  tasks:
  - name: define default variables
    set_fact:
      tfm_connection: &tfm_connection
      username: "admin"
      password: "secret"
      server_url: "https://localhost"
      validate_certs: "false"
  - name: centos 7 image creation in ESX1
    theforeman.foreman.image:
      <<: *tfm_connection
      state: present
      name: "CentOS 7"
      uuid: "502f263f-6f70-a568-d0c9-7e25f4993ae0"
      image_username: "ansible"
      operatingsystem: "CentOS 7"
      compute_resource: "ESX1"
      architecture: "x86_64"
      user_data: true
EXPECTED RESULTS

Running the task a second time would update the image

ACTUAL RESULTS

Running the task a second time throws an error

TASK [centos 7 image creation in ESX1] *************************************************************************************************************************************************************************************************** 
fatal: [localhost]: FAILED! => {"changed": false, "error": {"errors": {"name": ["has already been taken"], "uuid": ["has already been taken"]}, "full_messages": ["Name has already been taken", "UUID has already been taken"], "id": null}, "msg": "Error while performing create on images: 422 Client Error: Unprocessable Entity"}

PLAY RECAP *********************************************************************************************************************************************************************************************************************************** 
localhost : ok=2 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0

According to the foreman api docs POST should be used for creating an image and PUT to update it
https://theforeman.org/plugins/katello/3.14/api/apidoc/v2/images/update.html

The error might be caused by the module using POST instead of PUT on both runs

Additionally changing state: present to absent does not delete the image

@evgeni
Copy link
Member

evgeni commented Aug 18, 2020

This looks like it can't find the image it just created and tries to create a new one instead of updating (or deleting) it.

@Fobhep and @hlawatschek will love to look into that as time permits.

@hlawatschek
Copy link
Contributor

It seems that this error occurs only when you try to change the image name or name includes a space character.

evgeni added a commit to evgeni/foreman-ansible-modules that referenced this issue Sep 1, 2020
evgeni added a commit that referenced this issue Sep 1, 2020
pondrejk pushed a commit to pondrejk/foreman-ansible-modules that referenced this issue Sep 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants