Do not execute anything if a host is unreachable

If a host is unreachable, the default behaviour for
ansible is to ignore that and execute all the tasks
in the hosts that are reachable. This is unwanted
behaviour for B&R, as we need the whole controller
cluster to be healthy and reachable before we take
a backup from it. This patch introduces a mechanism
to abort execution if there is one or more
unreachable hosts.

Change-Id: I3820875e72a8d805d71c7981468398bbcec0bf04
This commit is contained in:
jlarriba 2022-09-08 11:09:50 +02:00
parent 5305f0b8a1
commit a7f54163cf
4 changed files with 46 additions and 1 deletions

View File

@ -13,6 +13,21 @@
# License for the specific language governing permissions and limitations
# under the License.
- name: Do nothing if one of the hosts is unreachable
hosts: '{{ tripleo_controller_group_name }}'
become: true
vars_files:
../roles/backup_and_restore/defaults/main.yml
tasks:
- name: Check ALL hosts are reacheable
fail:
msg: >
[REQUIRED] ALL hosts to be reachable, so flagging {{ inventory_hostname }} as failed,
because host {{ item }} has no facts, meaning it is UNREACHABLE.
when: "hostvars[item].ansible_facts|list|length == 0"
with_items: "{{ groups[tripleo_controller_group_name] }}"
run_once: true
- name: TripleO Controller backup
hosts: Undercloud
become: true

View File

@ -12,6 +12,22 @@
# 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: Stop executing if one of the hosts is unreachable
hosts: '{{ tripleo_controller_group_name }}'
become: true
vars_files:
../roles/backup_and_restore/defaults/main.yml
tasks:
- name: Check ALL hosts are reacheable
fail:
msg: >
[REQUIRED] ALL hosts to be reachable, so flagging {{ inventory_hostname }} as failed,
because host {{ item }} has no facts, meaning it is UNREACHABLE.
when: "hostvars[item].ansible_facts|list|length == 0"
with_items: "{{ groups[tripleo_controller_group_name] }}"
run_once: true
- name: Backup ceph authentication
hosts: ceph_mon
become: true

View File

@ -13,6 +13,21 @@
# License for the specific language governing permissions and limitations
# under the License.
- name: Stop executing if one of the hosts is unreachable
hosts: '{{ tripleo_controller_group_name }}'
become: true
vars_files:
../roles/backup_and_restore/defaults/main.yml
tasks:
- name: Check ALL hosts are reacheable
fail:
msg: >
[REQUIRED] ALL hosts to be reachable, so flagging {{ inventory_hostname }} as failed,
because host {{ item }} has no facts, meaning it is UNREACHABLE.
when: "hostvars[item].ansible_facts|list|length == 0"
with_items: "{{ groups[tripleo_controller_group_name] }}"
run_once: true
- name: TripleO Controller ReaR installation and configuration.
hosts: '{{ tripleo_controller_group_name }}'
remote_user: "{{ tripleo_target_user | default(lookup('env', 'USER')) }}"

View File

@ -14,7 +14,6 @@
# License for the specific language governing permissions and limitations
# under the License.
# "backup_and_restore" will search for and load any operating system variable file
# found within the "vars/" path. If no OS files are found the task will skip.