summaryrefslogtreecommitdiffstats
path: root/installation/ansible-server/src/main/Playbooks/ansible_huawei_precheck@0.01.yml
blob: 32de4b3746f0c47fe946735e51c36d9fc1d2f797 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
---
- hosts: all
  tasks:

  - name: parameter neIdentifier
    set_fact:
      ne_identifier: "{{neIdentifier}}"
    when: neIdentifier is defined

  - name: compatible with parameter pnfName
    set_fact:
      ne_identifier: "{{pnfName}}"
    when: neIdentifier is not defined and pnfName is defined

  - name: create a temporary file for additional data
    tempfile: 
      state: file
    register: additional_data_file

  - name: prepare additional data
    copy:
      content: "{{additionalData}}"
      dest: "{{additional_data_file.path}}"

  - name: execute pre-check operation
    shell: ./swm/upgrade-pre-check {{ne_identifier}} {{oldSwVersion}} {{targetSwVersion}} {{ruleName}} {{additional_data_file.path}}
    ignore_errors: yes
    register: precheck_result

  - name: write output to file
    local_action: copy content="{{precheck_result.stdout}}" dest="{{inventory_dir}}/{{inventory_hostname}}_results.txt"
    when: precheck_result.stdout != ""

  - name: remove the temporary file
    file:
      path: "{{additional_data_file.path}}"
      state: absent
    when: additional_data_file.path is defined

  - name: build error message
    set_fact:
      err_msg:
        "reason": "{{precheck_result.stderr}}"
        "result": "Failure"
    when: precheck_result is failed and precheck_result.stdout == "" and precheck_result.stderr != ""

  - name: write error message to file
    local_action: copy content="{{err_msg}}" dest="{{inventory_dir}}/{{inventory_hostname}}_results.txt"
    when: precheck_result is failed and precheck_result.stdout == "" and precheck_result.stderr != ""

  - name: use result of pre-check as the result of Playbook
    fail:
      msg: "{{precheck_result.stderr}}"
    when: precheck_result is failed