diff --git a/roles/cloud-digitalocean/tasks/main.yml b/roles/cloud-digitalocean/tasks/main.yml index 6faa173..3461485 100644 --- a/roles/cloud-digitalocean/tasks/main.yml +++ b/roles/cloud-digitalocean/tasks/main.yml @@ -3,39 +3,18 @@ do_token: "{{ do_access_token }}" public_key: "{{ lookup('file', '{{ SSH_keys.public }}') }}" -- name: Get existing SSH keys - uri: - url: https://api.digitalocean.com/v2/account/keys - method: GET - HEADER_Content-Type: 'application/json' - HEADER_Authorization: "Bearer {{ do_access_token }}" - status_code: 200 - body_format: json - register: do_existing_keys - -- set_fact: - ssh_key_exist: true - when: public_key == item.public_key - with_items: - - "{{ do_existing_keys.json.ssh_keys }}" - -- name: Upload the SSH key - uri: - url: https://api.digitalocean.com/v2/account/keys - method: POST - HEADER_Content-Type: 'application/json' - HEADER_Authorization: "Bearer {{ do_access_token }}" - body: > - { - "name" : "{{ SSH_keys.comment }}", - "public_key" : "{{ public_key }}" - } - status_code: 201 - body_format: json - register: do_ssh_key - when: ssh_key_exist is not defined +- name: "Delete the existing Algo SSH keys" + digital_ocean: + state: absent + command: ssh + api_token: "{{ do_access_token }}" + name: "{{ SSH_keys.comment }}" + register: ssh_keys + until: ssh_keys.changed != 1 + retries: 10 + delay: 1 -- name: "Getting your SSH key ID on Digital Ocean..." +- name: "Upload the SSH key" digital_ocean: state: present command: ssh