Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ansible/ansible-examples.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbennojoy <benno@ansibleworks.com>2013-08-29 17:19:58 +0400
committerbennojoy <benno@ansibleworks.com>2013-08-29 17:19:58 +0400
commit42a1575fb99d36b71a6a8cd17a518b8bae986530 (patch)
treedba8abe58542acabc04657def70196fecd59605d
parent403f50fbad507f70636d089981dccec2958ae836 (diff)
openshift ec2 remove
-rw-r--r--openshift/ec2.yml77
-rw-r--r--openshift/ec2_remove.yml23
-rw-r--r--openshift/group_vars/all2
-rw-r--r--openshift/remove_ec2.yml27
-rw-r--r--openshift/roles/ec2/tasks/main.yml30
-rw-r--r--openshift/roles/ec2_remove/tasks/main.yml25
6 files changed, 102 insertions, 82 deletions
diff --git a/openshift/ec2.yml b/openshift/ec2.yml
index c483bc9..67a8e1e 100644
--- a/openshift/ec2.yml
+++ b/openshift/ec2.yml
@@ -1,55 +1,33 @@
- hosts: localhost
connection: local
- tasks:
+ pre_tasks:
- fail: msg=" Please make sure the variables id is specified and unique in the command line -e id=uniquedev1"
when: id is not defined
- - name: Create Instance
- ec2: >
- region="{{ region }}"
- zone="{{ zone }}"
- id="{{ id }}"
- ec2_access_key="{{ ec2_access_key }}"
- ec2_secret_key="{{ ec2_secret_key }}"
- keypair="{{ keypair }}"
- instance_type="{{ instance_type }}"
- image="{{ image }}"
- wait=true
- group="{{ group }}"
- instance_tags='{"type": "openshift_servers", "id":"{{ id }}"}'
- count="{{ count }}"
- register: ec2
-
- - name: Wait for the instance to come up
- wait_for: delay=10 host={{ item.public_dns_name }} port=22 state=started timeout=360
- with_items: ec2.instances
-
- - pause: seconds=60
-
- - name: Add new instance to host group dns
- add_host: hostname={{ ec2.instances[0].public_dns_name }} groupname=dns
-
- - name: Add new instance to host group mongo
- add_host: hostname={{ ec2.instances[item|int()].public_dns_name }} groupname="mongo_servers"
- with_sequence: start=0 end=2
-
- - name: Add new instance to host group mq
- add_host: hostname={{ ec2.instances[item| int()].public_dns_name }} groupname="mq"
- with_sequence: start=0 end=2
+ roles:
+ - role: ec2
+ type: dns
+ ncount: 1
- - name: Add new instance to host group broker
- add_host: hostname={{ ec2.instances[item| int()].public_dns_name }} groupname=broker
- with_sequence: start=0 end=1
+ - role: ec2
+ type: mq
+ ncount: 3
- - name: Add new instance to host group broker
- set_fact: >
- broker1="{{ ec2.instances[0].id }}"
- broker2="{{ ec2.instances[1].id }}"
+ - role: ec2
+ type: broker
+ ncount: 2
- - name: Add new instance to host group nodes
- add_host: hostname={{ ec2.instances[item| int()].public_dns_name }} groupname=nodes
- with_sequence: start=3 end={{ count|int - 1 }}
-
+ - role: ec2
+ type: nodes
+ ncount: "{{ count }}"
+
+ post_tasks:
+ - name: Wait for the instance to come up
+ wait_for: delay=10 host={{ item.public_dns_name }} port=22 state=started timeout=360
+ with_items: ec2.instances
+
+ - debug: msg="{{ groups }}"
+
- hosts: all:!localhost
user: root
roles:
@@ -59,6 +37,7 @@
user: root
roles:
- role: dns
+
- hosts: mongo_servers
user: root
roles:
@@ -79,14 +58,4 @@
roles:
- role: nodes
-- hosts: localhost
- gather_facts: no
- connection: local
- tasks:
- - name: Add the Instance to elb
- ec2_elb: region={{ region }} ec2_access_key={{ ec2_access_key }} ec2_secret_key={{ ec2_secret_key }} ec2_elbs={{ ec2_elbs }} instance_id={{ item }} state=present
- with_items:
- - "{{ broker1 }}"
- - "{{ broker2 }}"
- when: ec2_elbs is defined
diff --git a/openshift/ec2_remove.yml b/openshift/ec2_remove.yml
new file mode 100644
index 0000000..c667dd3
--- /dev/null
+++ b/openshift/ec2_remove.yml
@@ -0,0 +1,23 @@
+- hosts: localhost
+ connection: local
+ pre_tasks:
+ - fail: msg=" Please make sure the variables id is specified and unique in the command line -e id=uniquedev1"
+ when: id is not defined
+
+ roles:
+ - role: ec2_remove
+ type: dns
+ ncount: 1
+
+ - role: ec2_remove
+ type: mq
+ ncount: 3
+
+ - role: ec2_remove
+ type: broker
+ ncount: 2
+
+ - role: ec2_remove
+ type: nodes
+ ncount: "{{ count }}"
+
diff --git a/openshift/group_vars/all b/openshift/group_vars/all
index a18dadb..e76015e 100644
--- a/openshift/group_vars/all
+++ b/openshift/group_vars/all
@@ -8,7 +8,7 @@ keypair: "axialkey"
instance_type: "m1.small"
image: "ami-bf5021d6"
group: "default"
-count: 5
+count: 2
ec2_elbs: oselb
region: "us-east-1"
zone: "us-east-1a"
diff --git a/openshift/remove_ec2.yml b/openshift/remove_ec2.yml
deleted file mode 100644
index 1ca4975..0000000
--- a/openshift/remove_ec2.yml
+++ /dev/null
@@ -1,27 +0,0 @@
-- hosts: all
- connection: local
- gather_facts: no
- tasks:
- - fail: msg=" Please make sure the variables id is specified and unique in the command line -e id=uniquedev1"
- when: id is not defined
- - name: Create Instance
- ec2: >
- region="{{ region }}"
- zone="{{ zone }}"
- id="{{ id }}"
- ec2_access_key="{{ ec2_access_key }}"
- ec2_secret_key="{{ ec2_secret_key }}"
- keypair="{{ keypair }}"
- instance_type="{{ instance_type }}"
- image="{{ image }}"
- wait=true
- group="{{ group }}"
- instance_tags='{"type": "openshift_servers", "id":"{{ id }}"}'
- count="{{ count }}"
- register: ec2
-
- - name: Delete Instance
- ec2:
- state: 'absent'
- instance_ids: "{{ item }}"
- with_items: ec2.instance_ids
diff --git a/openshift/roles/ec2/tasks/main.yml b/openshift/roles/ec2/tasks/main.yml
new file mode 100644
index 0000000..8136ffb
--- /dev/null
+++ b/openshift/roles/ec2/tasks/main.yml
@@ -0,0 +1,30 @@
+---
+- name: Create Instance
+ ec2: >
+ region="{{ region }}"
+ zone="{{ zone }}"
+ id="{{ id + '_' + type }}"
+ ec2_access_key="{{ ec2_access_key }}"
+ ec2_secret_key="{{ ec2_secret_key }}"
+ keypair="{{ keypair }}"
+ instance_type="{{ instance_type }}"
+ image="{{ image }}"
+ group="{{ group }}"
+ wait=true
+ user_data="{{ type }}"
+ instance_tags='{"type":"{{ type }}", "id":"{{ id }}"}'
+ count="{{ ncount }}"
+ register: ec2
+
+- pause: seconds=60
+ when: type == 'nodes'
+
+- name: Add new instance to host group
+ add_host: hostname={{ item.public_dns_name }} groupname={{ type }}
+ with_items: ec2.instances
+ when: type != 'mq'
+
+- name: Add new instance to host group
+ add_host: hostname={{ item.public_dns_name }} groupname="mq,mongo_servers"
+ with_items: ec2.instances
+ when: type == 'mq'
diff --git a/openshift/roles/ec2_remove/tasks/main.yml b/openshift/roles/ec2_remove/tasks/main.yml
new file mode 100644
index 0000000..1e93667
--- /dev/null
+++ b/openshift/roles/ec2_remove/tasks/main.yml
@@ -0,0 +1,25 @@
+---
+
+- name: Create Instance
+ ec2: >
+ region="{{ region }}"
+ zone="{{ zone }}"
+ id="{{ id + '_' + type }}"
+ ec2_access_key="{{ ec2_access_key }}"
+ ec2_secret_key="{{ ec2_secret_key }}"
+ keypair="{{ keypair }}"
+ instance_type="{{ instance_type }}"
+ image="{{ image }}"
+ group="{{ group }}"
+ wait=true
+ count="{{ ncount }}"
+ register: ec2
+
+- name: Delete Instance
+ ec2:
+ region: "{{ region }}"
+ ec2_access_key: "{{ ec2_access_key }}"
+ ec2_secret_key: "{{ ec2_secret_key }}"
+ state: 'absent'
+ instance_ids: "{{ item }}"
+ with_items: ec2.instance_ids