mirror of
https://github.com/kevingruesser/bootstrap-vz.git
synced 2025-08-22 09:50:37 +00:00
ansible: Make playbook path relative to manifest
This commit is contained in:
parent
85a0e6a191
commit
ad6c89cb41
2 changed files with 9 additions and 11 deletions
|
@ -20,10 +20,8 @@ properties:
|
|||
type: array
|
||||
host: {type: string}
|
||||
minItems: 1
|
||||
playbook: {$ref: '#/definitions/absolute_path'}
|
||||
playbook:
|
||||
type: string
|
||||
pattern: ^[^\0]+$
|
||||
required: [playbook]
|
||||
additionalProperties: false
|
||||
definitions:
|
||||
absolute_path:
|
||||
pattern: ^/[^\0]+$
|
||||
type: string
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
from bootstrapvz.base import Task
|
||||
from bootstrapvz.common import phases
|
||||
from bootstrapvz.common.tools import rel_path
|
||||
import os
|
||||
|
||||
|
||||
|
@ -10,7 +11,7 @@ class CheckPlaybookPath(Task):
|
|||
@classmethod
|
||||
def run(cls, info):
|
||||
from bootstrapvz.common.exceptions import TaskError
|
||||
playbook = info.manifest.plugins['ansible']['playbook']
|
||||
playbook = rel_path(info.manifest.path, info.manifest.plugins['ansible']['playbook'])
|
||||
if not os.path.exists(playbook):
|
||||
msg = 'The playbook file {playbook} does not exist.'.format(playbook=playbook)
|
||||
raise TaskError(msg)
|
||||
|
@ -29,7 +30,7 @@ class AddPackages(Task):
|
|||
|
||||
|
||||
class RunAnsiblePlaybook(Task):
|
||||
description = 'Running ansible playbooks'
|
||||
description = 'Running ansible playbook'
|
||||
phase = phases.user_modification
|
||||
|
||||
@classmethod
|
||||
|
@ -37,8 +38,7 @@ class RunAnsiblePlaybook(Task):
|
|||
from bootstrapvz.common.tools import log_check_call
|
||||
|
||||
# Extract playbook and directory
|
||||
playbook = info.manifest.plugins['ansible']['playbook']
|
||||
playbook_dir = os.path.dirname(os.path.realpath(playbook))
|
||||
playbook = rel_path(info.manifest.path, info.manifest.plugins['ansible']['playbook'])
|
||||
|
||||
# Check for hosts
|
||||
hosts = None
|
||||
|
@ -77,7 +77,7 @@ class RunAnsiblePlaybook(Task):
|
|||
handle.write(content)
|
||||
|
||||
# build the ansible command
|
||||
cmd = ['ansible-playbook', '-i', inventory, os.path.basename(playbook)]
|
||||
cmd = ['ansible-playbook', '-i', inventory, playbook]
|
||||
if extra_vars:
|
||||
tmp_cmd = ['--extra-vars', '\"{}\"'.format(extra_vars)]
|
||||
cmd.extend(tmp_cmd)
|
||||
|
@ -92,5 +92,5 @@ class RunAnsiblePlaybook(Task):
|
|||
cmd.extend(opt_flags)
|
||||
|
||||
# Run and remove the inventory file
|
||||
log_check_call(cmd, cwd=playbook_dir)
|
||||
log_check_call(cmd)
|
||||
os.remove(inventory)
|
||||
|
|
Loading…
Add table
Reference in a new issue