71 lines
2.0 KiB
YAML
71 lines
2.0 KiB
YAML
---
|
|
#
|
|
# Copyright (c) 2019 Wind River Systems, Inc.
|
|
#
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
#
|
|
# ROLE DESCRIPTION:
|
|
# This role contains common components (tasks, vars, etc.) that
|
|
# can be shared by all the backup and restore playbooks.
|
|
|
|
# Check host connectivity
|
|
- block:
|
|
- name: Set SSH port
|
|
set_fact:
|
|
ansible_port: "{{ ansible_port | default(22) }}"
|
|
|
|
- name: Update SSH known hosts
|
|
lineinfile:
|
|
path: ~/.ssh/known_hosts
|
|
state: absent
|
|
regexp: '^{{ ansible_host }}|^\[{{ ansible_host }}\]:{{ ansible_port }}'
|
|
delegate_to: localhost
|
|
|
|
- name: Check connectivity
|
|
local_action: command ping -c 1 {{ ansible_host }}
|
|
failed_when: false
|
|
register: ping_result
|
|
|
|
- name: Fail if host is unreachable
|
|
fail: msg='Host {{ ansible_host }} is unreachable!'
|
|
with_items:
|
|
- "{{ ping_result.stdout_lines|list }}"
|
|
when: ping_result.rc != 0 and item is search('100% packet loss')
|
|
|
|
when: inventory_hostname != 'localhost'
|
|
|
|
- name: Check archive dir
|
|
stat:
|
|
path: "{{ backup_dir }}"
|
|
register: backup_dir_result
|
|
|
|
- name: Fail if archive dir does not exist
|
|
fail:
|
|
msg: " Archive directory {{ backup_dir }} does not exist!"
|
|
when: backup_dir_result.stat.exists == false
|
|
|
|
- name: Retrieve software version number
|
|
# lookup module does not work with /etc/build.info as it does not have ini
|
|
# format. Resort to shell source.
|
|
shell: source /etc/build.info; echo $SW_VERSION
|
|
register: sw_version_result
|
|
|
|
- name: Fail if software version is not defined
|
|
fail:
|
|
msg: "SW_VERSION is missing in /etc/build.info"
|
|
when: sw_version_result.stdout_lines|length == 0
|
|
|
|
- name: Retrieve system type
|
|
shell: source /etc/platform/platform.conf; echo $system_type
|
|
register: system_type_result
|
|
|
|
- name: Fail if system type is not defined
|
|
fail:
|
|
msg: "system_type is missing in /etc/platform/platform.conf"
|
|
when: system_type_result.stdout_lines|length == 0
|
|
|
|
- name: Set software version fact
|
|
set_fact:
|
|
software_version: "{{ sw_version_result.stdout_lines[0] }}"
|
|
system_type: "{{ system_type_result.stdout_lines[0] }}"
|