|
|
|
@ -67,3 +67,36 @@
|
|
|
|
|
|
|
|
|
|
- set_fact:
|
|
|
|
|
cloud_instance_ip: "{{ do.droplet.ip_address }}"
|
|
|
|
|
|
|
|
|
|
- name: Tag the groplet
|
|
|
|
|
digital_ocean_tag:
|
|
|
|
|
name: "Environment:Algo"
|
|
|
|
|
resource_id: "{{ do.droplet.id }}"
|
|
|
|
|
api_token: "{{ do_access_token }}"
|
|
|
|
|
state: present
|
|
|
|
|
|
|
|
|
|
- name: Get droplets
|
|
|
|
|
uri:
|
|
|
|
|
url: "https://api.digitalocean.com/v2/droplets?tag_name=Environment:Algo"
|
|
|
|
|
method: GET
|
|
|
|
|
status_code: 200
|
|
|
|
|
headers:
|
|
|
|
|
Content-Type: "application/json"
|
|
|
|
|
Authorization: "Bearer {{ do_access_token }}"
|
|
|
|
|
register: do_droplets
|
|
|
|
|
|
|
|
|
|
- name: Ensure the group ec2 exists in the dynamic inventory file
|
|
|
|
|
lineinfile:
|
|
|
|
|
state: present
|
|
|
|
|
dest: configs/inventory.dynamic
|
|
|
|
|
line: '[digitalocean]'
|
|
|
|
|
|
|
|
|
|
- name: Populate the dynamic inventory
|
|
|
|
|
lineinfile:
|
|
|
|
|
state: present
|
|
|
|
|
dest: configs/inventory.dynamic
|
|
|
|
|
insertafter: '\[digitalocean\]'
|
|
|
|
|
regexp: "^{{ item.networks.v4[0].ip_address }}.*"
|
|
|
|
|
line: "{{ item.networks.v4[0].ip_address }}"
|
|
|
|
|
with_items:
|
|
|
|
|
- "{{ do_droplets.json.droplets }}"
|
|
|
|
|