From d0519b49105b60b163f4e4690dc7b6e4ae125d82 Mon Sep 17 00:00:00 2001 From: Marco Massari Calderone Date: Thu, 28 Jun 2018 16:11:04 -0500 Subject: [PATCH] first test of retriving duplicate inactive systems from JC --- README.md | 2 +- tasks/check_system_registration.yml | 6 ------ tasks/find_registered_systems.yml | 29 +++++++++++++++++++++++++++++ tasks/main.yml | 6 ++++++ 4 files changed, 36 insertions(+), 7 deletions(-) create mode 100644 tasks/find_registered_systems.yml diff --git a/README.md b/README.md index 130b85c..dc6a91b 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ Default: `no` Whether or not to use sudo during installation. -#### [`jumpcloud_tags`][jumpcloud-tagsh] +#### [`jumpcloud_tags`][jumpcloud-tags] The list of JC tags you want a host or a group of hosts to be part of - 'tag_one' diff --git a/tasks/check_system_registration.yml b/tasks/check_system_registration.yml index a3495ea..9860002 100644 --- a/tasks/check_system_registration.yml +++ b/tasks/check_system_registration.yml @@ -7,12 +7,6 @@ "Content-Type": "application/json" "Accept": "application/json" "x-api-key": "{{ jumpcloud_api_key }}" - body_format: json - body: '{ "displayName" : "{{ jumpcloud_displayName }}", - "allowPublicKeyAuthentication" : "{{ jumpcloud_allowPublicKeyAuthentication }}", - "allowSshPasswordAuthentication" : "{{ jumpcloud_allowSshPasswordAuthentication }}", - "allowSshRootLogin" : "{{ jumpcloud_allowSshRootLogin }}", - "allowMultiFactorAuthentication" : "{{ jumpcloud_allowMultiFactorAuthentication }}" }' follow_redirects: all return_content: yes status_code: 200 diff --git a/tasks/find_registered_systems.yml b/tasks/find_registered_systems.yml new file mode 100644 index 0000000..0fc8fe7 --- /dev/null +++ b/tasks/find_registered_systems.yml @@ -0,0 +1,29 @@ +--- +- name: Retrive the list of registeed systems with the same name + uri: + url: "{{ jumpcloud_api_v1_url }}/search/systems" + method: POST + headers: + "Content-Type": "application/json" + "Accept": "application/json" + "x-api-key": "{{ jumpcloud_api_key }}" + body_format: json + body: '{ "filter" : + {"and" : + [{ "displayName" : "{{ jumpcloud_displayName }}" }, + {"active" : "false" }] + }, + "fields": "displayName _id" }' + follow_redirects: all + return_content: yes + status_code: 200 + delegate_to: localhost + register: jc_registered_systems_json_response + when: jumpcloud_displayName is defined + ignore_errors: yes + +- debug: + var: jc_registered_systems_json_response + +- pause: +... diff --git a/tasks/main.yml b/tasks/main.yml index f5e1284..933332a 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -26,10 +26,16 @@ jumpcloud_system_key: "{{ jumpcloud_system_key_result.stdout }}" when: jumpcloud_is_installed +- debug: + var: jumpcloud_system_key + - name: Check System Registration import_tasks: check_system_registration.yml when: jumpcloud_system_key is defined +- name: Find Registered Systems with the same name + import_tasks: find_registered_systems.yml + - name: Update System Attributes if the System is registered in JumpCloud import_tasks: update_system.yml when: jc_system_is_registered