Refactored server and server_info modules

Allow to update server attributes such as its description.

Changed default value of server attribute 'security_groups' from
['default'] to [] because the latter is the default in
python-openstackclient [1] and the former behavior causes issues
with existing servers [2]: Previously, when no 'security_groups'
parameter was given, the server module would change existing
servers to use the default security group, dropping all other
security groups assigned to the server.
Our (undocumented) guideline when writing modules is to only
add or change what has been requested by the user and to stick to
defaults from openstacksdk and python-openstackclient whenever
possible. Since we have to break backward compatibility with the
next release anyway, we take this opportunity to clean up this odd
behavior. Now, when no security groups are given, then security
groups of an existing server will not be touched.
Closes story #2007893 [2].
Note, Nova will create a server in the default security group,
if the security_groups parameter is omitted.

Dropped 'openstack' field from server module's results. This
variable expanded to additional server information which might
be useful for Ansible inventories and was filled from
openstacksdk's get_openstack_vars() function [3]. Variables in
this function can make additional cloud queries to retrieve
additional data, so calling this function can be expensive [4].
Users can use *_info modules to retrieve this data on-demand.

Dropped 'availabity_zone' attribute from generic OpenStackModule
arguments and inserted it into server and volume modules because
it is relevant to those two modules only. This is completes what
was started years ago [5] and is possible now since we have
breaking changes anyway.

Switched attribute name 'userdata' with its alias 'user_data' to
match openstacksdk's attribute names which are used e.g. in module
results. The previous attribute name 'userdata' is now used as an
alias and 'user_data' is used as the attribute name to keep backward
compatibility.

Wait for server to get into 'ACTIVE' state when creating a server
and attribute 'wait' has been set to true.

Sorted argument specs and documentation of the server module and
marked attributes which are not updatable. Changed unstable bash
script example in server module documentation.

Renamed server's module attribute 'delete_fip' to 'delete_ips' to
match openstacksdk and clarify that it includes all floating ip
addresses of the server.

Renamed server_info's module attribute 'server' to 'name' and added
the former as an alias to be consistent with other *_info modules.

Added RETURN fields documentation for the module results of both
server and server_info modules.

Added description and examples of how to use the 'filters' attribute
of the server_info module. Closes story #2007873 [6].

Removed 'openstack_' prefix from module results because the prefix is
not consistently used across modules, is more to type without any
benefit and removal of the prefix allows us to signal to users that
their code for handling module results has to be updated. Many modules
have different return values with openstacksdk >= 0.99.0 because it
consistently uses resource proxies now.

Added assertions for module results to catch future changes in the
openstacksdk and our Ansible modules.

Added integration tests to check the update mechanism of the server
module.

Fixed indentation in integration tests.

Ensure proper creation and deletion of resources such as networks,
subnets and servers in integration tests of server_action module.

Renamed ci/roles/server/defaults/main.yaml to main.yml, removing the
'a' in the file extension to be consistent with other filenames.

Dropped deprecated function openstack_find_nova_addresses() and
incorporated its code directly into the server module because it
is not used anywhere else.

[1] e49ad1795b/openstackclient/compute/v2/server.py (L1070)
[2] https://storyboard.openstack.org/#!/story/2007893
[3] 9e9fc98795/openstack/cloud/_compute.py (L1772)
[4] 9e9fc98795/openstack/cloud/meta.py (L482)
[5] 9bf33e56dd
[6] https://storyboard.openstack.org/#!/story/2007873

Signed-off-by: Jakob Meng <code@jakobmeng.de>
Change-Id: I2f955519a7e8c782b1dab8f94f7a019ed384b81d
This commit is contained in:
Jakob Meng 2022-07-11 08:40:53 +02:00
parent 3fdbd56a58
commit ac401bb354
12 changed files with 1702 additions and 642 deletions

View File

@ -103,6 +103,7 @@
router
security_group
security_group_rule
server
subnet
subnet_pool
user
@ -113,7 +114,6 @@
# floating_ip
# orchestrate
# neutron_rbac
# server
- job:
name: ansible-collections-openstack-functional-devstack-octavia-base

View File

@ -162,11 +162,11 @@
# that no floating ip on public network is associated with "10.7.7.100" before running this role
assert:
that:
- info.openstack_servers|length == 1
- info.openstack_servers.0.public_v4|length == 0
- info.openstack_servers.0.public_v6|length == 0
- info.openstack_servers.0.addresses.ansible_internal|length == 1
- info.openstack_servers.0.addresses.ansible_internal|map(attribute="addr")|sort|list == ["10.7.7.100"]
- info.servers|length == 1
- info.servers.0.public_v4|length == 0
- info.servers.0.public_v6|length == 0
- info.servers.0.addresses.ansible_internal|length == 1
- info.servers.0.addresses.ansible_internal|map(attribute="addr")|sort|list == ["10.7.7.100"]
- name: Create server with two nics
openstack.cloud.server:
@ -190,11 +190,11 @@
- name: Assert two internal ports and no floating ips on server 2
assert:
that:
- info.openstack_servers|length == 1
- info.openstack_servers.0.public_v4|length == 0
- info.openstack_servers.0.public_v6|length == 0
- info.openstack_servers.0.addresses.ansible_internal|length == 2
- info.openstack_servers.0.addresses.ansible_internal|map(attribute="addr")|sort|list ==
- info.servers|length == 1
- info.servers.0.public_v4|length == 0
- info.servers.0.public_v6|length == 0
- info.servers.0.addresses.ansible_internal|length == 2
- info.servers.0.addresses.ansible_internal|map(attribute="addr")|sort|list ==
["10.7.7.101", "10.7.7.102"]
# Tests
@ -214,8 +214,8 @@
- name: Assert one internal port and one floating ip on server 1
assert:
that:
- info.openstack_servers.0.addresses.ansible_internal|length == 2
- info.openstack_servers.0.addresses.ansible_internal|map(attribute="OS-EXT-IPS:type")|sort|list ==
- info.servers.0.addresses.ansible_internal|length == 2
- info.servers.0.addresses.ansible_internal|map(attribute="OS-EXT-IPS:type")|sort|list ==
["fixed", "floating"]
- name: Detach floating IP from server
@ -224,7 +224,7 @@
state: absent
server: ansible_server1
network: public
floating_ip_address: "{{ (info.openstack_servers.0.addresses.ansible_internal|
floating_ip_address: "{{ (info.servers.0.addresses.ansible_internal|
selectattr('OS-EXT-IPS:type', '==', 'floating')|map(attribute='addr')|list)[0] }}"
- name: Get info about server
@ -233,16 +233,16 @@
server: ansible_server1
register: info
# When detaching a floating ip from an instance there might be a delay until openstack.cloud.server_info
# does not list it any more in info.openstack_servers.0.addresses.ansible_internal, so retry if necessary.
# does not list it any more in info.servers.0.addresses.ansible_internal, so retry if necessary.
retries: 10
delay: 3
until: info.openstack_servers.0.addresses.ansible_internal|length == 1
until: info.servers.0.addresses.ansible_internal|length == 1
- name: Assert one internal port on server 1
assert:
that:
- info.openstack_servers.0.addresses.ansible_internal|length == 1
- info.openstack_servers.0.addresses.ansible_internal|map(attribute="addr")|list == ["10.7.7.100"]
- info.servers.0.addresses.ansible_internal|length == 1
- info.servers.0.addresses.ansible_internal|map(attribute="addr")|list == ["10.7.7.100"]
- name: Assign floating IP to server
openstack.cloud.floating_ip:
@ -263,8 +263,8 @@
- name: Assert two internal ports and one floating ip on server 2
assert:
that:
- info.openstack_servers.0.addresses.ansible_internal|length == 3
- info.openstack_servers.0.addresses.ansible_internal|map(attribute="OS-EXT-IPS:type")|sort|list ==
- info.servers.0.addresses.ansible_internal|length == 3
- info.servers.0.addresses.ansible_internal|map(attribute="OS-EXT-IPS:type")|sort|list ==
["fixed", "fixed", "floating"]
- name: Assign a second, specific floating IP to server
@ -288,13 +288,13 @@
# retry because we cannot wait for second floating ip
retries: 10
delay: 3
until: info.openstack_servers.0.addresses.ansible_internal|length == 4
until: info.servers.0.addresses.ansible_internal|length == 4
- name: Assert two internal ports and two floating ips on server 2
assert:
that:
- info.openstack_servers.0.addresses.ansible_internal|length == 4
- ("10.6.6.150" in info.openstack_servers.0.addresses.ansible_internal|map(attribute="addr")|sort|list)
- info.servers.0.addresses.ansible_internal|length == 4
- ("10.6.6.150" in info.servers.0.addresses.ansible_internal|map(attribute="addr")|sort|list)
- name: Detach second floating IP from server
openstack.cloud.floating_ip:
@ -310,15 +310,15 @@
server: ansible_server2
register: info
# When detaching a floating ip from an instance there might be a delay until openstack.cloud.server_info
# does not list it any more in info.openstack_servers.0.addresses.ansible_internal, so retry if necessary.
# does not list it any more in info.servers.0.addresses.ansible_internal, so retry if necessary.
retries: 10
delay: 3
until: info.openstack_servers.0.addresses.ansible_internal|length == 3
until: info.servers.0.addresses.ansible_internal|length == 3
- name: Assert two internal ports and one floating ip on server 2
assert:
that:
- info.openstack_servers.0.addresses.ansible_internal|length == 3
- info.servers.0.addresses.ansible_internal|length == 3
- name: Detach remaining floating IP from server
openstack.cloud.floating_ip:
@ -326,7 +326,7 @@
state: absent
server: ansible_server2
network: public
floating_ip_address: "{{ (info.openstack_servers.0.addresses.ansible_internal|
floating_ip_address: "{{ (info.servers.0.addresses.ansible_internal|
selectattr('OS-EXT-IPS:type', '==', 'floating')|map(attribute='addr')|list)[0] }}"
- name: Get info about server
@ -335,16 +335,16 @@
server: ansible_server2
register: info
# When detaching a floating ip from an instance there might be a delay until openstack.cloud.server_info
# does not list it any more in info.openstack_servers.0.addresses.ansible_internal, so retry if necessary.
# does not list it any more in info.servers.0.addresses.ansible_internal, so retry if necessary.
retries: 10
delay: 3
until: info.openstack_servers.0.addresses.ansible_internal|length == 2
until: info.servers.0.addresses.ansible_internal|length == 2
- name: Assert two internal ports on server 2
assert:
that:
- info.openstack_servers.0.addresses.ansible_internal|length == 2
- info.openstack_servers.0.addresses.ansible_internal|map(attribute="addr")|list == ["10.7.7.101", "10.7.7.102"]
- info.servers.0.addresses.ansible_internal|length == 2
- info.servers.0.addresses.ansible_internal|map(attribute="addr")|list == ["10.7.7.101", "10.7.7.102"]
# Clean environment
- name: Delete server with two nics

View File

@ -1,8 +0,0 @@
server_network: private
server_name: ansible_server
server_alt_network: private_alt
server_alt_subnet: subnet_alt
server_alt_name: ansible_server_alt
flavor: m1.tiny
floating_ip_pool_name: public
boot_volume_size: 5

View File

@ -0,0 +1,66 @@
boot_volume_size: 5
expected_fields:
- access_ipv4
- access_ipv6
- addresses
- admin_password
- attached_volumes
- availability_zone
- block_device_mapping
- compute_host
- config_drive
- created_at
- description
- disk_config
- flavor
- flavor_id
- has_config_drive
- host_id
- host_status
- hostname
- hypervisor_hostname
- id
- image
- image_id
- instance_name
- is_locked
- kernel_id
- key_name
- launch_index
- launched_at
- links
- max_count
- metadata
- min_count
- name
- networks
- power_state
- progress
- project_id
- ramdisk_id
- reservation_id
- root_device_name
- scheduler_hints
- security_groups
- server_groups
- status
- tags
- task_state
- terminated_at
- trusted_image_certificates
- updated_at
- user_data
- user_id
- vm_state
- volumes
flavor: m1.tiny
floating_ip_pool_name: public
server_alt_name: ansible_server_alt
server_alt_network: ansible_server_network_alt
server_alt_security_group: ansible_server_security_group_alt
server_alt_subnet: ansible_server_subnet_alt
server_name: ansible_server
server_network: ansible_server_network
server_port: ansible_server_port
server_security_group: ansible_server_security_group
server_subnet: ansible_server_subnet

View File

@ -1,19 +1,79 @@
---
- name: Create network for server
openstack.cloud.network:
cloud: "{{ cloud }}"
name: "{{ server_network }}"
state: present
register: network
- name: Create subnet for server
openstack.cloud.subnet:
cidr: 192.168.0.0/24
cloud: "{{ cloud }}"
name: "{{ server_subnet }}"
network_name: "{{ server_network }}"
state: present
register: subnet
- name: Create second network for server
openstack.cloud.network:
cloud: "{{ cloud }}"
name: "{{ server_alt_network }}"
state: present
- name: Create second subnet for server
openstack.cloud.subnet:
cidr: 192.168.1.0/24
cloud: "{{ cloud }}"
name: "{{ server_alt_subnet }}"
network_name: "{{ server_alt_network }}"
state: present
- name: Create security group for server
openstack.cloud.security_group:
cloud: "{{ cloud }}"
state: present
name: "{{ server_security_group }}"
register: security_group
- name: Create second security group for server
openstack.cloud.security_group:
cloud: "{{ cloud }}"
state: present
name: "{{ server_alt_security_group }}"
register: security_group_alt
- name: Create server with meta as CSV
openstack.cloud.server:
cloud: "{{ cloud }}"
state: present
name: "{{ server_name }}"
image: "{{ image }}"
flavor: "{{ flavor }}"
network: "{{ server_network }}"
auto_floating_ip: false
meta: "key1=value1,key2=value2"
wait: true
cloud: "{{ cloud }}"
state: present
name: "{{ server_name }}"
image: "{{ image }}"
flavor: "{{ flavor }}"
network: "{{ server_network }}"
auto_ip: false
metadata: "key1=value1,key2=value2"
wait: true
register: server
- debug: var=server
- name: assert return values of server module
assert:
that:
# allow new fields to be introduced but prevent fields from being removed
- expected_fields|difference(server.server.keys())|length == 0
- name: Assert server
assert:
that:
- server.server.name == server_name
- server.server.metadata.keys()|sort == ['key1', 'key2']
- server.server.metadata['key1'] == 'value1'
- server.server.metadata['key2'] == 'value2'
- server_network in server.server.addresses
- server.server.security_groups|map(attribute='name')|list == ['default']
- name: Get info about all servers
openstack.cloud.server_info:
cloud: "{{ cloud }}"
@ -22,14 +82,16 @@
- name: Check info about servers
assert:
that:
info.openstack_servers|length > 0
- info.servers|length > 0
# allow new fields to be introduced but prevent fields from being removed
- expected_fields|difference(info.servers[0].keys())|length == 0
- name: Delete server with meta as CSV
openstack.cloud.server:
cloud: "{{ cloud }}"
state: absent
name: "{{ server_name }}"
wait: true
cloud: "{{ cloud }}"
state: absent
name: "{{ server_name }}"
wait: true
- name: Get info about all servers
openstack.cloud.server_info:
@ -39,21 +101,21 @@
- name: Check info about no servers
assert:
that:
info.openstack_servers|length == 0
- info.servers|length == 0
- name: Create server with meta as dict
openstack.cloud.server:
cloud: "{{ cloud }}"
state: present
name: "{{ server_name }}"
image: "{{ image }}"
flavor: "{{ flavor }}"
auto_floating_ip: false
network: "{{ server_network }}"
meta:
key1: value1
key2: value2
wait: true
cloud: "{{ cloud }}"
state: present
name: "{{ server_name }}"
image: "{{ image }}"
flavor: "{{ flavor }}"
auto_ip: false
network: "{{ server_network }}"
metadata:
key1: value1
key2: value2
wait: true
register: server
- debug: var=server
@ -67,26 +129,66 @@
- name: Check info about server name
assert:
that:
info.openstack_servers[0].name == "{{ server_name }}"
- info.servers[0].name == "{{ server_name }}"
- info.servers[0].id == server.server.id
- name: Filter servers
openstack.cloud.server_info:
cloud: "{{ cloud }}"
filters:
id: "{{ server.server.id }}"
metadata:
key1: value1
key2: value2
register: info
- name: Check filter results
assert:
that: info.servers|map(attribute='id')|list == [server.server.id]
- name: Filter servers with partial data
openstack.cloud.server_info:
cloud: "{{ cloud }}"
filters:
id: "{{ server.server.id }}"
metadata:
key1: value1
# intentially left out parts of metadata here
register: info
- name: Check filter results
assert:
that: info.servers|map(attribute='id')|list == [server.server.id]
- name: Filter servers which should not return results
openstack.cloud.server_info:
cloud: "{{ cloud }}"
filters:
id: "THIS_IS_NOT_A_VALID_ID"
register: info
- name: Check filter results
assert:
that: info.servers|length == 0
- name: Delete server with meta as dict
openstack.cloud.server:
cloud: "{{ cloud }}"
state: absent
name: "{{ server_name }}"
wait: true
cloud: "{{ cloud }}"
state: absent
name: "{{ server_name }}"
wait: true
- name: Create server (FIP from pool/network)
openstack.cloud.server:
cloud: "{{ cloud }}"
state: present
name: "{{ server_name }}"
image: "{{ image }}"
flavor: "{{ flavor }}"
network: "{{ server_network }}"
floating_ip_pools:
- "{{ floating_ip_pool_name }}"
wait: true
cloud: "{{ cloud }}"
state: present
name: "{{ server_name }}"
image: "{{ image }}"
flavor: "{{ flavor }}"
network: "private"
floating_ip_pools:
- "{{ floating_ip_pool_name }}"
wait: true
register: server
- debug: var=server
@ -97,52 +199,59 @@
server: "{{ server_name }}"
detailed: true
register: info
# TODO: Drop ignore_errors once openstacksdk's bug #2010135 has been solved.
# Ref.: https://storyboard.openstack.org/#!/story/2010135
ignore_errors: yes
- name: Check info about server image name
assert:
that:
info.openstack_servers[0].image.name == "{{ image }}"
- info.servers[0].image.name == "{{ image }}"
# TODO: Drop ignore_errors once openstacksdk's bug #2010135 has been solved.
# Ref.: https://storyboard.openstack.org/#!/story/2010135
ignore_errors: yes
- name: Delete server (FIP from pool/network)
openstack.cloud.server:
cloud: "{{ cloud }}"
state: absent
name: "{{ server_name }}"
wait: true
cloud: "{{ cloud }}"
state: absent
name: "{{ server_name }}"
wait: true
- name: Create server from volume
openstack.cloud.server:
cloud: "{{ cloud }}"
state: present
name: "{{ server_name }}"
image: "{{ image }}"
flavor: "{{ flavor }}"
network: "{{ server_network }}"
auto_floating_ip: false
boot_from_volume: true
volume_size: "{{ boot_volume_size }}"
terminate_volume: true
wait: true
cloud: "{{ cloud }}"
state: present
name: "{{ server_name }}"
image: "{{ image }}"
flavor: "{{ flavor }}"
network: "{{ server_network }}"
auto_ip: false
boot_from_volume: true
volume_size: "{{ boot_volume_size }}"
terminate_volume: true
wait: true
register: server
- debug: var=server
- name: Delete server with volume
openstack.cloud.server:
cloud: "{{ cloud }}"
state: absent
name: "{{ server_name }}"
wait: true
cloud: "{{ cloud }}"
state: absent
name: "{{ server_name }}"
wait: true
- name: Create a minimal server
openstack.cloud.server:
cloud: "{{ cloud }}"
state: present
name: "{{ server_name }}"
image: "{{ image }}"
flavor: "{{ flavor }}"
network: "{{ server_network }}"
auto_floating_ip: false
wait: true
cloud: "{{ cloud }}"
state: present
name: "{{ server_name }}"
image: "{{ image }}"
flavor: "{{ flavor }}"
network: "{{ server_network }}"
auto_ip: false
wait: true
register: server
- debug: var=server
@ -155,8 +264,7 @@
- name: Check info about servers in all projects
assert:
that:
info.openstack_servers|length > 0
that: info.servers|length > 0
- name: Get info about one server in all projects
openstack.cloud.server_info:
@ -167,14 +275,174 @@
- name: Check info about one server in all projects
assert:
that:
info.openstack_servers|length > 0
that: info.servers|length > 0
- name: Delete minimal server
openstack.cloud.server:
cloud: "{{ cloud }}"
state: absent
name: "{{ server_name }}"
wait: true
cloud: "{{ cloud }}"
state: absent
name: "{{ server_name }}"
wait: true
- include_tasks: server_actions.yml
- name: Create port to be attached to server
openstack.cloud.port:
cloud: "{{ cloud }}"
state: present
name: "{{ server_port }}"
network: "{{ server_network }}"
no_security_groups: yes
fixed_ips:
- ip_address: 192.168.0.42
register: port
- name: Create server which will be updated
openstack.cloud.server:
auto_ip: false
cloud: "{{ cloud }}"
# TODO: Uncomment once openstacksdk with support for
# description parameter has been released to PyPI.
# Ref.: https://review.opendev.org/c/openstack/openstacksdk/+/850671
#description: "This is a server"
flavor: "{{ flavor }}"
image: "{{ image }}"
metadata:
key1: value1
key2: value2
name: "{{ server_name }}"
nics:
- net-name: 'public'
- net-name: "{{ server_network }}"
- port-id: '{{ port.port.id }}'
state: present
wait: true
register: server
- debug: var=server
- name: Update server
openstack.cloud.server:
auto_ip: true
cloud: "{{ cloud }}"
description: "This server got updated"
# flavor cannot be updated but must be present
flavor: "{{ flavor }}"
# image cannot be updated but must be present
image: "{{ image }}"
metadata:
key2: value2
key3: value3
name: "{{ server_name }}"
# nics cannot be updated
nics:
- net-name: 'public'
- net-name: "{{ server_network }}"
- port-id: '{{ port.port.id }}'
security_groups:
- '{{ server_security_group }}'
- '{{ server_alt_security_group }}'
state: present
wait: true
register: server_updated
- debug: var=server_updated
- name: Assert updated server
assert:
that:
- server.server.id == server_updated.server.id
- server_updated is changed
- server_updated.server.description == "This server got updated"
- "'key1' not in server_updated.server.metadata"
- server_updated.server.metadata['key2'] == 'value2'
- server_updated.server.metadata['key3'] == 'value3'
- server_updated.server.addresses.keys()|sort == [server_network,'public']
- server_updated.server.addresses[server_network]|length == 2
- server_updated.server.addresses.public|length > 0
- port.port.fixed_ips[0].ip_address in
server_updated.server.addresses[server_network]|map(attribute='addr')
- server_updated.server.security_groups|map(attribute='name')|unique|length == 2
- security_group.secgroup.name in server_updated.server.security_groups|map(attribute='name')
- security_group_alt.secgroup.name in server_updated.server.security_groups|map(attribute='name')
- name: Update server again
openstack.cloud.server:
auto_ip: true
cloud: "{{ cloud }}"
description: "This server got updated"
# flavor cannot be updated but must be present
flavor: "{{ flavor }}"
# image cannot be updated but must be present
image: "{{ image }}"
metadata:
key2: value2
key3: value3
name: "{{ server_name }}"
# nics cannot be updated
nics:
- net-name: 'public'
- net-name: "{{ server_network }}"
- port-id: '{{ port.port.id }}'
security_groups:
- '{{ server_security_group }}'
- '{{ server_alt_security_group }}'
state: present
wait: true
register: server_again
- name: Assert server did not change
assert:
that:
- server.server.id == server_again.server.id
- server_again is not changed
- name: Delete updated server
openstack.cloud.server:
cloud: "{{ cloud }}"
delete_ips: yes
name: "{{ server_name }}"
state: absent
wait: true
- name: Delete port which was attached to server
openstack.cloud.port:
cloud: "{{ cloud }}"
state: absent
name: "{{ server_port }}"
- name: Delete second security group for server
openstack.cloud.security_group:
cloud: "{{ cloud }}"
state: absent
name: "{{ server_alt_security_group }}"
- name: Delete security group for server
openstack.cloud.security_group:
cloud: "{{ cloud }}"
state: absent
name: "{{ server_security_group }}"
- name: Delete second subnet for server
openstack.cloud.subnet:
cloud: "{{ cloud }}"
state: absent
name: "{{ server_alt_subnet }}"
- name: Delete second network for server
openstack.cloud.network:
cloud: "{{ cloud }}"
state: absent
name: "{{ server_alt_network }}"
- name: Delete subnet for server
openstack.cloud.subnet:
cloud: "{{ cloud }}"
state: absent
name: "{{ server_subnet }}"
- name: Delete network for server
openstack.cloud.network:
cloud: "{{ cloud }}"
state: absent
name: "{{ server_network }}"
- import_tasks: server_actions.yml

View File

@ -1,3 +1,20 @@
---
- name: Create network for server
openstack.cloud.network:
cloud: "{{ cloud }}"
name: "{{ server_network }}"
state: present
register: network
- name: Create subnet for server
openstack.cloud.subnet:
cidr: 192.168.0.0/24
cloud: "{{ cloud }}"
name: "{{ server_subnet }}"
network_name: "{{ server_network }}"
state: present
register: subnet
- name: Create server
openstack.cloud.server:
cloud: "{{ cloud }}"
@ -19,7 +36,7 @@
- name: Ensure status for server is ACTIVE
assert:
that:
- info1.openstack_servers.0.status == 'ACTIVE'
- info1.servers.0.status == 'ACTIVE'
- name: Stop server
openstack.cloud.server_action:
@ -38,7 +55,7 @@
- name: Ensure status for server is SHUTOFF
assert:
that:
- info2.openstack_servers.0.status == 'SHUTOFF'
- info2.servers.0.status == 'SHUTOFF'
- server is changed
- name: Stop server again
@ -58,7 +75,7 @@
- name: Ensure status for server is SHUTOFF
assert:
that:
- info3.openstack_servers.0.status == 'SHUTOFF'
- info3.servers.0.status == 'SHUTOFF'
- server is not changed
- name: Start server
@ -78,7 +95,7 @@
- name: Ensure status for server is ACTIVE
assert:
that:
- info4.openstack_servers.0.status == 'ACTIVE'
- info4.servers.0.status == 'ACTIVE'
- server is changed
- name: Start server again
@ -98,7 +115,7 @@
- name: Ensure status for server is ACTIVE
assert:
that:
- info5.openstack_servers.0.status == 'ACTIVE'
- info5.servers.0.status == 'ACTIVE'
- server is not changed
- name: Pause server
@ -118,7 +135,7 @@
- name: Ensure status for server is PAUSED
assert:
that:
- info6.openstack_servers.0.status == 'PAUSED'
- info6.servers.0.status == 'PAUSED'
- server is changed
- name: Pause server again
@ -138,7 +155,7 @@
- name: Ensure status for server is PAUSED
assert:
that:
- info7.openstack_servers.0.status == 'PAUSED'
- info7.servers.0.status == 'PAUSED'
- server is not changed
- name: Unpause server
@ -158,7 +175,7 @@
- name: Ensure status for server is ACTIVE
assert:
that:
- info8.openstack_servers.0.status == 'ACTIVE'
- info8.servers.0.status == 'ACTIVE'
- server is changed
- name: Unpause server again
@ -178,7 +195,7 @@
- name: Ensure status for server is ACTIVE
assert:
that:
- info9.openstack_servers.0.status == 'ACTIVE'
- info9.servers.0.status == 'ACTIVE'
- server is not changed
- name: Lock server
@ -198,7 +215,7 @@
- name: Ensure status for server is ACTIVE
assert:
that:
- info10.openstack_servers.0.status == 'ACTIVE'
- info10.servers.0.status == 'ACTIVE'
# not in all versions 'locked' is supported
- >-
(info10.openstack_server[0]['locked'] is defined and
@ -223,7 +240,7 @@
- name: Ensure status for server is ACTIVE
assert:
that:
- info11.openstack_servers.0.status == 'ACTIVE'
- info11.servers.0.status == 'ACTIVE'
# not in all versions 'locked' is supported
- >-
(info11.openstack_server[0]['locked'] is defined and
@ -248,7 +265,7 @@
- name: Ensure status for server is ACTIVE
assert:
that:
- info12.openstack_servers.0.status == 'ACTIVE'
- info12.servers.0.status == 'ACTIVE'
# not in all versions 'locked' is supported
- >-
(info12.openstack_server[0]['locked'] is defined and
@ -273,7 +290,7 @@
- name: Ensure status for server is ACTIVE
assert:
that:
- info13.openstack_servers.0.status == 'ACTIVE'
- info13.servers.0.status == 'ACTIVE'
- server is changed # no support for unlock idempotency
# not in all versions 'locked' is supported
- >-
@ -298,7 +315,7 @@
- name: Ensure status for server is SUSPENDED
assert:
that:
- info14.openstack_servers.0.status == 'SUSPENDED'
- info14.servers.0.status == 'SUSPENDED'
- server is changed
- name: Suspend server again
@ -318,7 +335,7 @@
- name: Ensure status for server is SUSPENDED
assert:
that:
- info15.openstack_servers.0.status == 'SUSPENDED'
- info15.servers.0.status == 'SUSPENDED'
- server is not changed
- name: Resume server
@ -338,7 +355,7 @@
- name: Ensure status for server is ACTIVE
assert:
that:
- info16.openstack_servers.0.status == 'ACTIVE'
- info16.servers.0.status == 'ACTIVE'
- server is changed
- name: Resume server again
@ -358,7 +375,7 @@
- name: Ensure status for server is ACTIVE
assert:
that:
- info17.openstack_servers.0.status == 'ACTIVE'
- info17.servers.0.status == 'ACTIVE'
- server is not changed
- name: Rebuild server - error
@ -394,7 +411,7 @@
- name: Ensure status for server is ACTIVE
assert:
that:
- info18.openstack_servers.0.status in ('ACTIVE', 'REBUILD')
- info18.servers.0.status in ('ACTIVE', 'REBUILD')
- server is changed
- name: Rebuild server with admin password
@ -416,7 +433,7 @@
- name: Ensure status for server is ACTIVE
assert:
that:
- info19.openstack_servers.0.status in ('ACTIVE', 'REBUILD')
- info19.servers.0.status in ('ACTIVE', 'REBUILD')
- server is changed
- name: Shelve server
@ -436,7 +453,7 @@
- name: Ensure status for server is SHELVED or SHELVED_OFFLOADED
assert:
that:
- info20.openstack_servers.0.status in ['SHELVED', 'SHELVED_OFFLOADED']
- info20.servers.0.status in ['SHELVED', 'SHELVED_OFFLOADED']
- server is changed
- name: Shelve offload server
@ -457,7 +474,7 @@
# no change if server has been offloaded automatically after first shelve command
assert:
that:
- info21.openstack_servers.0.status == 'SHELVED_OFFLOADED'
- info21.servers.0.status == 'SHELVED_OFFLOADED'
- name: Shelve offload server again
openstack.cloud.server_action:
@ -476,7 +493,7 @@
- name: Ensure status for server is SHELVED_OFFLOADED
assert:
that:
- info22.openstack_servers.0.status == 'SHELVED_OFFLOADED'
- info22.servers.0.status == 'SHELVED_OFFLOADED'
- server is not changed
- name: Unshelve server
@ -496,7 +513,7 @@
- name: Ensure status for server is ACTIVE
assert:
that:
- info23.openstack_servers.0.status == 'ACTIVE'
- info23.servers.0.status == 'ACTIVE'
- server is changed
- name: Unshelve server again
@ -516,9 +533,16 @@
- name: Ensure status for server is ACTIVE
assert:
that:
- info24.openstack_servers.0.status == 'ACTIVE'
- info24.servers.0.status == 'ACTIVE'
- server is not changed
- name: Delete server
openstack.cloud.server:
cloud: "{{ cloud }}"
name: "{{ server_name }}"
state: absent
wait: true
- name: Create network for alternate server
openstack.cloud.network:
cloud: "{{ cloud_alt }}"
@ -554,7 +578,7 @@
- name: Ensure status for server in alternate project is ACTIVE
assert:
that:
- info25.openstack_servers.0.status == 'ACTIVE'
- info25.servers.0.status == 'ACTIVE'
- name: Try to stop server in alternate project
openstack.cloud.server_action:
@ -589,7 +613,7 @@
- name: Ensure status for server is SHUTOFF
assert:
that:
- info26.openstack_servers.0.status == 'SHUTOFF'
- info26.servers.0.status == 'SHUTOFF'
- server_alt is changed
- name: Delete server in alternate project
@ -610,3 +634,15 @@
cloud: "{{ cloud_alt }}"
name: "{{ server_alt_network }}"
state: absent
- name: Delete subnet for server
openstack.cloud.subnet:
cloud: "{{ cloud }}"
state: absent
name: "{{ server_subnet }}"
- name: Delete network for server
openstack.cloud.network:
cloud: "{{ cloud }}"
state: absent
name: "{{ server_network }}"

View File

@ -86,10 +86,6 @@ options:
choices: [ admin, internal, public ]
default: public
aliases: [ endpoint_type ]
availability_zone:
description:
- Ignored. Present for backwards compatibility
type: str
sdk_log_path:
description:
- Path to the logfile of the OpenStackSDK. If empty no log is written

View File

@ -46,7 +46,6 @@ import importlib
import os
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.six import iteritems
OVERRIDES = {}
@ -73,7 +72,6 @@ def openstack_argument_spec():
login_username=dict(default=OS_USERNAME),
auth_url=dict(default=OS_AUTH_URL),
region_name=dict(default=OS_REGION_NAME),
availability_zone=dict(),
)
if OS_PASSWORD:
spec['login_password'] = dict(default=OS_PASSWORD)
@ -86,26 +84,12 @@ def openstack_argument_spec():
return spec
def openstack_find_nova_addresses(addresses, ext_tag, key_name=None):
ret = []
for (k, v) in iteritems(addresses):
if key_name and k == key_name:
ret.extend([addrs['addr'] for addrs in v])
else:
for interface_spec in v:
if 'OS-EXT-IPS:type' in interface_spec and interface_spec['OS-EXT-IPS:type'] == ext_tag:
ret.append(interface_spec['addr'])
return ret
def openstack_full_argument_spec(**kwargs):
spec = dict(
cloud=dict(type='raw'),
auth_type=dict(),
auth=dict(type='dict', no_log=True),
region_name=dict(),
availability_zone=dict(),
validate_certs=dict(type='bool', aliases=['verify']),
ca_cert=dict(aliases=['cacert']),
client_cert=dict(aliases=['cert']),

File diff suppressed because it is too large Load Diff

View File

@ -14,10 +14,11 @@ description:
notes:
- The result contains a list of servers.
options:
server:
name:
description:
- restrict results to servers with names or UUID matching
this glob expression (e.g., <web*>).
this glob expression such as web*.
aliases: ['server']
type: str
detailed:
description:
@ -26,9 +27,10 @@ options:
type: bool
default: 'no'
filters:
description:
- restrict results to servers matching a dictionary of
filters
description: |
Used for further filtering of results. Either a string containing a
JMESPath expression or a dictionary of meta data. Elements of the latter
may, themselves, be dictionaries.
type: dict
all_projects:
description:
@ -45,15 +47,316 @@ extends_documentation_fragment:
'''
EXAMPLES = '''
# Gather information about all servers named <web*> that are in an active state:
- openstack.cloud.server_info:
cloud: rax-dfw
server: web*
- name: Gather information about all 'web*' servers in active state
openstack.cloud.server_info:
cloud: devstack
name: web*
filters:
vm_state: active
register: result
- debug:
msg: "{{ result.openstack_servers }}"
- name: Filter servers with nested dictionaries
openstack.cloud.server_info:
cloud: devstack
filters:
metadata:
key1: value1
key2: value2
'''
RETURN = '''
servers:
description: List of servers matching the filters
elements: dict
type: list
returned: always
contains:
access_ipv4:
description: |
IPv4 address that should be used to access this server.
May be automatically set by the provider.
returned: success
type: str
access_ipv6:
description: |
IPv6 address that should be used to access this
server. May be automatically set by the provider.
returned: success
type: str
addresses:
description: |
A dictionary of addresses this server can be accessed through.
The dictionary contains keys such as 'private' and 'public',
each containing a list of dictionaries for addresses of that
type. The addresses are contained in a dictionary with keys
'addr' and 'version', which is either 4 or 6 depending on the
protocol of the IP address.
returned: success
type: dict
admin_password:
description: |
When a server is first created, it provides the administrator
password.
returned: success
type: str
attached_volumes:
description: |
A list of an attached volumes. Each item in the list contains
at least an 'id' key to identify the specific volumes.
returned: success
type: list
availability_zone:
description: |
The name of the availability zone this server is a part of.
returned: success
type: str
block_device_mapping:
description: |
Enables fine grained control of the block device mapping for an
instance. This is typically used for booting servers from
volumes.
returned: success
type: str
compute_host:
description: |
The name of the compute host on which this instance is running.
Appears in the response for administrative users only.
returned: success
type: str
config_drive:
description: |
Indicates whether or not a config drive was used for this
server.
returned: success
type: str
created_at:
description: Timestamp of when the server was created.
returned: success
type: str
description:
description: |
The description of the server. Before microversion
2.19 this was set to the server name.
returned: success
type: str
disk_config:
description: The disk configuration. Either AUTO or MANUAL.
returned: success
type: str
flavor:
description: The flavor property as returned from server.
returned: success
type: dict
flavor_id:
description: |
The flavor reference, as a ID or full URL, for the flavor to
use for this server.
returned: success
type: str
has_config_drive:
description: |
Indicates whether a configuration drive enables metadata
injection. Not all cloud providers enable this feature.
returned: success
type: str
host_id:
description: An ID representing the host of this server.
returned: success
type: str
host_status:
description: The host status.
returned: success
type: str
hostname:
description: |
The hostname set on the instance when it is booted.
By default, it appears in the response for administrative users
only.
returned: success
type: str
hypervisor_hostname:
description: |
The hypervisor host name. Appears in the response for
administrative users only.
returned: success
type: str
id:
description: ID of the server.
returned: success
type: str
image:
description: The image property as returned from server.
returned: success
type: dict
image_id:
description: |
The image reference, as a ID or full URL, for the image to use
for this server.
returned: success
type: str
instance_name:
description: |
The instance name. The Compute API generates the instance name
from the instance name template. Appears in the response for
administrative users only.
returned: success
type: str
is_locked:
description: The locked status of the server
returned: success
type: bool
kernel_id:
description: |
The UUID of the kernel image when using an AMI. Will be null if
not. By default, it appears in the response for administrative
users only.
returned: success
type: str
key_name:
description: The name of an associated keypair.
returned: success
type: str
launch_index:
description: |
When servers are launched via multiple create, this is the
sequence in which the servers were launched. By default, it
appears in the response for administrative users only.
returned: success
type: int
launched_at:
description: The timestamp when the server was launched.
returned: success
type: str
links:
description: |
A list of dictionaries holding links relevant to this server.
returned: success
type: str
max_count:
description: The maximum number of servers to create.
returned: success
type: str
metadata:
description: List of tag strings.
returned: success
type: dict
min_count:
description: The minimum number of servers to create.
returned: success
type: str
name:
description: Name of the server
returned: success
type: str
networks:
description: |
A networks object. Required parameter when there are multiple
networks defined for the tenant. When you do not specify the
networks parameter, the server attaches to the only network
created for the current tenant.
returned: success
type: str
power_state:
description: The power state of this server.
returned: success
type: str
progress:
description: |
While the server is building, this value represents the
percentage of completion. Once it is completed, it will be 100.
returned: success
type: int
project_id:
description: The ID of the project this server is associated with.
returned: success
type: str
ramdisk_id:
description: |
The UUID of the ramdisk image when using an AMI. Will be null
if not. By default, it appears in the response for
administrative users only.
returned: success
type: str
reservation_id:
description: |
The reservation id for the server. This is an id that can be
useful in tracking groups of servers created with multiple
create, that will all have the same reservation_id. By default,
it appears in the response for administrative users only.
returned: success
type: str
root_device_name:
description: |
The root device name for the instance By default, it appears in
the response for administrative users only.
returned: success
type: str
scheduler_hints:
description: The dictionary of data to send to the scheduler.
returned: success
type: dict
security_groups:
description: |
A list of applicable security groups. Each group contains keys
for: description, name, id, and rules.
returned: success
type: list
elements: dict
server_groups:
description: |
The UUIDs of the server groups to which the server belongs.
Currently this can contain at most one entry.
returned: success
type: list
status:
description: |
The state this server is in. Valid values include 'ACTIVE',
'BUILDING', 'DELETED', 'ERROR', 'HARD_REBOOT', 'PASSWORD',
'PAUSED', 'REBOOT', 'REBUILD', 'RESCUED', 'RESIZED',
'REVERT_RESIZE', 'SHUTOFF', 'SOFT_DELETED', 'STOPPED',
'SUSPENDED', 'UNKNOWN', or 'VERIFY_RESIZE'.
returned: success
type: str
tags:
description: A list of associated tags.
returned: success
type: list
task_state:
description: The task state of this server.
returned: success
type: str
terminated_at:
description: |
The timestamp when the server was terminated (if it has been).
returned: success
type: str
trusted_image_certificates:
description: |
A list of trusted certificate IDs, that were used during image
signature verification to verify the signing certificate.
returned: success
type: list
updated_at:
description: Timestamp of when this server was last updated.
returned: success
type: str
user_data:
description: |
Configuration information or scripts to use upon launch.
Base64 encoded.
returned: success
type: str
user_id:
description: The ID of the owners of this server.
returned: success
type: str
vm_state:
description: The VM state of this server.
returned: success
type: str
volumes:
description: Same as attached_volumes.
returned: success
type: list
'''
from ansible_collections.openstack.cloud.plugins.module_utils.openstack import OpenStackModule
@ -62,7 +365,7 @@ from ansible_collections.openstack.cloud.plugins.module_utils.openstack import O
class ServerInfoModule(OpenStackModule):
argument_spec = dict(
server=dict(),
name=dict(aliases=['server']),
detailed=dict(type='bool', default=False),
filters=dict(type='dict'),
all_projects=dict(type='bool', default=False),
@ -72,16 +375,14 @@ class ServerInfoModule(OpenStackModule):
)
def run(self):
kwargs = dict((k, self.params[k])
for k in ['detailed', 'filters', 'all_projects']
if self.params[k] is not None)
kwargs['name_or_id'] = self.params['name']
kwargs = self.check_versioned(
detailed=self.params['detailed'],
filters=self.params['filters'],
all_projects=self.params['all_projects']
)
if self.params['server']:
kwargs['name_or_id'] = self.params['server']
openstack_servers = self.conn.search_servers(**kwargs)
self.exit(changed=False, openstack_servers=openstack_servers)
self.exit(changed=False,
servers=[server.to_dict(computed=False) for server in
self.conn.search_servers(**kwargs)])
def main():

View File

@ -31,11 +31,6 @@ options:
choices: [present, absent]
default: present
type: str
availability_zone:
description:
- Availability zone in which to create the snapshot.
required: false
type: str
requirements:
- "python >= 3.6"
- "openstacksdk"

View File

@ -12,6 +12,10 @@ author: OpenStack Ansible SIG
description:
- Create or Remove cinder block storage volumes
options:
availability_zone:
description:
- The availability zone.
type: str
size:
description:
- Size of volume in GB. This parameter is required when the
@ -106,6 +110,7 @@ from ansible_collections.openstack.cloud.plugins.module_utils.openstack import O
class VolumeModule(OpenStackModule):
argument_spec = dict(
availability_zone=dict(type='str'),
size=dict(type='int'),
volume_type=dict(),
display_name=dict(required=True, aliases=['name']),