From dab15647470825cdeb09c28fdf2d046802cb013a Mon Sep 17 00:00:00 2001 From: Aleksandr Petrenko Date: Wed, 10 Jul 2019 16:23:35 +0300 Subject: [PATCH 1/8] Change method to post for update_admin_password script --- tasks/declare_script_each.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/declare_script_each.yml b/tasks/declare_script_each.yml index ad46e4f..70b9622 100644 --- a/tasks/declare_script_each.yml +++ b/tasks/declare_script_each.yml @@ -4,7 +4,7 @@ url: "http://localhost:{{ nexus_default_port }}{{ nexus_default_context_path }}service/siesta/rest/v1/script/{{ item }}" user: 'admin' password: "{{ current_nexus_admin_password }}" - method: DELETE + method: POST force_basic_auth: yes status_code: 204,404 From 58ea075ef762ab0e7c8491fd203697d42102bcd2 Mon Sep 17 00:00:00 2001 From: Aleksandr Petrenko Date: Tue, 13 Aug 2019 15:29:22 +0300 Subject: [PATCH 2/8] Fix Nexus api URL --- defaults/main.yml | 1 + tasks/call_script.yml | 2 +- tasks/declare_script_each.yml | 4 ++-- tasks/main.yml | 5 +++++ 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index 861a60e..158c85d 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -27,6 +27,7 @@ nexus_docker_hosted_port: 9080 nexus_docker_proxy_port: 9081 nexus_docker_group_port: 9082 nexus_default_context_path: '/' +nexus_api_url: 'service/siesta/rest/v1/script/' nexus_admin_password: 'changeme' # Note : admin password change subsequent to first-time install is *not implemented* yet nexus_anonymous_access: false diff --git a/tasks/call_script.yml b/tasks/call_script.yml index 6cb1d57..7c5fc31 100644 --- a/tasks/call_script.yml +++ b/tasks/call_script.yml @@ -1,7 +1,7 @@ --- - name: Calling Groovy script {{ script_name }} uri: - url: "http://localhost:{{ nexus_default_port }}{{ nexus_default_context_path }}service/siesta/rest/v1/script/{{ script_name }}/run" + url: "http://localhost:{{ nexus_default_port }}{{ nexus_default_context_path }}{{ nexus_api_url }}{{ script_name }}/run" user: 'admin' password: "{{ current_nexus_admin_password }}" headers: diff --git a/tasks/declare_script_each.yml b/tasks/declare_script_each.yml index 70b9622..e8fce75 100644 --- a/tasks/declare_script_each.yml +++ b/tasks/declare_script_each.yml @@ -1,7 +1,7 @@ --- - name: Removing (potential) previously declared Groovy script {{ item }} uri: - url: "http://localhost:{{ nexus_default_port }}{{ nexus_default_context_path }}service/siesta/rest/v1/script/{{ item }}" + url: "http://localhost:{{ nexus_default_port }}{{ nexus_default_context_path }}{{ nexus_api_url }}{{ item }}" user: 'admin' password: "{{ current_nexus_admin_password }}" method: POST @@ -10,7 +10,7 @@ - name: Declaring Groovy script {{ item }} uri: - url: "http://localhost:{{ nexus_default_port }}{{ nexus_default_context_path }}service/siesta/rest/v1/script" + url: "http://localhost:{{ nexus_default_port }}{{ nexus_default_context_path }}{{ nexus_api_url }}" user: 'admin' password: "{{ current_nexus_admin_password }}" body_format: json diff --git a/tasks/main.yml b/tasks/main.yml index 2943b6e..549b55d 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,4 +1,9 @@ --- +- name: Setup api url and http method + set_fact: + nexus_api_url: 'service/rest/v1/script/' + when: nexus_version | match('3.17.0-01') + - include: nexus_purge.yml when: ((purge is defined) and (purge | bool)) From 7cb2b5e2fb6d4bedb38e06970672d90c25a55610 Mon Sep 17 00:00:00 2001 From: Aleksandr Petrenko Date: Tue, 13 Aug 2019 15:44:43 +0300 Subject: [PATCH 3/8] Fix Error 405: Method POST is not supported by this URL - Removing (potential) previously declared Groovy script --- tasks/declare_script_each.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/declare_script_each.yml b/tasks/declare_script_each.yml index e8fce75..5321373 100644 --- a/tasks/declare_script_each.yml +++ b/tasks/declare_script_each.yml @@ -4,7 +4,7 @@ url: "http://localhost:{{ nexus_default_port }}{{ nexus_default_context_path }}{{ nexus_api_url }}{{ item }}" user: 'admin' password: "{{ current_nexus_admin_password }}" - method: POST + method: GET force_basic_auth: yes status_code: 204,404 From 771e5e0f48e85928572c95814d45ab498b696f3c Mon Sep 17 00:00:00 2001 From: Aleksandr Petrenko Date: Tue, 13 Aug 2019 17:00:47 +0300 Subject: [PATCH 4/8] Add version 3.18 to condition --- tasks/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/main.yml b/tasks/main.yml index 549b55d..bcaaed0 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -2,7 +2,7 @@ - name: Setup api url and http method set_fact: nexus_api_url: 'service/rest/v1/script/' - when: nexus_version | match('3.17.0-01') + when: (nexus_version | match('3.17.0-01')) or (nexus_version | match('3.18.1-01')) - include: nexus_purge.yml when: ((purge is defined) and (purge | bool)) From 76b02b3c6be7f2321bc8b51c3892174280b7d968 Mon Sep 17 00:00:00 2001 From: Aleksandr Petrenko Date: Tue, 13 Aug 2019 17:10:55 +0300 Subject: [PATCH 5/8] Add status code 200 to Removing (potential) previously declared Groovy script --- tasks/declare_script_each.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/declare_script_each.yml b/tasks/declare_script_each.yml index 5321373..12ce2ae 100644 --- a/tasks/declare_script_each.yml +++ b/tasks/declare_script_each.yml @@ -6,7 +6,7 @@ password: "{{ current_nexus_admin_password }}" method: GET force_basic_auth: yes - status_code: 204,404 + status_code: 200,204,404 - name: Declaring Groovy script {{ item }} uri: From 57a07157ac3584bba559733d66763ece5cd8d121 Mon Sep 17 00:00:00 2001 From: Aleksandr Petrenko Date: Tue, 13 Aug 2019 18:00:47 +0300 Subject: [PATCH 6/8] Try DELETE method in Removing (potential) previously declared Groovy script --- tasks/declare_script_each.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/declare_script_each.yml b/tasks/declare_script_each.yml index 12ce2ae..72cdf94 100644 --- a/tasks/declare_script_each.yml +++ b/tasks/declare_script_each.yml @@ -4,7 +4,7 @@ url: "http://localhost:{{ nexus_default_port }}{{ nexus_default_context_path }}{{ nexus_api_url }}{{ item }}" user: 'admin' password: "{{ current_nexus_admin_password }}" - method: GET + method: DELETE force_basic_auth: yes status_code: 200,204,404 From 581e9f3d39a4dd26861be00b538633db9ed267b0 Mon Sep 17 00:00:00 2001 From: Aleksandr Petrenko Date: Thu, 15 Aug 2019 14:03:53 +0300 Subject: [PATCH 7/8] Determine minor version of Nexus and set API URL https://github.com/ansible-ThoTeam/nexus3-oss/issues/14 --- defaults/main.yml | 1 + tasks/main.yml | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index 158c85d..dbe8c76 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -28,6 +28,7 @@ nexus_docker_proxy_port: 9081 nexus_docker_group_port: 9082 nexus_default_context_path: '/' nexus_api_url: 'service/siesta/rest/v1/script/' +nexus_new_api_url: 'service/rest/v1/script/' nexus_admin_password: 'changeme' # Note : admin password change subsequent to first-time install is *not implemented* yet nexus_anonymous_access: false diff --git a/tasks/main.yml b/tasks/main.yml index bcaaed0..1928dff 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,8 +1,14 @@ --- -- name: Setup api url and http method +- name: Determine minor version of Nexus set_fact: - nexus_api_url: 'service/rest/v1/script/' - when: (nexus_version | match('3.17.0-01')) or (nexus_version | match('3.18.1-01')) + minor_nexus_version: "{{ nexus_version | regex_search(regexp,'\\1') }}" + vars: + regexp: '3\.(\d+)\..*' + +- name: Set API URL + set_fact: + nexus_api_url: "{{ nexus_new_api_url }}" + when: minor_nexus_version >= 8 - include: nexus_purge.yml when: ((purge is defined) and (purge | bool)) From c5571940605756f18d9579d1b52fafedc862472d Mon Sep 17 00:00:00 2001 From: Aleksandr Petrenko Date: Thu, 15 Aug 2019 17:44:32 +0300 Subject: [PATCH 8/8] Add nexus_download_url to defaults --- defaults/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/defaults/main.yml b/defaults/main.yml index dbe8c76..07d4fa4 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,4 +1,5 @@ --- +nexus_download_url: "http://download.sonatype.com/nexus/3/" nexus_version: '3.3.1-01' nexus_package: "nexus-{{ nexus_version }}-unix.tar.gz" nexus_download_dir: '/tmp'