Make galaxy work when API server not available
`ansible-galaxy init --offline ...` can create a role without talking to the galaxy api server `ansible-galaxy install ...` only needs to talk to the galaxy api server for galaxy roles, not tar files or scm archives Fixed a bug in command line role installation
This commit is contained in:
parent
31540246dd
commit
bf9ea81c4b
1 changed files with 21 additions and 16 deletions
|
@ -174,6 +174,9 @@ def build_option_parser(action):
|
|||
'-p', '--init-path', dest='init_path', default="./",
|
||||
help='The path in which the skeleton role will be created. '
|
||||
'The default is the current working directory.')
|
||||
parser.add_option(
|
||||
'--offline', dest='offline', default=False, action='store_true',
|
||||
help="Don't query the galaxy API when creating roles")
|
||||
elif action == "install":
|
||||
parser.set_usage("usage: %prog install [options] [-r FILE | role_name(s)[,version] | scm+role_repo_url[,version] | tar_file(s)]")
|
||||
parser.add_option(
|
||||
|
@ -573,11 +576,13 @@ def execute_init(args, options, parser):
|
|||
init_path = get_opt(options, 'init_path', './')
|
||||
api_server = get_opt(options, "api_server", "galaxy.ansible.com")
|
||||
force = get_opt(options, 'force', False)
|
||||
offline = get_opt(options, 'offline', False)
|
||||
|
||||
api_config = api_get_config(api_server)
|
||||
if not api_config:
|
||||
print "The API server (%s) is not responding, please try again later." % api_server
|
||||
sys.exit(1)
|
||||
if not offline:
|
||||
api_config = api_get_config(api_server)
|
||||
if not api_config:
|
||||
print "The API server (%s) is not responding, please try again later." % api_server
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
role_name = args.pop(0).strip()
|
||||
|
@ -623,12 +628,12 @@ def execute_init(args, options, parser):
|
|||
# datastructure in place, plus with all of the available
|
||||
# tags/platforms included (but commented out) and the
|
||||
# dependencies section
|
||||
platforms = api_get_list(api_server, "platforms")
|
||||
if not platforms:
|
||||
platforms = []
|
||||
categories = api_get_list(api_server, "categories")
|
||||
if not categories:
|
||||
categories = []
|
||||
platforms = []
|
||||
if not offline:
|
||||
platforms = api_get_list(api_server, "platforms") or []
|
||||
categories = []
|
||||
if not offline:
|
||||
categories = api_get_list(api_server, "categories") or []
|
||||
|
||||
# group the list of platforms from the api based
|
||||
# on their names, with the release field being
|
||||
|
@ -692,11 +697,6 @@ def execute_install(args, options, parser):
|
|||
print "Please specify a user/role name, or a roles file, but not both"
|
||||
sys.exit(1)
|
||||
|
||||
api_config = api_get_config(api_server)
|
||||
if not api_config:
|
||||
print "The API server (%s) is not responding, please try again later." % api_server
|
||||
sys.exit(1)
|
||||
|
||||
roles_done = []
|
||||
if role_file:
|
||||
f = open(role_file, 'r')
|
||||
|
@ -709,7 +709,7 @@ def execute_install(args, options, parser):
|
|||
else:
|
||||
# roles were specified directly, so we'll just go out grab them
|
||||
# (and their dependencies, unless the user doesn't want us to).
|
||||
roles_left = args
|
||||
roles_left = map(ansible.utils.role_spec_parse, args)
|
||||
|
||||
while len(roles_left) > 0:
|
||||
# query the galaxy API for the role data
|
||||
|
@ -730,6 +730,11 @@ def execute_install(args, options, parser):
|
|||
tmp_file = fetch_role(role_src, None, None, options)
|
||||
else:
|
||||
# installing from galaxy
|
||||
api_config = api_get_config(api_server)
|
||||
if not api_config:
|
||||
print "The API server (%s) is not responding, please try again later." % api_server
|
||||
sys.exit(1)
|
||||
|
||||
role_data = api_lookup_role_by_name(api_server, role_src)
|
||||
if not role_data:
|
||||
print "Sorry, %s was not found on %s." % (role_src, api_server)
|
||||
|
|
Loading…
Reference in a new issue