From 291fb9e9440a00ecb4ebd321efadaf47a3a60597 Mon Sep 17 00:00:00 2001 From: Stephen Fromm Date: Mon, 20 May 2013 22:25:01 -0700 Subject: [PATCH] Help ansible-pull work better in bootstap environment 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 #2464. --- bin/ansible-pull | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/bin/ansible-pull b/bin/ansible-pull index 89356c7b68e..53b403e5540 100755 --- a/bin/ansible-pull +++ b/bin/ansible-pull @@ -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' } @@ -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: @@ -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 @@ -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)