From 6751f6d32d95d9bf630463f1b164be108516d194 Mon Sep 17 00:00:00 2001 From: Javier Palacios Date: Sat, 13 Feb 2016 13:25:17 +0100 Subject: [PATCH 1/6] Use custom download url if supplied by galaxy --- bin/ansible-galaxy | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bin/ansible-galaxy b/bin/ansible-galaxy index 565dd89f599a93..9a295cbd7f7953 100755 --- a/bin/ansible-galaxy +++ b/bin/ansible-galaxy @@ -851,6 +851,10 @@ def execute_install(args, options, parser): exit_without_ignore(options) continue + matched_version = filter( lambda v : v['name'] == role['version'] , role_versions ) + if len(matched_version) == 1 : + role_src = matched_version[0].get('url', role_src) or role_src + # download the role. if --no-deps was specified, we stop here, # otherwise we recursively grab roles and all of their deps. tmp_file = fetch_role(role_src, role["version"], role_data, options) From 60a3ec82bf506470ae34c0bd3c6767daffafc226 Mon Sep 17 00:00:00 2001 From: Javier Palacios Date: Sat, 13 Feb 2016 14:23:51 +0100 Subject: [PATCH 2/6] Allow galaxy server to be specified on ansible.cfg --- bin/ansible-galaxy | 8 ++++---- lib/ansible/constants.py | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/bin/ansible-galaxy b/bin/ansible-galaxy index 9a295cbd7f7953..a6656938582881 100755 --- a/bin/ansible-galaxy +++ b/bin/ansible-galaxy @@ -207,7 +207,7 @@ def build_option_parser(action): if action in ("info","init","install"): parser.add_option( - '-s', '--server', dest='api_server', default="galaxy.ansible.com", + '-s', '--server', dest='api_server', default=C.DEFAULT_API_SERVER, help='The API server destination') parser.add_option('-c', '--ignore-certs', action='store_true', dest='ignore_certs', default=False, help='Ignore SSL certificate validation errors.') @@ -606,7 +606,7 @@ def execute_init(args, options, parser): """ init_path = get_opt(options, 'init_path', './') - api_server = get_opt(options, "api_server", "galaxy.ansible.com") + api_server = get_opt(options, "api_server", C.DEFAULT_API_SERVER) force = get_opt(options, 'force', False) offline = get_opt(options, 'offline', False) ignore_certs = get_opt(options, 'ignore_certs', False) @@ -709,7 +709,7 @@ def execute_info(args, options, parser): print "- you must specify a user/role name" sys.exit(1) - api_server = get_opt(options, "api_server", "galaxy.ansible.com") + api_server = get_opt(options, "api_server", C.DEFAULT_API_SERVER) api_config = api_get_config(api_server) roles_path = get_opt(options, "roles_path") ignore_certs = get_opt(options, "ignore_certs", False) @@ -778,7 +778,7 @@ def execute_install(args, options, parser): print "- please specify a user/role name, or a roles file, but not both" sys.exit(1) - api_server = get_opt(options, "api_server", "galaxy.ansible.com") + api_server = get_opt(options, "api_server", C.DEFAULT_API_SERVER) no_deps = get_opt(options, "no_deps", False) roles_path = get_opt(options, "roles_path") ignore_certs = get_opt(options, "ignore_certs") diff --git a/lib/ansible/constants.py b/lib/ansible/constants.py index 2cdc08d8ce87ac..3d4e183d043bc5 100644 --- a/lib/ansible/constants.py +++ b/lib/ansible/constants.py @@ -135,6 +135,7 @@ def shell_expand_path(path): DEFAULT_ASK_SU_PASS = get_config(p, DEFAULTS, 'ask_su_pass', 'ANSIBLE_ASK_SU_PASS', False, boolean=True) DEFAULT_GATHERING = get_config(p, DEFAULTS, 'gathering', 'ANSIBLE_GATHERING', 'implicit').lower() DEFAULT_LOG_PATH = shell_expand_path(get_config(p, DEFAULTS, 'log_path', 'ANSIBLE_LOG_PATH', '')) +DEFAULT_API_SERVER = get_config(p, DEFAULTS, 'api_server', 'ANSIBLE_API_SERVER', 'galaxy.ansible.com') # selinux DEFAULT_SELINUX_SPECIAL_FS = get_config(p, 'selinux', 'special_context_filesystems', None, 'fuse, nfs, vboxsf', islist=True) From c79c1c468e9442322b7357e3bb66cc4800368d5b Mon Sep 17 00:00:00 2001 From: Javier Palacios Date: Mon, 15 Feb 2016 13:39:03 +0100 Subject: [PATCH 3/6] Make HTTP schema explicit on galaxy server name --- bin/ansible-galaxy | 12 ++++++------ lib/ansible/constants.py | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/bin/ansible-galaxy b/bin/ansible-galaxy index a6656938582881..5f468d85203a9d 100755 --- a/bin/ansible-galaxy +++ b/bin/ansible-galaxy @@ -257,7 +257,7 @@ def api_get_config(api_server, ignore_certs=False): validate_certs = False try: - url = 'https://%s/api/' % api_server + url = '%s/api/' % api_server data = json.load(open_url(url, validate_certs=validate_certs)) if not data.get("current_version",None): return None @@ -288,7 +288,7 @@ def api_lookup_role_by_name(api_server, role_name, parser, notify=True, ignore_c print "- invalid role name (%s). Specify role as format: username.rolename" % role_name sys.exit(1) - url = 'https://%s/api/v1/roles/?owner__username=%s&name=%s' % (api_server,user_name,role_name) + url = '%s/api/v1/roles/?owner__username=%s&name=%s' % (api_server,user_name,role_name) try: data = json.load(open_url(url, validate_certs=validate_certs)) if len(data["results"]) == 0: @@ -309,12 +309,12 @@ def api_fetch_role_related(api_server, related, role_id, ignore_certs=False): validate_certs = False try: - url = 'https://%s/api/v1/roles/%d/%s/?page_size=50' % (api_server, int(role_id), related) + url = '%s/api/v1/roles/%d/%s/?page_size=50' % (api_server, int(role_id), related) data = json.load(open_url(url, validate_certs=validate_certs)) results = data['results'] done = (data.get('next_link', None) == None) while not done: - url = 'https://%s%s' % (api_server, data['next_link']) + url = '%s%s' % (api_server, data['next_link']) print url data = json.load(open_url(url)) results += data['results'] @@ -333,7 +333,7 @@ def api_get_list(api_server, what, ignore_certs=False): validate_certs = False try: - url = 'https://%s/api/v1/%s/?page_size' % (api_server, what) + url = '%s/api/v1/%s/?page_size' % (api_server, what) data = json.load(open_url(url, validate_certs=validate_certs)) if "results" in data: results = data['results'] @@ -343,7 +343,7 @@ def api_get_list(api_server, what, ignore_certs=False): if "next_link" in data: done = (data.get('next_link', None) == None) while not done: - url = 'https://%s%s' % (api_server, data['next_link']) + url = '%s%s' % (api_server, data['next_link']) print url data = json.load(open_url(url)) results += data['results'] diff --git a/lib/ansible/constants.py b/lib/ansible/constants.py index 3d4e183d043bc5..5371d1c0eee599 100644 --- a/lib/ansible/constants.py +++ b/lib/ansible/constants.py @@ -135,7 +135,7 @@ def shell_expand_path(path): DEFAULT_ASK_SU_PASS = get_config(p, DEFAULTS, 'ask_su_pass', 'ANSIBLE_ASK_SU_PASS', False, boolean=True) DEFAULT_GATHERING = get_config(p, DEFAULTS, 'gathering', 'ANSIBLE_GATHERING', 'implicit').lower() DEFAULT_LOG_PATH = shell_expand_path(get_config(p, DEFAULTS, 'log_path', 'ANSIBLE_LOG_PATH', '')) -DEFAULT_API_SERVER = get_config(p, DEFAULTS, 'api_server', 'ANSIBLE_API_SERVER', 'galaxy.ansible.com') +DEFAULT_API_SERVER = get_config(p, DEFAULTS, 'api_server', 'ANSIBLE_API_SERVER', 'https://galaxy.ansible.com') # selinux DEFAULT_SELINUX_SPECIAL_FS = get_config(p, 'selinux', 'special_context_filesystems', None, 'fuse, nfs, vboxsf', islist=True) From e89007dc6551b762031d5f7fa6b9635570989153 Mon Sep 17 00:00:00 2001 From: Javier Palacios Date: Tue, 16 Feb 2016 00:00:31 +0100 Subject: [PATCH 4/6] Use the same env var for galaxy than ansible 2.x --- lib/ansible/constants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ansible/constants.py b/lib/ansible/constants.py index 5371d1c0eee599..64db1436e85278 100644 --- a/lib/ansible/constants.py +++ b/lib/ansible/constants.py @@ -135,7 +135,7 @@ def shell_expand_path(path): DEFAULT_ASK_SU_PASS = get_config(p, DEFAULTS, 'ask_su_pass', 'ANSIBLE_ASK_SU_PASS', False, boolean=True) DEFAULT_GATHERING = get_config(p, DEFAULTS, 'gathering', 'ANSIBLE_GATHERING', 'implicit').lower() DEFAULT_LOG_PATH = shell_expand_path(get_config(p, DEFAULTS, 'log_path', 'ANSIBLE_LOG_PATH', '')) -DEFAULT_API_SERVER = get_config(p, DEFAULTS, 'api_server', 'ANSIBLE_API_SERVER', 'https://galaxy.ansible.com') +DEFAULT_API_SERVER = get_config(p, DEFAULTS, 'api_server', 'ANSIBLE_GALAXY_SERVER't , 'https://galaxy.ansible.com') # selinux DEFAULT_SELINUX_SPECIAL_FS = get_config(p, 'selinux', 'special_context_filesystems', None, 'fuse, nfs, vboxsf', islist=True) From 86fa08aa78051af851b56c23600f14c2cb6f365e Mon Sep 17 00:00:00 2001 From: Javier Palacios Date: Wed, 17 Feb 2016 17:22:51 +0100 Subject: [PATCH 5/6] Use specific galaxy section as done by 2.x --- bin/ansible-galaxy | 8 ++++---- lib/ansible/constants.py | 4 +++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/bin/ansible-galaxy b/bin/ansible-galaxy index 5f468d85203a9d..822279ce0aaa5e 100755 --- a/bin/ansible-galaxy +++ b/bin/ansible-galaxy @@ -207,7 +207,7 @@ def build_option_parser(action): if action in ("info","init","install"): parser.add_option( - '-s', '--server', dest='api_server', default=C.DEFAULT_API_SERVER, + '-s', '--server', dest='api_server', default=C.GALAXY_SERVER, help='The API server destination') parser.add_option('-c', '--ignore-certs', action='store_true', dest='ignore_certs', default=False, help='Ignore SSL certificate validation errors.') @@ -606,7 +606,7 @@ def execute_init(args, options, parser): """ init_path = get_opt(options, 'init_path', './') - api_server = get_opt(options, "api_server", C.DEFAULT_API_SERVER) + api_server = get_opt(options, "api_server", C.GALAXY_SERVER) force = get_opt(options, 'force', False) offline = get_opt(options, 'offline', False) ignore_certs = get_opt(options, 'ignore_certs', False) @@ -709,7 +709,7 @@ def execute_info(args, options, parser): print "- you must specify a user/role name" sys.exit(1) - api_server = get_opt(options, "api_server", C.DEFAULT_API_SERVER) + api_server = get_opt(options, "api_server", C.GALAXY_SERVER) api_config = api_get_config(api_server) roles_path = get_opt(options, "roles_path") ignore_certs = get_opt(options, "ignore_certs", False) @@ -778,7 +778,7 @@ def execute_install(args, options, parser): print "- please specify a user/role name, or a roles file, but not both" sys.exit(1) - api_server = get_opt(options, "api_server", C.DEFAULT_API_SERVER) + api_server = get_opt(options, "api_server", C.GALAXY_SERVER) no_deps = get_opt(options, "no_deps", False) roles_path = get_opt(options, "roles_path") ignore_certs = get_opt(options, "ignore_certs") diff --git a/lib/ansible/constants.py b/lib/ansible/constants.py index 64db1436e85278..e9f4d23ebc3de2 100644 --- a/lib/ansible/constants.py +++ b/lib/ansible/constants.py @@ -135,7 +135,9 @@ def shell_expand_path(path): DEFAULT_ASK_SU_PASS = get_config(p, DEFAULTS, 'ask_su_pass', 'ANSIBLE_ASK_SU_PASS', False, boolean=True) DEFAULT_GATHERING = get_config(p, DEFAULTS, 'gathering', 'ANSIBLE_GATHERING', 'implicit').lower() DEFAULT_LOG_PATH = shell_expand_path(get_config(p, DEFAULTS, 'log_path', 'ANSIBLE_LOG_PATH', '')) -DEFAULT_API_SERVER = get_config(p, DEFAULTS, 'api_server', 'ANSIBLE_GALAXY_SERVER't , 'https://galaxy.ansible.com') + +# galaxy related +GALAXY_SERVER = get_config(p, 'galaxy', 'server', 'ANSIBLE_GALAXY_SERVER', 'https://galaxy.ansible.com') # selinux DEFAULT_SELINUX_SPECIAL_FS = get_config(p, 'selinux', 'special_context_filesystems', None, 'fuse, nfs, vboxsf', islist=True) From 56c1db9ac3167ae9526ce9aed75679d16f8c2e7c Mon Sep 17 00:00:00 2001 From: Javier Palacios Date: Wed, 9 Mar 2016 22:05:49 +0100 Subject: [PATCH 6/6] Use a non-existing key to hold download url --- bin/ansible-galaxy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/ansible-galaxy b/bin/ansible-galaxy index 822279ce0aaa5e..c4addcfb387511 100755 --- a/bin/ansible-galaxy +++ b/bin/ansible-galaxy @@ -853,7 +853,7 @@ def execute_install(args, options, parser): matched_version = filter( lambda v : v['name'] == role['version'] , role_versions ) if len(matched_version) == 1 : - role_src = matched_version[0].get('url', role_src) or role_src + role_src = matched_version[0].get('download', role_src) or role_src # download the role. if --no-deps was specified, we stop here, # otherwise we recursively grab roles and all of their deps.