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