Fix missing payload for DGs and Playbooks of SW upgrade
[sdnc/oam.git] / installation / ansible-server / src / main / Playbooks / ansible_huawei_upgrade@0.01.yml
1 ---\r
2 - hosts: all\r
3   tasks:\r
4 \r
5   - name: compatible with parameter targetSwVersion\r
6     set_fact:\r
7       sw_to_be_downloaded: "{{targetSwVersion}}"\r
8     when: targetSwVersion is defined\r
9 \r
10   - name: support new parameter swToBeDownloaded\r
11     set_fact:\r
12       sw_to_be_downloaded: "{{swToBeDownloaded}}"\r
13     when: swToBeDownloaded is defined\r
14 \r
15   - name: compatible with parameter pnfId\r
16     set_fact:\r
17       ne_identifier: "{{pnfId}}"\r
18     when: pnfId is defined\r
19 \r
20   - name: support new parameter neIdentifier\r
21     set_fact:\r
22       ne_identifier: "{{neIdentifier}}"\r
23     when: neIdentifier is defined\r
24 \r
25   - name: support new parameter swToBeInstalled\r
26     set_fact:\r
27       sw_to_be_installed: "{{swToBeInstalled}}"\r
28     when: swToBeInstalled is defined\r
29 \r
30   - name: check if swToBeInstalled is empty\r
31     fail:\r
32     when: swToBeInstalled is defined and sw_to_be_installed | length == 0\r
33 \r
34   - name: support new parameter swVersionToBeActivated\r
35     set_fact:\r
36       sw_version_to_be_activated: "{{swVersionToBeActivated}}"\r
37     when: swVersionToBeActivated is defined\r
38 \r
39   - name: execute downloadNESw operation\r
40     shell: ./swm/downloadNESw --swToBeDownloaded {{sw_to_be_downloaded}} --neIdentifier {{ne_identifier}}\r
41     ignore_errors: yes\r
42     register: download_result\r
43 \r
44   - name: build error message for downloadNESw\r
45     set_fact:\r
46       download_err_msg:\r
47         "reason": "downloadNESw failure"\r
48         "result": "Failure"\r
49     when: download_result is failed\r
50 \r
51   - name: write error message to file for downloadNESw\r
52     local_action: copy content="{{download_err_msg}}" dest="{{inventory_dir}}/{{inventory_hostname}}_results.txt"\r
53     when: download_result is failed\r
54 \r
55   - name: use result of downloadNESw as the result of Playbook\r
56     fail:\r
57       msg: "{{download_err_msg}}"\r
58     when: download_result is failed\r
59 \r
60   - name: parse response of downloadNESw\r
61     set_fact:\r
62       download_response: "{{ download_result.stdout | from_json }}"\r
63     when: swToBeInstalled is not defined\r
64 \r
65   - name: fetch file of Notification notifyDownloadNESwStatusChanged\r
66     fetch:\r
67       dest: "{{inventory_dir}}"\r
68       src: "/tmp/notifyDownloadNESwStatusChanged-{{download_response.downloadProcessId}}"\r
69     when: swToBeInstalled is not defined\r
70 \r
71   - name: read contents of Notification notifyDownloadNESwStatusChanged\r
72     set_fact:\r
73       download_notification: "{{ lookup('file', '{{inventory_dir}}/{{inventory_hostname}}/tmp/notifyDownloadNESwStatusChanged-{{download_response.downloadProcessId}}') | from_json }}"\r
74     when: swToBeInstalled is not defined\r
75 \r
76   - name: delete file of Notification notifyDownloadNESwStatusChanged\r
77     local_action: file path="{{inventory_dir}}/{{inventory_hostname}}/tmp/notifyDownloadNESwStatusChanged-{{download_response.downloadProcessId}}" state=absent\r
78     when: swToBeInstalled is not defined\r
79 \r
80   - name: set downloadedNESwInfo\r
81     set_fact:\r
82       downloaded_ne_sw_info: "{{ download_notification.downloadedNESwInfo }}"\r
83     when: swToBeInstalled is not defined\r
84 \r
85   - name: execute installNESw operation\r
86     shell: ./swm/installNESw --swToBeInstalled {{item}} --neIdentifier {{ne_identifier}}\r
87     ignore_errors: yes\r
88     register: install_result\r
89     with_items: "{{ downloaded_ne_sw_info | default([]) }}"\r
90 \r
91   - name: execute installNESw operation using new parameter\r
92     shell: ./swm/installNESw --swToBeInstalled {{item}} --neIdentifier {{ne_identifier}}\r
93     ignore_errors: yes\r
94     register: install_result_new\r
95     with_items: "{{ sw_to_be_installed | default([]) }}"\r
96 \r
97   - name: unify install result\r
98     set_fact:\r
99       install_result: "{{ install_result_new }}"\r
100     when: swToBeInstalled is defined\r
101 \r
102   - name: build error message for installNESw\r
103     set_fact:\r
104       install_err_msg:\r
105         "reason": "installNESw failure"\r
106         "result": "Failure"\r
107     when: install_result is failed\r
108 \r
109   - name: write error message to file for installNESw\r
110     local_action: copy content="{{install_err_msg}}" dest="{{inventory_dir}}/{{inventory_hostname}}_results.txt"\r
111     when: install_result is failed\r
112 \r
113   - name: use result of installNESw as the result of Playbook\r
114     fail:\r
115       msg: "{{install_err_msg}}"\r
116     when: install_result is failed\r
117 \r
118   - name: set install results list\r
119     set_fact:\r
120       install_results_list: "{{ install_result.results }}"\r
121     when: swVersionToBeActivated is not defined\r
122 \r
123   - name: parse responses of all the installNESws\r
124     set_fact:\r
125       install_responses: "{{ install_responses | default([]) + [item.stdout | from_json] }}"\r
126     with_items: "{{ install_results_list | default([]) }}"\r
127 \r
128   - name: fetch files of all the Notifications notifyInstallNESwStatusChanged\r
129     fetch:\r
130       dest: "{{inventory_dir}}"\r
131       src: "/tmp/notifyInstallNESwStatusChanged-{{item.installProcessId}}"\r
132     with_items: "{{ install_responses | default([]) }}"\r
133 \r
134   - name: read contents of all the Notifications notifyInstallNESwStatusChanged\r
135     set_fact:\r
136       install_notifications: "{{ install_notifications | default([]) + [lookup('file', '{{inventory_dir}}/{{inventory_hostname}}/tmp/notifyInstallNESwStatusChanged-{{item.installProcessId}}') | from_json] }}"\r
137     with_items: "{{ install_responses | default([]) }}"\r
138 \r
139   - name: delete files of all the Notifications notifyInstallNESwStatusChanged\r
140     local_action: file path="{{inventory_dir}}/{{inventory_hostname}}/tmp/notifyInstallNESwStatusChanged-{{item.installProcessId}}" state=absent\r
141     with_items: "{{ install_responses | default([]) }}"\r
142 \r
143   - name: parse all the installed NE SW info\r
144     set_fact:\r
145       installed_ne_sw_info: "{{ installed_ne_sw_info | default([]) + item.installedNESwInfo }}"\r
146     with_items: "{{ install_notifications | default([]) }}"\r
147 \r
148   - name: execute activateNESw operation\r
149     shell: ./swm/activateNESw --swVersionToBeActivated {{item}} --neIdentifier {{ne_identifier}}\r
150     ignore_errors: yes\r
151     register: activate_result\r
152     with_items: "{{ installed_ne_sw_info | default([]) }}"\r
153 \r
154   - name: execute activateNESw operation using new parameter\r
155     shell: ./swm/activateNESw --swVersionToBeActivated {{sw_version_to_be_activated}} --neIdentifier {{ne_identifier}}\r
156     ignore_errors: yes\r
157     register: activate_result_new\r
158     when: swVersionToBeActivated is defined\r
159 \r
160   - name: unify activate result\r
161     set_fact:\r
162       activate_result: "{{ activate_result_new }}"\r
163     when: swVersionToBeActivated is defined\r
164 \r
165   - name: build error message for activateNESw\r
166     set_fact:\r
167       activate_err_msg:\r
168         "reason": "activateNESw failure"\r
169         "result": "Failure"\r
170     when: activate_result is failed\r
171 \r
172   - name: write error message to file for activateNESw\r
173     local_action: copy content="{{activate_err_msg}}" dest="{{inventory_dir}}/{{inventory_hostname}}_results.txt"\r
174     when: activate_result is failed\r
175 \r
176   - name: use result of activateNESw as the result of Playbook\r
177     fail:\r
178       msg: "{{activate_err_msg}}"\r
179     when: activate_result is failed\r
180 \r
181   - name: build success message for activateNESw\r
182     set_fact:\r
183       activate_success_msg:\r
184         "result": "Success"\r
185     when: activate_result is not failed\r
186 \r
187   - name: write success message to file for activateNESw\r
188     local_action: copy content="{{activate_success_msg}}" dest="{{inventory_dir}}/{{inventory_hostname}}_results.txt"\r
189     when: activate_result is not failed\r
190 \r