openstack-ansible-ops/ansible_tools/playbooks/remove_compute_node.yml
Vaishali Pavashe 47cde0a9c9 Remove neutron agent task fails to loop through multiple agents.
Change-Id: I58150d2607a37fcb3d6d7a52ec4d7a88177f676a
2017-08-15 14:49:29 -04:00

63 lines
2.5 KiB
YAML

---
# Copyright 2014, Rackspace US, Inc.
#
# 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.
- name: Remove a compute node from the OSA environment
hosts: utility[0]
user: root
pre_tasks:
- name: Fail if host_to_be_removed is not defined
fail:
msg: "host_to_be_removed must be defined as ansible user variable"
when: host_to_be_removed is not defined
- name: Find ID of the nova-compute service we want to remove
shell: |
. {{ ansible_env.HOME }}/openrc
openstack compute service list | grep {{ host_to_be_removed }} | awk '{print $2}'
register: results
changed_when: results.rc == 0 and results.stdout_lines|length > 0
failed_when: results.rc > 0 or results.stdout_lines|length == 0
- name: Find ID of the neutron agent service we want to remove
shell: |
. {{ ansible_env.HOME }}/openrc
neutron agent-list | grep {{ host_to_be_removed }} | awk '{print $2}'
register: neutron_agent_list_results
changed_when: neutron_agent_list_results.rc == 0
failed_when: neutron_agent_list_results.rc > 0
tasks:
- name: Remove the nova-compute service from compute node
shell: |
. {{ ansible_env.HOME }}/openrc
openstack compute service delete {{ results.stdout }}
register: compute_delete_result
changed_when: compute_delete_result.rc
failed_when: compute_delete_result.rc > 0
- name: Remove neutron agent service on {{ host_to_be_removed }}
shell: |
. {{ ansible_env.HOME }}/openrc
neutron agent-delete {{ item }}
with_items: "{{ neutron_agent_list_results.stdout_lines }}"
register: neutron_delete_results
changed_when: neutron_delete_results.rc == 0
failed_when: neutron_delete_results.rc > 0
- name: Delete the host from the OSA inventory file
shell: |
python /opt/openstack-ansible/scripts/inventory-manage.py -r {{ host_to_be_removed }}
register: inventory_manage_output
delegate_to: 127.0.0.1
connection: local
failed_when : inventory_manage_output.rc > 0