diff --git a/tripleo_ansible/playbooks/cli-overcloud-restore-node.yml b/tripleo_ansible/playbooks/cli-overcloud-restore-node.yml new file mode 100644 index 000000000..84ebdb350 --- /dev/null +++ b/tripleo_ansible/playbooks/cli-overcloud-restore-node.yml @@ -0,0 +1,23 @@ +--- +# Copyright 2021 Red Hat, 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: TripleO Restore a node + hosts: Undercloud + remote_user: "{{ tripleo_target_user | default(lookup('env', 'USER')) }}" + tasks: + - name: Restore one node + include_role: + name: backup_and_restore + tasks_from: restore_node.yml diff --git a/tripleo_ansible/roles/backup_and_restore/defaults/main.yml b/tripleo_ansible/roles/backup_and_restore/defaults/main.yml index fe67b767d..4824c70ba 100644 --- a/tripleo_ansible/roles/backup_and_restore/defaults/main.yml +++ b/tripleo_ansible/roles/backup_and_restore/defaults/main.yml @@ -121,3 +121,18 @@ tripleo_backup_and_restore_ceph_mon_role: "ceph_mon" # The cephadm path tripleo_backup_and_restore_cephadm_path: "/usr/sbin/cephadm" + +# The name of the node to restore +tripleo_backup_and_restore_overcloud_restore_name: undercloud + +# Ironic images path +tripleo_backup_and_restore_ironic_images_path: "/var/lib/ironic/images" + +# Restore retries +tripleo_backup_and_restore_restore_retries: 300 + +# Restore delay +tripleo_backup_and_restore_restore_delay: 10 + +# Ironic subdirectory where the kernel and initrd are uploaded +backup_and_restore_history_path: "" diff --git a/tripleo_ansible/roles/backup_and_restore/tasks/restore_node.yml b/tripleo_ansible/roles/backup_and_restore/tasks/restore_node.yml new file mode 100644 index 000000000..f487df049 --- /dev/null +++ b/tripleo_ansible/roles/backup_and_restore/tasks/restore_node.yml @@ -0,0 +1,152 @@ +--- +# Copyright 2021 Red Hat, Inc. +# All Rights Reserved. +# +# 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: Get the name of the node + environment: + OS_CLOUD: undercloud + command: metalsmith -f value -c Hostname show {{ tripleo_backup_and_restore_overcloud_restore_name }} + register: instance_name + tags: + - bar_restore_image + +- name: Get metalsmith instance informartion + environment: + OS_CLOUD: undercloud + command: metalsmith -f json show {{ instance_name.stdout }} + register: instance_information + tags: + - bar_restore_image + +- name: Parse instance informatation + set_fact: + instance_information_json: "{{ instance_information.stdout | from_json }}" + tags: + - bar_restore_image + +- name: Get node name + set_fact: + node_name: "{{ instance_information_json[instance_name.stdout]['node']['name'] }}" + node_hostname: "{{ instance_name.stdout }}" + tags: + - bar_restore_image + +- name: Set kernel and initrd + set_fact: + restore_kernel: "{{ (backup_and_restore_history_path == '') | ternary(node_hostname, backup_and_restore_history_path+'/'+node_hostname) + '.kernel' }}" + restore_initrd: "{{ (backup_and_restore_history_path == '') | ternary(node_hostname, backup_and_restore_history_path+'/'+node_hostname) + '.initrd.cgz' }}" + tags: + - bar_restore_image + +- name: Power off node + environment: + OS_CLOUD: undercloud + command: openstack baremetal node power off {{ node_name }} + tags: + - bar_restore_image + +- name: Set node in maintenance + environment: + OS_CLOUD: undercloud + command: openstack baremetal node maintenance set {{ node_name }} + tags: + - bar_restore_image + +- name: Change node settings + environment: + OS_CLOUD: undercloud + command: openstack baremetal node set \ + --instance-info kernel=file://{{ tripleo_backup_and_restore_ironic_images_path }}/{{ restore_kernel }} \ + --instance-info ramdisk=file://{{ tripleo_backup_and_restore_ironic_images_path }}/{{ restore_initrd }} \ + --instance-info kernel_append_params="unattended" \ + --deploy-interface ramdisk \ + {{ node_name }} + tags: + - bar_restore_image + +- name: Unset node from maintenance + environment: + OS_CLOUD: undercloud + command: openstack baremetal node maintenance unset {{ node_name }} + tags: + - bar_restore_image + +- name: Rebuild node + environment: + OS_CLOUD: undercloud + command: openstack baremetal node rebuild {{ node_name }} + tags: + - bar_restore_image + +- name: Wait node is active + environment: + OS_CLOUD: undercloud + command: openstack baremetal node show {{ node_name }} --fields provision_state -f value + register: node_provision_state + retries: "{{ tripleo_backup_and_restore_restore_retries }}" + until: node_provision_state.stdout == 'active' + delay: "{{ tripleo_backup_and_restore_restore_delay }}" + tags: + - bar_restore_image + +- name: Wait node is power off + environment: + OS_CLOUD: undercloud + command: openstack baremetal node show {{ node_name }} --fields power_state -f value + register: node_power_status + retries: "{{ tripleo_backup_and_restore_restore_retries }}" + until: '"off" in node_power_status.stdout' + delay: "{{ tripleo_backup_and_restore_restore_delay }}" + tags: + - bar_restore_image + +- name: Set node to maintenance + environment: + OS_CLOUD: undercloud + command: openstack baremetal node maintenance set {{ node_name }} + tags: + - bar_restore_image + +- name: Change back configuration node + environment: + OS_CLOUD: undercloud + command: openstack baremetal node set \ + --instance-info kernel="file://{{ tripleo_backup_and_restore_ironic_images_path }}/overcloud-full.vmlinuz" \ + --instance-info ramdisk="file://{{ tripleo_backup_and_restore_ironic_images_path }}/overcloud-full.initrd" \ + --deploy-interface direct \ + {{ node_name }} + tags: + - bar_restore_image + +- name: Change boot device to disk + environment: + OS_CLOUD: undercloud + command: openstack baremetal node boot device set {{ node_name }} disk + tags: + - bar_restore_image + +- name: Unset maintenance from node + environment: + OS_CLOUD: undercloud + command: openstack baremetal node maintenance unset {{ node_name }} + tags: + - bar_restore_image + +- name: Power on instance + environment: + OS_CLOUD: undercloud + command: openstack baremetal node power on {{ node_name }} + tags: + - bar_restore_image