mirror of
https://github.com/trailofbits/algo.git
synced 2025-06-06 15:13:56 +02:00
Fix SSH keys for DigitalOcean
This commit is contained in:
parent
2c9c3ccb09
commit
33b3af540a
1 changed files with 11 additions and 32 deletions
|
@ -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
|
||||
- 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
|
||||
|
||||
- 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: "Getting your SSH key ID on Digital Ocean..."
|
||||
- name: "Upload the SSH key"
|
||||
digital_ocean:
|
||||
state: present
|
||||
command: ssh
|
||||
|
|
Loading…
Add table
Reference in a new issue