mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
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="./",
|
'-p', '--init-path', dest='init_path', default="./",
|
||||||
help='The path in which the skeleton role will be created. '
|
help='The path in which the skeleton role will be created. '
|
||||||
'The default is the current working directory.')
|
'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":
|
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.set_usage("usage: %prog install [options] [-r FILE | role_name(s)[,version] | scm+role_repo_url[,version] | tar_file(s)]")
|
||||||
parser.add_option(
|
parser.add_option(
|
||||||
|
@ -573,11 +576,13 @@ def execute_init(args, options, parser):
|
||||||
init_path = get_opt(options, 'init_path', './')
|
init_path = get_opt(options, 'init_path', './')
|
||||||
api_server = get_opt(options, "api_server", "galaxy.ansible.com")
|
api_server = get_opt(options, "api_server", "galaxy.ansible.com")
|
||||||
force = get_opt(options, 'force', False)
|
force = get_opt(options, 'force', False)
|
||||||
|
offline = get_opt(options, 'offline', False)
|
||||||
|
|
||||||
api_config = api_get_config(api_server)
|
if not offline:
|
||||||
if not api_config:
|
api_config = api_get_config(api_server)
|
||||||
print "The API server (%s) is not responding, please try again later." % api_server
|
if not api_config:
|
||||||
sys.exit(1)
|
print "The API server (%s) is not responding, please try again later." % api_server
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
role_name = args.pop(0).strip()
|
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
|
# datastructure in place, plus with all of the available
|
||||||
# tags/platforms included (but commented out) and the
|
# tags/platforms included (but commented out) and the
|
||||||
# dependencies section
|
# dependencies section
|
||||||
platforms = api_get_list(api_server, "platforms")
|
platforms = []
|
||||||
if not platforms:
|
if not offline:
|
||||||
platforms = []
|
platforms = api_get_list(api_server, "platforms") or []
|
||||||
categories = api_get_list(api_server, "categories")
|
categories = []
|
||||||
if not categories:
|
if not offline:
|
||||||
categories = []
|
categories = api_get_list(api_server, "categories") or []
|
||||||
|
|
||||||
# group the list of platforms from the api based
|
# group the list of platforms from the api based
|
||||||
# on their names, with the release field being
|
# 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"
|
print "Please specify a user/role name, or a roles file, but not both"
|
||||||
sys.exit(1)
|
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 = []
|
roles_done = []
|
||||||
if role_file:
|
if role_file:
|
||||||
f = open(role_file, 'r')
|
f = open(role_file, 'r')
|
||||||
|
@ -709,7 +709,7 @@ def execute_install(args, options, parser):
|
||||||
else:
|
else:
|
||||||
# roles were specified directly, so we'll just go out grab them
|
# roles were specified directly, so we'll just go out grab them
|
||||||
# (and their dependencies, unless the user doesn't want us to).
|
# (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:
|
while len(roles_left) > 0:
|
||||||
# query the galaxy API for the role data
|
# 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)
|
tmp_file = fetch_role(role_src, None, None, options)
|
||||||
else:
|
else:
|
||||||
# installing from galaxy
|
# 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)
|
role_data = api_lookup_role_by_name(api_server, role_src)
|
||||||
if not role_data:
|
if not role_data:
|
||||||
print "Sorry, %s was not found on %s." % (role_src, api_server)
|
print "Sorry, %s was not found on %s." % (role_src, api_server)
|
||||||
|
|
Loading…
Reference in a new issue