Skip to content
Permalink
master
Switch branches/tags
Go to file
 
 
Cannot retrieve contributors at this time
50 lines (45 sloc) 1.65 KB
---
- hosts: localhost
connection: local
gather_facts: false
vars:
droplets:
- { name: a4d.lamp.varnish, group: "lamp_varnish" }
- { name: a4d.lamp.www.1, group: "lamp_www" }
- { name: a4d.lamp.www.2, group: "lamp_www" }
- { name: a4d.lamp.db.1, group: "lamp_db" }
- { name: a4d.lamp.db.2, group: "lamp_db" }
- { name: a4d.lamp.memcached, group: "lamp_memcached" }
tasks:
- name: Provision DigitalOcean droplets.
digital_ocean_droplet:
state: "{{ item.state | default('present') }}"
name: "{{ item.name }}"
private_networking: yes
size: "{{ item.size | default('1gb') }}"
image: "{{ item.image | default('centos-7-x64') }}"
region: "{{ item.region | default('nyc3') }}"
# Customize this default for your account.
ssh_keys:
- "{{ item.ssh_key | default('138954') }}"
unique_name: yes
register: created_droplets
with_items: "{{ droplets }}"
- name: Add DigitalOcean hosts to inventory groups.
add_host:
name: "{{ item.1.data.ip_address }}"
groups: "do,{{ droplets[item.0].group }},{{ item.1.data.droplet.name }}"
# You can dynamically add inventory variables per-host.
ansible_user: root
mysql_replication_role: >-
{{ 'master' if (item.1.data.droplet.name == 'a4d.lamp.db.1')
else 'slave' }}
mysql_server_id: "{{ item.0 }}"
when: item.1.data is defined
with_indexed_items: "{{ created_droplets.results }}"
- hosts: do
remote_user: root
gather_facts: false
tasks:
- name: Wait for hosts to become reachable.
wait_for_connection: