How to change flavor or sg of a virtual machine with Ansible?
Hello, I'm new in this Openstack world and I love Ansible. I'm trying to use the openstack.cloud Ansible collection to manage virtual machines. There is no problems in adding or deleting a virtual machine (vm). The openstack.cloud.server module works very well. I'm in trouble if I want to update a vm. The server module has only the "present" state: the resource is not updated after the creation if I change something in the module parameters. So, I can't use openstack.cloud.server module in order to change the flavor or security group of an already existing vm. The "server_action" module is not useful because it has not update actions about sg or flavor. I tried the CRUD "resource" module in some way such as --- - name: Change resources hosts: localhost tasks: - name: Change flavor to vm openstack.cloud.resource: cloud: myStack service: compute type: server attributes: name: vm-name flavor_id: 22b4d2c2-0fff-437b-a67c-009244f89403 state: present wait: true but the play fails with fatal: [localhost]: FAILED! => {"changed": false, "extra_data": {"data": null, "details": "Invalid input for field/attribute server. Value: {'flavorRef': '22b4d2c2-0fd8-437b-a67c-009244f89403'}. Additional properties are not allowed ('flavorRef' was unexpected)" If I try with "flavor" or "security_groups" attributes in place of "flavor_id" the error doesn't change. Could you help me? My env is: [root@cnt-ansible]/workdir/openstack# ansible-galaxy collection list | grep openstack openstack.cloud 2.5.0 [root@cnt-ansible]/workdir/openstack# pip3 list | grep openstack openstacksdk 4.9.0 ansible [core 2.16.14] Thank you very much Kind Regards Marco
Hi Marco, I am not 100% sure, but I think this operation is currently not implemented in the openstack.cloud collection. I'd assume that the openstack.cloud.server_action module should be responsible for an operation like this [1], but `resize` is not in the list of actions. Regarding openstack.cloud.resource - I frankly never properly played with it to suggest anything, but if to refer to openstacksdk documentation, it still should be `resize_server`, which is not listed as supported. Thus, I'd guess your best choice would be to use ansible.builtin.command with supplying `-f json`, to be able to register and parse stdout with | from_json.... [1] https://docs.ansible.com/projects/ansible/latest/collections/openstack/cloud... [2] https://docs.openstack.org/openstacksdk/latest/user/proxies/compute.html#mod... пн, 2 февр. 2026 г. в 15:45, Marco Favero <marco.favero@csi.it>:
Hello,
I'm new in this Openstack world and I love Ansible. I'm trying to use the openstack.cloud Ansible collection to manage virtual machines.
There is no problems in adding or deleting a virtual machine (vm). The openstack.cloud.server module works very well.
I'm in trouble if I want to update a vm. The server module has only the "present" state: the resource is not updated after the creation if I change something in the module parameters.
So, I can't use openstack.cloud.server module in order to change the flavor or security group of an already existing vm.
The "server_action" module is not useful because it has not update actions about sg or flavor.
I tried the CRUD "resource" module in some way such as
--- - name: Change resources hosts: localhost tasks: - name: Change flavor to vm openstack.cloud.resource: cloud: myStack service: compute type: server attributes: name: vm-name flavor_id: 22b4d2c2-0fff-437b-a67c-009244f89403 state: present wait: true
but the play fails with
fatal: [localhost]: FAILED! => {"changed": false, "extra_data": {"data": null, "details": "Invalid input for field/attribute server. Value: {'flavorRef': '22b4d2c2-0fd8-437b-a67c-009244f89403'}. Additional properties are not allowed ('flavorRef' was unexpected)"
If I try with "flavor" or "security_groups" attributes in place of "flavor_id" the error doesn't change.
Could you help me?
My env is:
[root@cnt-ansible]/workdir/openstack# ansible-galaxy collection list | grep openstack openstack.cloud 2.5.0 [root@cnt-ansible]/workdir/openstack# pip3 list | grep openstack openstacksdk 4.9.0
ansible [core 2.16.14]
Thank you very much Kind Regards
Marco
Hi Dmitriy, thank you for the help. Reading the documentation and trying better I see that with server module I can change the sg. :) But I can't change the flavor. I think I have to modify the collection in server_action in order to perform a flavor change. Because it seems that resource module can't do that :( Thank you Kind Regards Marco
participants (3)
-
Dmitriy Rabotyagov
-
Marco Favero
-
marco.favero@csi.it