Update DGs and Playbooks for PNF SW Upgrade
[sdnc/oam.git] / installation / ansible-server / src / main / Playbooks / ansible_huawei_postcheck@0.01.yml
index ad4edf5..cc867c1 100644 (file)
@@ -1,18 +1,29 @@
 ---\r
 - hosts: all\r
   tasks:\r
+\r
+  - name: parameter neIdentifier\r
+    set_fact:\r
+      ne_identifier: "{{neIdentifier}}"\r
+    when: neIdentifier is defined\r
+\r
+  - name: compatible with parameter pnfName\r
+    set_fact:\r
+      ne_identifier: "{{pnfName}}"\r
+    when: neIdentifier is not defined and pnfName is defined\r
+\r
   - name: create a temporary file for additional data\r
-    file: \r
-        path: /tmp/tmp-{{Id}}\r
-        state: touch\r
-    become: false\r
+    tempfile: \r
+      state: file\r
+    register: additional_data_file\r
 \r
   - name: prepare additional data\r
-    shell: echo {{additionalData}} > /tmp/tmp-{{Id}}\r
-    become: false\r
+    copy:\r
+      content: "{{additionalData}}"\r
+      dest: "{{additional_data_file.path}}"\r
 \r
   - name: execute post-check operation\r
-    shell: ./swm/upgrade-post-check {{pnfId}} {{oldSwVersion}} {{targetSwVersion}} {{ruleName}} /tmp/tmp-{{Id}}\r
+    shell: ./swm/upgrade-post-check {{ne_identifier}} {{oldSwVersion}} {{targetSwVersion}} {{ruleName}} {{additional_data_file.path}}\r
     ignore_errors: yes\r
     register: postcheck_result\r
 \r
 \r
   - name: remove the temporary file\r
     file:\r
-        path: /tmp/tmp-{{Id}}\r
-        state: absent\r
-    become: false\r
+      path: "{{additional_data_file.path}}"\r
+      state: absent\r
+    when: additional_data_file.path is defined\r
+\r
+  - name: build error message\r
+    set_fact:\r
+      err_msg:\r
+        "reason": "{{postcheck_result.stderr}}"\r
+        "result": "Failure"\r
+    when: postcheck_result is failed and postcheck_result.stdout == "" and postcheck_result.stderr != ""\r
+\r
+  - name: write error message to file\r
+    local_action: copy content="{{err_msg}}" dest="{{inventory_dir}}/{{inventory_hostname}}_results.txt"\r
+    when: postcheck_result is failed and postcheck_result.stdout == "" and postcheck_result.stderr != ""\r
 \r
   - name: use result of post-check as the result of Playbook\r
     fail:\r