blob: 37ed18b7e064c2831a72c2b985e9527349aef2e1 [file] [log] [blame]
lloretgalleg1d2ff512020-08-01 06:05:58 +00001##
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
23import logging
24import json
25from shlex import quote
26
27import osm_ee.util.util_ee as util_ee
28
29logger = logging.getLogger("osm_ee.util_ansible")
30
31
garciadeblas43fc9352024-07-09 14:30:44 +020032async def execute_playbook(
33 playbook_name: str,
34 inventory: str,
35 extra_vars: dict,
36) -> (int, str):
lloretgalleg1d2ff512020-08-01 06:05:58 +000037
garciadeblas43fc9352024-07-09 14:30:44 +020038 command = "ansible-playbook --inventory={} --extra-vars {} {}".format(
39 quote(inventory), quote(json.dumps(extra_vars)), quote(playbook_name)
40 )
lloretgalleg1d2ff512020-08-01 06:05:58 +000041
42 logger.debug("Command to be executed: {}".format(command))
43
44 return_code, stdout, stderr = await util_ee.local_async_exec(command)
45 logger.debug("Return code: {}".format(return_code))
46 logger.debug("stdout: {}".format(stdout))
47 logger.debug("stderr: {}".format(stderr))
48
49 return return_code, stdout, stderr