aboutsummaryrefslogtreecommitdiffstats
path: root/installation/ansible-server/src/main/Playbooks/ansible_huawei_postcheck@0.01.yml
blob: b9b1ab81ee1f974bcdd9f7a60d362ef0a5ea52ec (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
---
- hosts: all
  tasks:
  - name: create a temporary file for additional data
    file: 
      path: /tmp/tmp-{{Id}}
      state: touch

  - name: prepare additional data
    shell: echo {{additionalData}} > /tmp/tmp-{{Id}}

  - name: execute post-check operation
    shell: ./swm/upgrade-post-check {{pnfId}} {{oldSwVersion}} {{targetSwVersion}} {{ruleName}} /tmp/tmp-{{Id}}
    ignore_errors: yes
    register: postcheck_result

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

  - name: remove the temporary file
    file:
      path: /tmp/tmp-{{Id}}
      state: absent

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

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

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