Fix SSH keys for DigitalOcean

pull/171/head
Jack Ivanov 8 years ago
parent 2c9c3ccb09
commit 33b3af540a

@ -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

Loading…
Cancel
Save