tripleo-ansible/playbooks/stop_vms.yml

57 lines
2.4 KiB
YAML

# Copyright (c) 2014 Hewlett-Packard Development Company, L.P.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
- service_facts:
when: instance_status == "ACTIVE"
- name: Ensure libvirt daemon is running
sudo: yes
service: name={{ item }} state=started enabled=yes
when: use_nova_powercontrol is not defined and item in existing_services
with_items: hypervisor_daemons
- name: Collect list of VMs
sudo: yes
virt: command=list_vms
register: virtual_machines
when: use_nova_powercontrol is not defined
- name: Issue graceful shutdowns
sudo: yes
virt: state=shutdown name={{item}}
when: use_nova_powercontrol is not defined
with_items: virtual_machines.list_vms
- name: Tell the cloud to shutdown via nova_powercontrol.
nova_powercontrol:
login_username: "{{ lookup('env',OC_OS_USERNAME'}}"
login_password: "{{ lookup('env',OC_OS_PASSWORD'}}"
login_tenant_name: "{{ lookup('env',OC_OS_TENANT_NAME'}}"
auth_url: "{{ lookup('env',OC_OS_AUTH_URL'}}"
all_instances: yes
state: stopped
when: use_nova_powercontrol is defined
- name: Pausing for 60 seconds to give VMs time to stop.
pause: seconds=60
- name: Collect list of VMs
sudo: yes
virt: command=list_vms
register: virtual_machines
when: use_nova_powercontrol is not defined
- name: Issue graceful shutdowns
sudo: yes
virt: state=shutdown name={{item}}
when: use_nova_powercontrol is not defined
with_items: virtual_machines.list_vms
register: test_from_second_shutdown_call
- name: "Fail if virtual machines were still running"
fail: msg="If the ansible playbook has failed and exited at this point, virtual machines were still running on the compute node after sixty seconds passed from the shutdown commands having been initiated. Please retry and/or manually ensure that virtual machines on the nodes to be updated have been shut down."
when: use_nova_powercontrol is not defined and test_from_second_shutdown_call.changed == true