Permalink
Fetching contributors…
Cannot retrieve contributors at this time
51 lines (45 sloc) 1.71 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:
state: "{{ item.state | default('present') }}"
command: droplet
name: "{{ item.name }}"
private_networking: yes
size_id: "{{ item.size | default('512mb') }}"
image_id: "{{ item.image | default('centos-6-5-x32') }}"
region_id: "{{ item.region | default('nyc2') }}"
# Customize this default for your account.
ssh_key_ids: "{{ 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.droplet.ip_address }}"
groups: "do,{{ droplets[item.0].group }},{{ item.1.droplet.name }}"
# You can dynamically add inventory variables per-host.
ansible_ssh_user: root
mysql_replication_role: >
"{{ 'master' if (item.1.droplet.name == 'a4d.lamp.db.1')
else 'slave' }}"
mysql_server_id: "{{ item.0 }}"
when: item.1.droplet is defined
with_indexed_items: "{{ created_droplets.results }}"
- hosts: do
remote_user: root
gather_facts: false
tasks:
- name: Wait for port 22 to become available.
local_action: "wait_for port=22 host={{ inventory_hostname }}"