Skip to content

Commit

Permalink
Help ansible-pull work better in bootstap environment
Browse files Browse the repository at this point in the history
Add option to specify inventory.  No default is defined since
ansible-playbook already does this and it allows an ansible.cfg in the
git repository to take precedence.
Overall, this should help ansible-pull work with less setup in advance,
which should be helpful in kickstart scenarios.  Much of this was
discussed in issue ansible#2464.
  • Loading branch information
sfromm committed Jun 2, 2013
1 parent 1c4fa2c commit 291fb9e
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion bin/ansible-pull
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ import datetime
import socket
from optparse import OptionParser

import ansible.constants as C

DEFAULT_PLAYBOOK = 'local.yml'
PLAYBOOK_ERRORS = { 1: 'File does not exist',
2: 'File is not readable' }
Expand Down Expand Up @@ -102,6 +104,8 @@ def main(args):
parser.add_option('-C', '--checkout', dest='checkout',
default="HEAD",
help='Branch/Tag/Commit to checkout. Defaults to HEAD.')
parser.add_option('-i', '--inventory-file', dest='inventory',
help="specify inventory host file")
options, args = parser.parse_args(args)

if not options.dest:
Expand All @@ -115,9 +119,12 @@ def main(args):
now = datetime.datetime.now()
print >>sys.stderr, now.strftime("Starting ansible-pull at %F %T")

inv_opts = 'localhost,'
limit_opts = 'localhost:%s:127.0.0.1' % socket.getfqdn()
git_opts = "repo=%s dest=%s version=%s" % (options.url, options.dest, options.checkout)
cmd = 'ansible all -c local --limit "%s" -m git -a "%s"' % (limit_opts, git_opts)
cmd = 'ansible all -c local -i "%s" --limit "%s" -m git -a "%s"' % (
inv_opts, limit_opts, git_opts
)
rc = _run(cmd)
if rc != 0:
return rc
Expand All @@ -129,6 +136,8 @@ def main(args):
return 1

cmd = 'ansible-playbook -c local --limit "%s" %s' % (limit_opts, playbook)
if options.inventory:
cmd += ' -i "%s"' % options.inventory
os.chdir(options.dest)
rc = _run(cmd)

Expand Down

0 comments on commit 291fb9e

Please sign in to comment.