#!/bin/env bash
#
# Run minor update on overcloud nodes
#
set -euo pipefail

source {{ undercloud_rc }}

echo "Generate inventory for stack {{ overcloud_stack_name }}"
tripleo-ansible-inventory --plan {{ overcloud_stack_name }} {% if overcloud_ssh_user != '' %} --ansible_ssh_user {{ overcloud_ssh_user }} {% endif %}\
    --static-inventory {{ working_dir }}/{{ overcloud_stack_name }}-inventory

{% if  item|string == 'all' %}
echo "Running minor update of all overcloud nodes"
openstack overcloud update stack --stack {{ overcloud_stack_name }} \
    --static-inventory {{ working_dir }}/{{ overcloud_stack_name }}-inventory 2>&1
{% else %}
{% set tmp_role_name = item.split('-', 1)[-1] %}
echo "Runing update of {{ tmp_role_name }}"
openstack overcloud update stack --stack {{ overcloud_stack_name }} \
    --static-inventory {{ working_dir }}/{{ overcloud_stack_name }}-inventory \
    --nodes {{ tmp_role_name }} 2>&1
{% endif %}
