Merge "Add ansible playbook for removing compute"
This commit is contained in:
commit
a96cdc0152
6
ansible_tools/README.rst
Normal file
6
ansible_tools/README.rst
Normal file
@ -0,0 +1,6 @@
|
||||
OpenStack-Ansible Operator Ansible Tools
|
||||
========================================
|
||||
|
||||
These are Ansible playbooks and roles that are designed to
|
||||
help OSA operators perform various tasks against their OSA
|
||||
environment.
|
24
ansible_tools/playbooks/ansible.cfg
Normal file
24
ansible_tools/playbooks/ansible.cfg
Normal file
@ -0,0 +1,24 @@
|
||||
[defaults]
|
||||
# Additional plugins
|
||||
lookup_plugins = /etc/ansible/plugins/lookup
|
||||
filter_plugins = /etc/ansible/plugins/filter
|
||||
action_plugins = /etc/ansible/plugins/action
|
||||
library = /etc/ansible/plugins/library
|
||||
|
||||
# Fact caching
|
||||
gathering = smart
|
||||
fact_caching = jsonfile
|
||||
fact_caching_connection = /etc/openstack_deploy/ansible_facts
|
||||
fact_caching_timeout = 86400
|
||||
|
||||
inventory = /opt/openstack-ansible/playbooks/inventory
|
||||
host_key_checking = False
|
||||
|
||||
# Set color options
|
||||
nocolor = 0
|
||||
|
||||
# SSH timeout
|
||||
timeout = 120
|
||||
|
||||
[ssh_connection]
|
||||
pipelining = True
|
61
ansible_tools/playbooks/remove_compute_node.yml
Normal file
61
ansible_tools/playbooks/remove_compute_node.yml
Normal file
@ -0,0 +1,61 @@
|
||||
---
|
||||
# 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 {{ neutron_agent_list_results.stdout }}
|
||||
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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user