Description
SUMMARY
The community.general.one_host module fails when allocating the first host (ID: 0) in OpenNebula.
It also fails when updating the template/attributes of the host with an ID of 0.
This occurs even though it appears the host has been allocated or updated successfully in OpenNebula.
I think the problem is that the allocate()
and update()
functions used on lines 141 and 254 of one_host.py
return the ID of the OpenNebula host allocated or updated. The result of these function calls is checked by an if statement, and if the result is 0
then self.fail()
is called. Therefore, when updating or allocating the host with an ID of 0 in OpenNebula, ansible needlessly fails when it was actually successful.
ISSUE TYPE
- Bug Report
COMPONENT NAME
one_host
ANSIBLE VERSION
ansible 2.10.2
config file = $ANSIBLE_PROJECT/ansible.cfg
configured module search path = ['$HOME/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = $HOME/.ansible/venv/lib/python3.5/site-packages/ansible
executable location = $HOME/.ansible/venv/bin/ansible
python version = 3.5.2 (default, Oct 7 2020, 17:19:02) [GCC 5.4.0 20160609]
CONFIGURATION
OS / ENVIRONMENT
OS: Debian 10
Collection: community.general shipped with ansible 2.10
Packages:
- OpenNebula 5.12.0.3
- pyone 5.12.0.3
STEPS TO REPRODUCE
Setup environment:
- Create python virtual environment and install ansible + pyone.
- Provision OpenNebula front-end.
- Provision OpenNebula host.
Steps:
- Run example playbook from below.
- Verify that the host was successfully added to OpenNebula.
- Run example playbook again.
- name: Example
hosts: localhost
connection: local
become: false
gather_facts: false
tasks:
- name: Add host to OpenNebula
community.general.one_host:
api_url: "{{ one_api_url }}"
api_username: "{{ one_api_username }}"
api_password: "{{ one_api_password }}"
name: "{{ one_host }}"
im_mad_name: kvm
vmm_mad_name: kvm
template:
TYPE: "testing"
state: present
EXPECTED RESULTS
First play:
TASK [Add host to OpenNebula] ********************
changed: [localhost]
Second play:
TASK [Add host to OpenNebula] ********************
ok: [localhost]
ACTUAL RESULTS
First play:
TASK [Add host to OpenNebula] ********************
fatal: [localhost]: FAILED! => {"changed": false, "msg": "could not allocate host"}
Second play:
TASK [Add host to OpenNebula] ********************
fatal: [localhost]: FAILED! => {"changed": false, "msg": "failed to update the host template"}
Third play:
TASK [Add host to OpenNebula] ********************
ok: [localhost]