Skip to content

Commit

Permalink
added support for default hosts location
Browse files Browse the repository at this point in the history
  • Loading branch information
spencergibb committed Sep 12, 2013
1 parent 7f94e29 commit c713ace
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
25 changes: 14 additions & 11 deletions bin/battle
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import os
import sys

import ansible.playbook
import ansible.constants as C
import ansible.constants as AC
import ansible.utils.template
from ansible import errors
from ansible import callbacks
from ansible import utils
from ansible.color import ANSIBLE_COLOR, stringc
from ansible.callbacks import display
import battleschool.constants as C

from battleschool.source.git import Git
from battleschool.source.local import Local
Expand Down Expand Up @@ -57,10 +58,12 @@ def main(args):

battleschool_dir = "%s/.battleschool" % os.environ['HOME']

AC.DEFAULT_HOST_LIST = C.DEFAULT_HOST_LIST

# create parser for CLI options
usage = "%prog"
parser = utils.base_parser(
constants=C,
constants=AC,
usage=usage,
connect_opts=True,
runas_opts=True,
Expand All @@ -87,22 +90,22 @@ def main(args):

options, args = parser.parse_args(args)

args = ['battleschool.yml']
playbooks_to_run = ['battleschool.yml']

inventory = ansible.inventory.Inventory("hosts")
inventory = ansible.inventory.Inventory(options.inventory)
inventory.subset(options.subset)
if len(inventory.list_hosts()) == 0:
raise errors.AnsibleError("provided hosts list is empty")

sshpass = None
sudopass = None
if not options.listhosts and not options.syntax and not options.listtasks:
options.ask_pass = C.DEFAULT_ASK_PASS
options.ask_sudo_pass = options.ask_sudo_pass or C.DEFAULT_ASK_SUDO_PASS
options.ask_pass = AC.DEFAULT_ASK_PASS
options.ask_sudo_pass = options.ask_sudo_pass or AC.DEFAULT_ASK_SUDO_PASS
( sshpass, sudopass ) = utils.ask_passwords(ask_pass=options.ask_pass, ask_sudo_pass=options.ask_sudo_pass)
if options.sudo_user or options.ask_sudo_pass:
options.sudo = True
options.sudo_user = options.sudo_user or C.DEFAULT_SUDO_USER
options.sudo_user = options.sudo_user or AC.DEFAULT_SUDO_USER
if options.extra_vars and options.extra_vars[0] in '[{':
extra_vars = utils.json_loads(options.extra_vars)
else:
Expand All @@ -120,7 +123,7 @@ def main(args):
handlers = getSourceHandlers()

if options.module_path is None:
options.module_path = C.DEFAULT_MODULE_PATH
options.module_path = AC.DEFAULT_MODULE_PATH

if 'sources' in config_data:
sources = config_data['sources']
Expand All @@ -129,19 +132,19 @@ def main(args):
source = handler(options, sources)
playbooks, module_dir = source.run(inventory, sshpass, sudopass)
for playbook in playbooks:
args.append(playbook)
playbooks_to_run.append(playbook)

if module_dir is not None and os.path.exists(module_dir) and os.path.isdir(module_dir):
options.module_path = "%s:%s" % (module_dir, options.module_path)

for playbook in args:
for playbook in playbooks_to_run:
if not os.path.exists(playbook):
raise errors.AnsibleError("the playbook: %s could not be found" % playbook)
if not os.path.isfile(playbook):
raise errors.AnsibleError("the playbook: %s does not appear to be a file" % playbook)

# run all playbooks specified on the command line
for playbook in args:
for playbook in playbooks_to_run:

# let inventory know which playbooks are using so it can know the basedirs
inventory.set_playbook_basedir(os.path.dirname(playbook))
Expand Down
3 changes: 3 additions & 0 deletions lib/battleschool/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ def get_config(env_var, default):
# correct location. See #1277 for discussion
if getattr(sys, "real_prefix", None):
DIST_MODULE_PATH = os.path.join(sys.prefix, 'share/battleschool/')
DIST_CONFIG_PATH = os.path.join(sys.prefix, 'etc/battleschool/')
else:
DIST_MODULE_PATH = '/usr/share/battleschool/'
DIST_CONFIG_PATH = '/etc/battleschool/'

DEFAULT_MODULE_PATH = get_config('BATTLESCHOOL_LIBRARY', DIST_MODULE_PATH)
DEFAULT_HOST_LIST = os.path.expanduser(get_config('BATTLESCHOOL_HOSTS', os.path.join(DIST_CONFIG_PATH, 'hosts')))

5 changes: 5 additions & 0 deletions packaging/macports/sysutils/battleschool/Portfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ depends_lib-append port:ansible
patch {
fs-traverse f ${worksrcpath} {
if {[file isfile ${f}]} {
reinplace -locale C "s#/etc/battleschool#${prefix}/etc/battleschool#g" ${f}
reinplace -locale C "s#/usr/share/battleschool#${prefix}/share/battleschool#g" ${f}
}
}
Expand All @@ -47,6 +48,10 @@ post-destroot {
# man pages
#xinstall -d 644 ${destroot}${prefix}/share/man/man1
#eval xinstall -m 755 [glob ${worksrcpath}/docs/man/man1/*.1] ${destroot}${prefix}/share/man/man1

# install sample config and hosts file
xinstall -m 755 -d ${destroot}${prefix}/etc/battleschool
xinstall -m 755 ${worksrcpath}/hosts ${destroot}${prefix}/etc/battleschool/hosts
}

python.link_binaries_suffix
1 change: 0 additions & 1 deletion packaging/macports/sysutils/battleschool/work

This file was deleted.

0 comments on commit c713ace

Please sign in to comment.