Fix SSH keys for DigitalOcean

This commit is contained in:
Jack Ivanov 2016-12-19 00:19:26 +03:00
parent 2c9c3ccb09
commit 33b3af540a

View file

@ -3,39 +3,18 @@
do_token: "{{ do_access_token }}" do_token: "{{ do_access_token }}"
public_key: "{{ lookup('file', '{{ SSH_keys.public }}') }}" public_key: "{{ lookup('file', '{{ SSH_keys.public }}') }}"
- name: Get existing SSH keys - name: "Delete the existing Algo SSH keys"
uri: digital_ocean:
url: https://api.digitalocean.com/v2/account/keys state: absent
method: GET command: ssh
HEADER_Content-Type: 'application/json' api_token: "{{ do_access_token }}"
HEADER_Authorization: "Bearer {{ do_access_token }}" name: "{{ SSH_keys.comment }}"
status_code: 200 register: ssh_keys
body_format: json until: ssh_keys.changed != 1
register: do_existing_keys retries: 10
delay: 1
- set_fact: - name: "Upload the SSH key"
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..."
digital_ocean: digital_ocean:
state: present state: present
command: ssh command: ssh