From 291fb9e9440a00ecb4ebd321efadaf47a3a60597 Mon Sep 17 00:00:00 2001 From: Stephen Fromm Date: Mon, 20 May 2013 22:25:01 -0700 Subject: [PATCH 1/3] 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 89356c7b68..53b403e554 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) From a611027329315648e80c5207848b6a78846d2c1d Mon Sep 17 00:00:00 2001 From: Stephen Fromm Date: Sat, 1 Jun 2013 21:42:26 -0700 Subject: [PATCH 2/3] Update ansible-pull documentation --- docs/man/man1/ansible-pull.1.asciidoc.in | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/docs/man/man1/ansible-pull.1.asciidoc.in b/docs/man/man1/ansible-pull.1.asciidoc.in index 4d3147d550..19ed537dea 100644 --- a/docs/man/man1/ansible-pull.1.asciidoc.in +++ b/docs/man/man1/ansible-pull.1.asciidoc.in @@ -12,7 +12,7 @@ ansible-pull - set up a remote copy of ansible on each managed node SYNOPSIS -------- -ansible -d DEST -U URL [ -C CHECKOUT ] +ansible -d DEST -U URL [ -C CHECKOUT ] [ -i INVENTORY ] [ ] DESCRIPTION @@ -35,6 +35,17 @@ ansible-pull runs would be an excellent way to gather and analyze remote logs from ansible-pull. +OPTIONAL ARGUMENT +----------------- + +*filename.yml*:: + +The name of one the YAML format files to run as an ansible playbook. This can +be a relative path within the git checkout. If not provided, ansible-pull +will look for a playbook based on the host's fully-qualified domain name and +finally a playbook named *local.yml*. + + OPTIONS ------- @@ -50,6 +61,14 @@ URL of git repository to clone. Branch/Tag/Commit to checkout. Defaults to 'HEAD'. +*-i* 'PATH', *--inventory=*'PATH':: + +The 'PATH' to the inventory hosts file. This can be a relative path within +the git checkout. + +*--purge*:: + +Purge the git checkout after the playbook is run. AUTHOR From 355ab6983c0b9bbdd5ddb602f620c0cf7769ac54 Mon Sep 17 00:00:00 2001 From: Stephen Fromm Date: Sat, 1 Jun 2013 21:47:38 -0700 Subject: [PATCH 3/3] remove errant and unneeded import of ansible.constants --- bin/ansible-pull | 2 -- 1 file changed, 2 deletions(-) diff --git a/bin/ansible-pull b/bin/ansible-pull index 53b403e554..2c0e4395e2 100755 --- a/bin/ansible-pull +++ b/bin/ansible-pull @@ -44,8 +44,6 @@ 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' }