summaryrefslogtreecommitdiffstats
path: root/ansible-server
diff options
context:
space:
mode:
authorDan Timoney <dtimoney@att.com>2019-05-31 14:41:37 +0000
committerGerrit Code Review <gerrit@onap.org>2019-05-31 14:41:37 +0000
commit735c42c00da524d9ddd1da0d0b4dc2fd6b781fe3 (patch)
tree9f1a9bd7487613d6f808eef855660887a6b0ff6a /ansible-server
parent809c13f0b36c2c964f92fd42c0188938be5157ca (diff)
parent960153f697743cfc5da142606b1207934865cb24 (diff)
Merge "Fix playbook execution for VNF" into dublin
Diffstat (limited to 'ansible-server')
-rwxr-xr-xansible-server/src/main/ansible-server/AnsibleModule.py6
-rwxr-xr-xansible-server/src/main/ansible-server/BuildHostFile.py12
-rwxr-xr-xansible-server/src/main/ansible-server/RestServer.py24
3 files changed, 24 insertions, 18 deletions
diff --git a/ansible-server/src/main/ansible-server/AnsibleModule.py b/ansible-server/src/main/ansible-server/AnsibleModule.py
index 71d0c059..3985ee28 100755
--- a/ansible-server/src/main/ansible-server/AnsibleModule.py
+++ b/ansible-server/src/main/ansible-server/AnsibleModule.py
@@ -6,7 +6,9 @@
* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2019 Amdocs
-* =============================================================================
+* ================================================================================
+* Copyright (C) 2019 Orange
+* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -86,7 +88,7 @@ def ansibleSysCall (inventory_path, playbook_path, nodelist, mandatory, envparam
ok_flag = line.split(':')[1].strip().split('=')[1].split('changed')[0].strip()
changed_flag = line.split(':')[1].strip().split('=')[2].split('unreachable')[0].strip()
unreachable_flag = line.split(':')[1].strip().split('=')[3].split('failed')[0].strip()
- failed_flag = line.split(':')[1].strip().split('=')[4].strip()
+ failed_flag = line.split(':')[1].strip().split('=')[4].split('skipped')[0].strip()
retval[ip_address]=[ok_flag, changed_flag, unreachable_flag, failed_flag]
if "PLAY RECAP" in line:
ParseFlag = True
diff --git a/ansible-server/src/main/ansible-server/BuildHostFile.py b/ansible-server/src/main/ansible-server/BuildHostFile.py
index a49f94aa..64e184d2 100755
--- a/ansible-server/src/main/ansible-server/BuildHostFile.py
+++ b/ansible-server/src/main/ansible-server/BuildHostFile.py
@@ -6,7 +6,9 @@
* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2019 Amdocs
-* =============================================================================
+* ================================================================================
+* Copyright (C) 2019 Orange
+* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -77,10 +79,8 @@ def buildHostsSysCall(JsonInput, run_path, inventory_type):
output_file.write ("\n[%svip]\n" % Type )
if inventory_type == "None":
output_file.write ("%s\n" % (FloatingIP) )
- elif inventory_type == "VNFC":
+ elif inventory_type == "VNFC" or inventory_type == "VM":
output_file.write ("%s ansible_host=%s\n" % (NE_ID_VIP, FloatingIP) )
- elif inventory_type == "VM":
- output_file.write ("%s ansible_host=%s\n" % (NE_ID_VIP[0:13], FloatingIP) )
output_file.write ("\n[%s]\n" % Type )
Site = NodeList['site']
@@ -96,10 +96,8 @@ def buildHostsSysCall(JsonInput, run_path, inventory_type):
#print ("vm: " + Name + ": " + IpAddr)
if inventory_type == "None":
output_file.write ("%s\n" % (IpAddr) )
- elif inventory_type == "VNFC":
+ elif inventory_type == "VNFC" or inventory_type == "VM":
output_file.write ("%s ansible_host=%s\n" % (Name, IpAddr) )
- elif inventory_type == "VM":
- output_file.write ("%s ansible_host=%s\n" % (Name[0:13], IpAddr) )
# print site list
output_file.write ("\n[%s:children]\n" % Site )
diff --git a/ansible-server/src/main/ansible-server/RestServer.py b/ansible-server/src/main/ansible-server/RestServer.py
index 2b4da335..8f5aa7ef 100755
--- a/ansible-server/src/main/ansible-server/RestServer.py
+++ b/ansible-server/src/main/ansible-server/RestServer.py
@@ -6,7 +6,9 @@
* Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2017 Amdocs
-* =============================================================================
+* ================================================================================
+* Copyright (C) 2019 Orange
+* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -18,7 +20,7 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
-*
+*
* ============LICENSE_END=========================================================
*/
'''
@@ -554,9 +556,13 @@ def process_vnf_playbook(input_json, Id, EnvParameters, time_now):
else:
cherrypy.log("Successfully created the directory %s " % path)
+
# location of host file - Default
- HostFile = PlaybookDir + "/inventory/" + VNF_instance + "hosts"
- cherrypy.log("HostFile: " + HostFile)
+ HostFile = "inventory/" + VNF_instance + "hosts"
+ HostFilePath = PlaybookDir + "/" + HostFile
+ cherrypy.log("HostFile: " + HostFilePath)
+
+ # buildInventorySysCall(ANSIBLE_PATH, ANSIBLE_INV, NodeList, PlaybookDir, HostFile, hostgrouplist, hostnamelist)
# if NodeList and InventoryNames need to build host file
if HaveInventoryNames and HaveNodeList:
@@ -568,8 +574,8 @@ def process_vnf_playbook(input_json, Id, EnvParameters, time_now):
"StatusMessage": "NodeList: Missing vnfc-type field"}
# Having been built now copy new file to correct file
- shutil.copy(PlaybookDir + "/host_file.txt", HostFile)
- cherrypy.log("Copying Generated host file to: " + HostFile)
+ shutil.copy(PlaybookDir + "/host_file.txt", HostFilePath)
+ cherrypy.log("Copying Generated host file to: " + HostFilePath)
if 'Timeout' in input_json:
timeout = int(input_json['Timeout'])
@@ -657,14 +663,14 @@ def process_vnf_playbook(input_json, Id, EnvParameters, time_now):
f.close()
# Check that HostFile exists
- if not os.path.isfile(HostFile):
- cherrypy.log("Inventory file Not Found: " + HostFile)
+ if not os.path.isfile(HostFilePath):
+ cherrypy.log("Inventory file Not Found: " + HostFilePath)
return {"StatusCode": 101, "StatusMessage": "PLAYBOOK INVENTORY FILE NOT FOUND"}
# Cannot use thread because ansible module uses signals which are only supported in main thread.
# So use multiprocess with shared object
p = Process(target=RunAnsible_Playbook,
- args=(callback, Id, HostFile, PlaybookDir + '/' + PlayBookFile,
+ args=(callback, Id, "../" + HostFile, "site.yml",
NodeList, TestRecord, PlaybookDir + "/" + PlayBookFunction, ArchiveFlag))
p.start()
ActiveProcess[Id] = p