mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
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.
This commit is contained in:
parent
1c4fa2c45e
commit
291fb9e944
1 changed files with 10 additions and 1 deletions
|
@ -44,6 +44,8 @@ import datetime
|
||||||
import socket
|
import socket
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
|
||||||
|
import ansible.constants as C
|
||||||
|
|
||||||
DEFAULT_PLAYBOOK = 'local.yml'
|
DEFAULT_PLAYBOOK = 'local.yml'
|
||||||
PLAYBOOK_ERRORS = { 1: 'File does not exist',
|
PLAYBOOK_ERRORS = { 1: 'File does not exist',
|
||||||
2: 'File is not readable' }
|
2: 'File is not readable' }
|
||||||
|
@ -102,6 +104,8 @@ def main(args):
|
||||||
parser.add_option('-C', '--checkout', dest='checkout',
|
parser.add_option('-C', '--checkout', dest='checkout',
|
||||||
default="HEAD",
|
default="HEAD",
|
||||||
help='Branch/Tag/Commit to checkout. Defaults to 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)
|
options, args = parser.parse_args(args)
|
||||||
|
|
||||||
if not options.dest:
|
if not options.dest:
|
||||||
|
@ -115,9 +119,12 @@ def main(args):
|
||||||
now = datetime.datetime.now()
|
now = datetime.datetime.now()
|
||||||
print >>sys.stderr, now.strftime("Starting ansible-pull at %F %T")
|
print >>sys.stderr, now.strftime("Starting ansible-pull at %F %T")
|
||||||
|
|
||||||
|
inv_opts = 'localhost,'
|
||||||
limit_opts = 'localhost:%s:127.0.0.1' % socket.getfqdn()
|
limit_opts = 'localhost:%s:127.0.0.1' % socket.getfqdn()
|
||||||
git_opts = "repo=%s dest=%s version=%s" % (options.url, options.dest, options.checkout)
|
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)
|
rc = _run(cmd)
|
||||||
if rc != 0:
|
if rc != 0:
|
||||||
return rc
|
return rc
|
||||||
|
@ -129,6 +136,8 @@ def main(args):
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
cmd = 'ansible-playbook -c local --limit "%s" %s' % (limit_opts, playbook)
|
cmd = 'ansible-playbook -c local --limit "%s" %s' % (limit_opts, playbook)
|
||||||
|
if options.inventory:
|
||||||
|
cmd += ' -i "%s"' % options.inventory
|
||||||
os.chdir(options.dest)
|
os.chdir(options.dest)
|
||||||
rc = _run(cmd)
|
rc = _run(cmd)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue