| lloretgalleg | 1d2ff51 | 2020-08-01 06:05:58 +0000 | [diff] [blame] | 1 | ## |
| 2 | # Copyright 2019 Telefonica Investigacion y Desarrollo, S.A.U. |
| 3 | # This file is part of OSM |
| 4 | # All Rights Reserved. |
| 5 | # |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | # you may not use this file except in compliance with the License. |
| 8 | # You may obtain a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| 15 | # implied. |
| 16 | # See the License for the specific language governing permissions and |
| 17 | # limitations under the License. |
| 18 | # |
| 19 | # For those usages not covered by the Apache License, Version 2.0 please |
| 20 | # contact with: nfvlabs@tid.es |
| 21 | ## |
| 22 | |
| 23 | import logging |
| 24 | import json |
| 25 | from shlex import quote |
| 26 | |
| 27 | import osm_ee.util.util_ee as util_ee |
| 28 | |
| 29 | logger = logging.getLogger("osm_ee.util_ansible") |
| 30 | |
| 31 | |
| 32 | async def execute_playbook(playbook_name: str, inventory: str, extra_vars: dict, |
| 33 | ) -> (int, str): |
| 34 | |
| 35 | command = 'ansible-playbook --inventory={} --extra-vars {} {}'.format(quote(inventory), |
| 36 | quote(json.dumps(extra_vars)), |
| 37 | quote(playbook_name)) |
| 38 | |
| 39 | logger.debug("Command to be executed: {}".format(command)) |
| 40 | |
| 41 | return_code, stdout, stderr = await util_ee.local_async_exec(command) |
| 42 | logger.debug("Return code: {}".format(return_code)) |
| 43 | logger.debug("stdout: {}".format(stdout)) |
| 44 | logger.debug("stderr: {}".format(stderr)) |
| 45 | |
| 46 | return return_code, stdout, stderr |