ansible-collections-openstack/ci/roles/server_action/tasks/main.yml
Rafael Castillo 778cf14f1b Refactored server_action module
Co-Authored-By: Jakob Meng <code@jakobmeng.de>
Change-Id: Ib9b7e26889123443a67b35e094deb3cadeb615fe
2023-01-19 08:54:40 +01:00

693 lines
16 KiB
YAML

---
- name: List all images
openstack.cloud.image_info:
cloud: "{{ cloud }}"
register: images
- name: Identify CirrOS image name
set_fact:
image_name: "{{ images.images|community.general.json_query(query)|first }}"
vars:
query: "[?starts_with(name, 'cirros')].name"
- name: Create network for server
openstack.cloud.network:
cloud: "{{ cloud }}"
name: ansible_server_network
state: present
register: network
- name: Create subnet for server
openstack.cloud.subnet:
cidr: 192.168.0.0/24
cloud: "{{ cloud }}"
name: ansible_server_subnet
network_name: ansible_server_network
state: present
register: subnet
- name: Create server
openstack.cloud.server:
cloud: "{{ cloud }}"
state: present
name: ansible_server
image: "{{ image_name }}"
flavor: m1.tiny
network: ansible_server_network
auto_floating_ip: false
wait: true
register: server
- name: Get info about server
openstack.cloud.server_info:
cloud: "{{ cloud }}"
server: ansible_server
register: servers
- name: Ensure status for server is ACTIVE
assert:
that:
- servers.servers.0.status == 'ACTIVE'
- name: Stop server
openstack.cloud.server_action:
cloud: "{{ cloud }}"
server: ansible_server
action: stop
wait: true
register: server
- name: Get info about server
openstack.cloud.server_info:
cloud: "{{ cloud }}"
server: ansible_server
register: servers
- name: Ensure status for server is SHUTOFF
assert:
that:
- servers.servers.0.status == 'SHUTOFF'
- server is changed
- name: Stop server again
openstack.cloud.server_action:
cloud: "{{ cloud }}"
server: ansible_server
action: stop
wait: true
register: server
- name: Get info about server
openstack.cloud.server_info:
cloud: "{{ cloud }}"
server: ansible_server
register: servers
- name: Ensure status for server is SHUTOFF
assert:
that:
- servers.servers.0.status == 'SHUTOFF'
- server is not changed
- name: Start server
openstack.cloud.server_action:
cloud: "{{ cloud }}"
server: ansible_server
action: start
wait: true
register: server
- name: Get info about server
openstack.cloud.server_info:
cloud: "{{ cloud }}"
server: ansible_server
register: servers
- name: Ensure status for server is ACTIVE
assert:
that:
- servers.servers.0.status == 'ACTIVE'
- server is changed
- name: Start server again
openstack.cloud.server_action:
cloud: "{{ cloud }}"
server: ansible_server
action: start
wait: true
register: server
- name: Get info about server
openstack.cloud.server_info:
cloud: "{{ cloud }}"
server: ansible_server
register: servers
- name: Ensure status for server is ACTIVE
assert:
that:
- servers.servers.0.status == 'ACTIVE'
- server is not changed
- name: Pause server
openstack.cloud.server_action:
cloud: "{{ cloud }}"
server: ansible_server
action: pause
wait: true
register: server
- name: Get info about server
openstack.cloud.server_info:
cloud: "{{ cloud }}"
server: ansible_server
register: servers
- name: Ensure status for server is PAUSED
assert:
that:
- servers.servers.0.status == 'PAUSED'
- server is changed
- name: Pause server again
openstack.cloud.server_action:
cloud: "{{ cloud }}"
server: ansible_server
action: pause
wait: true
register: server
- name: Get info about server
openstack.cloud.server_info:
cloud: "{{ cloud }}"
server: ansible_server
register: servers
- name: Ensure status for server is PAUSED
assert:
that:
- servers.servers.0.status == 'PAUSED'
- server is not changed
- name: Unpause server
openstack.cloud.server_action:
cloud: "{{ cloud }}"
server: ansible_server
action: unpause
wait: true
register: server
- name: Get info about server
openstack.cloud.server_info:
cloud: "{{ cloud }}"
server: ansible_server
register: servers
- name: Ensure status for server is ACTIVE
assert:
that:
- servers.servers.0.status == 'ACTIVE'
- server is changed
- name: Unpause server again
openstack.cloud.server_action:
cloud: "{{ cloud }}"
server: ansible_server
action: unpause
wait: true
register: server
- name: Get info about server
openstack.cloud.server_info:
cloud: "{{ cloud }}"
server: ansible_server
register: servers
- name: Ensure status for server is ACTIVE
assert:
that:
- servers.servers.0.status == 'ACTIVE'
- server is not changed
- name: Lock server
openstack.cloud.server_action:
cloud: "{{ cloud }}"
server: ansible_server
action: lock
wait: true
register: server
- name: Get info about server
openstack.cloud.server_info:
cloud: "{{ cloud }}"
server: ansible_server
register: servers
- name: Ensure status for server is ACTIVE
assert:
that:
- servers.servers.0.status == 'ACTIVE'
- servers.servers.0.is_locked
- server is changed
- name: Lock server again
openstack.cloud.server_action:
cloud: "{{ cloud }}"
server: ansible_server
action: lock
wait: true
register: server
- name: Get info about server
openstack.cloud.server_info:
cloud: "{{ cloud }}"
server: ansible_server
register: servers
- name: Ensure status for server is ACTIVE
assert:
that:
- servers.servers.0.status == 'ACTIVE'
- servers.servers.0.is_locked
- server is not changed
- name: Unock server
openstack.cloud.server_action:
cloud: "{{ cloud }}"
server: ansible_server
action: unlock
wait: true
register: server
- name: Get info about server
openstack.cloud.server_info:
cloud: "{{ cloud }}"
server: ansible_server
register: servers
- name: Ensure status for server is ACTIVE
assert:
that:
- servers.servers.0.status == 'ACTIVE'
- not servers.servers.0.is_locked
- server is changed
- name: Unlock server again
openstack.cloud.server_action:
cloud: "{{ cloud }}"
server: ansible_server
action: unlock
wait: true
register: server
- name: Get info about server
openstack.cloud.server_info:
cloud: "{{ cloud }}"
server: ansible_server
register: servers
- name: Ensure status for server is ACTIVE
assert:
that:
- servers.servers.0.status == 'ACTIVE'
- server is not changed
- not servers.servers.0.is_locked
- name: Suspend server
openstack.cloud.server_action:
cloud: "{{ cloud }}"
server: ansible_server
action: suspend
wait: true
register: server
- name: Get info about server
openstack.cloud.server_info:
cloud: "{{ cloud }}"
server: ansible_server
register: servers
- name: Ensure status for server is SUSPENDED
assert:
that:
- servers.servers.0.status == 'SUSPENDED'
- server is changed
- name: Suspend server again
openstack.cloud.server_action:
cloud: "{{ cloud }}"
server: ansible_server
action: suspend
wait: true
register: server
- name: Get info about server
openstack.cloud.server_info:
cloud: "{{ cloud }}"
server: ansible_server
register: servers
- name: Ensure status for server is SUSPENDED
assert:
that:
- servers.servers.0.status == 'SUSPENDED'
- server is not changed
- name: Resume server
openstack.cloud.server_action:
cloud: "{{ cloud }}"
server: ansible_server
action: resume
wait: true
register: server
- name: Get info about server
openstack.cloud.server_info:
cloud: "{{ cloud }}"
server: ansible_server
register: servers
- name: Ensure status for server is ACTIVE
assert:
that:
- servers.servers.0.status == 'ACTIVE'
- server is changed
- name: Resume server again
openstack.cloud.server_action:
cloud: "{{ cloud }}"
server: ansible_server
action: resume
wait: true
register: server
- name: Get info about server
openstack.cloud.server_info:
cloud: "{{ cloud }}"
server: ansible_server
register: servers
- name: Ensure status for server is ACTIVE
assert:
that:
- servers.servers.0.status == 'ACTIVE'
- server is not changed
- name: Rebuild server - error
openstack.cloud.server_action:
cloud: "{{ cloud }}"
server: ansible_server
action: rebuild
wait: true
register: server
ignore_errors: true
- name: Ensure server rebuild failed
assert:
that:
- server is failed
- "'missing: image' in server.msg "
- name: Rebuild server
openstack.cloud.server_action:
cloud: "{{ cloud }}"
server: ansible_server
image: "{{ image_name }}"
action: rebuild
wait: true
register: server
- name: Get info about server
openstack.cloud.server_info:
cloud: "{{ cloud }}"
server: ansible_server
register: servers
- name: Ensure status for server is ACTIVE
assert:
that:
- servers.servers.0.status in ('ACTIVE', 'REBUILD')
- server is changed
- name: Rebuild server with admin password
openstack.cloud.server_action:
cloud: "{{ cloud }}"
server: ansible_server
image: "{{ image_name }}"
action: rebuild
wait: true
admin_password: random
register: server
- name: Get info about server
openstack.cloud.server_info:
cloud: "{{ cloud }}"
server: ansible_server
register: servers
- name: Ensure status for server is ACTIVE
assert:
that:
- servers.servers.0.status in ('ACTIVE', 'REBUILD')
- server is changed
- name: Shelve server
openstack.cloud.server_action:
cloud: "{{ cloud }}"
server: ansible_server
action: shelve
wait: true
register: server
- name: Get info about server
openstack.cloud.server_info:
cloud: "{{ cloud }}"
server: ansible_server
register: servers
- name: Ensure status for server is SHELVED or SHELVED_OFFLOADED
assert:
that:
- servers.servers.0.status in ['SHELVED', 'SHELVED_OFFLOADED']
- server is changed
- name: Shelve offload server
openstack.cloud.server_action:
cloud: "{{ cloud }}"
server: ansible_server
action: shelve_offload
wait: true
register: server
ignore_errors: true
- name: Assert shelve offload server
assert:
that:
- ((server is success)
or (server is not success
and "Cannot 'shelveOffload' instance" in server.msg
and "while it is in vm_state shelved_offloaded" in server.msg))
- name: Get info about server
openstack.cloud.server_info:
cloud: "{{ cloud }}"
server: ansible_server
register: servers
- name: Ensure status for server is SHELVED_OFFLOADED
# no change if server has been offloaded automatically after first shelve command
assert:
that:
- servers.servers.0.status == 'SHELVED_OFFLOADED'
- name: Shelve offload server again
openstack.cloud.server_action:
cloud: "{{ cloud }}"
server: ansible_server
action: shelve_offload
wait: true
register: server
- name: Get info about server
openstack.cloud.server_info:
cloud: "{{ cloud }}"
server: ansible_server
register: servers
- name: Ensure status for server is SHELVED_OFFLOADED
assert:
that:
- servers.servers.0.status == 'SHELVED_OFFLOADED'
- server is not changed
- name: Unshelve server
openstack.cloud.server_action:
cloud: "{{ cloud }}"
server: ansible_server
action: unshelve
wait: true
register: server
- name: Get info about server
openstack.cloud.server_info:
cloud: "{{ cloud }}"
server: ansible_server
register: servers
- name: Ensure status for server is ACTIVE
assert:
that:
- servers.servers.0.status == 'ACTIVE'
- server is changed
- name: Unshelve server again
openstack.cloud.server_action:
cloud: "{{ cloud }}"
server: ansible_server
action: unshelve
wait: true
register: server
- name: Get info about server
openstack.cloud.server_info:
cloud: "{{ cloud }}"
server: ansible_server
register: servers
- name: Ensure status for server is ACTIVE
assert:
that:
- servers.servers.0.status == 'ACTIVE'
- server is not changed
- name: Reboot server (SOFT)
openstack.cloud.server_action:
cloud: "{{ cloud }}"
server: ansible_server
action: reboot_soft
wait: true
register: server
- name: Get info about server
openstack.cloud.server_info:
cloud: "{{ cloud }}"
server: ansible_server
register: servers
- name: Ensure status for server is ACTIVE
assert:
that:
- servers.servers.0.status == 'ACTIVE'
- server is not changed
- name: Reboot server (HARD)
openstack.cloud.server_action:
cloud: "{{ cloud }}"
server: ansible_server
action: reboot_hard
wait: true
register: server
- name: Get info about server
openstack.cloud.server_info:
cloud: "{{ cloud }}"
server: ansible_server
register: servers
- name: Ensure status for server is ACTIVE
assert:
that:
- servers.servers.0.status == 'ACTIVE'
- server is not changed
- name: Delete server
openstack.cloud.server:
cloud: "{{ cloud }}"
name: ansible_server
state: absent
wait: true
- name: Create network for alternate server
openstack.cloud.network:
cloud: "{{ cloud_alt }}"
name: ansible_server_network2
state: present
- name: Create subnet for alternate server
openstack.cloud.subnet:
cloud: "{{ cloud_alt }}"
network_name: ansible_server_network2
name: ansible_server_subnet2
state: present
cidr: 192.168.0.0/24
- name: Create server in alternate project
openstack.cloud.server:
cloud: "{{ cloud_alt }}"
state: present
name: ansible_server2
image: "{{ image_name }}"
flavor: m1.tiny
network: ansible_server_network2
auto_floating_ip: false
wait: true
register: server
- name: Get info about server in alternate project
openstack.cloud.server_info:
cloud: "{{ cloud_alt }}"
server: ansible_server2
register: servers
- name: Ensure status for server in alternate project is ACTIVE
assert:
that:
- servers.servers.0.status == 'ACTIVE'
- name: Try to stop server in alternate project
openstack.cloud.server_action:
cloud: "{{ cloud }}"
server: ansible_server2
action: stop
wait: true
ignore_errors: true
register: server
- name: Ensure server was not stopped
assert:
that:
- server is failed
- server.msg == "No Server found for ansible_server2"
- name: Stop server in alternate project with all_projects=true
openstack.cloud.server_action:
cloud: "{{ cloud }}"
server: ansible_server2
action: stop
wait: true
all_projects: True
register: server
- name: Get info about server in alternate project
openstack.cloud.server_info:
cloud: "{{ cloud_alt }}"
server: ansible_server2
register: servers
- name: Ensure status for server is SHUTOFF
assert:
that:
- servers.servers.0.status == 'SHUTOFF'
- server is changed
- name: Delete server in alternate project
openstack.cloud.server:
cloud: "{{ cloud_alt }}"
state: absent
name: ansible_server2
wait: true
- name: Delete subnet for alternate server
openstack.cloud.subnet:
cloud: "{{ cloud_alt }}"
name: ansible_server_subnet2
state: absent
- name: Delete network for alternate server
openstack.cloud.network:
cloud: "{{ cloud_alt }}"
name: ansible_server_network2
state: absent
- name: Delete subnet for server
openstack.cloud.subnet:
cloud: "{{ cloud }}"
state: absent
name: ansible_server_subnet
- name: Delete network for server
openstack.cloud.network:
cloud: "{{ cloud }}"
state: absent
name: ansible_server_network