summaryrefslogtreecommitdiffstats
path: root/playbooks/gce/openshift-cluster
diff options
context:
space:
mode:
authorJhon Honce <jhonce@redhat.com>2015-03-06 13:52:20 -0700
committerJhon Honce <jhonce@redhat.com>2015-03-24 11:04:22 -0700
commit7c7cb82fdd5583784fd5832b92886abf86934325 (patch)
tree52b109394947ecc960ac458a6c69dce334a46467 /playbooks/gce/openshift-cluster
parent1c1df6a5733626865efc607d063f2a2a9b80499b (diff)
downloadopenshift-7c7cb82fdd5583784fd5832b92886abf86934325.tar.gz
openshift-7c7cb82fdd5583784fd5832b92886abf86934325.tar.bz2
openshift-7c7cb82fdd5583784fd5832b92886abf86934325.tar.xz
openshift-7c7cb82fdd5583784fd5832b92886abf86934325.zip
Use ansible playbook to initialize openshift cluster
* Added playbooks/gce/openshift-cluster * Added bin/cluster (will replace cluster.sh)
Diffstat (limited to 'playbooks/gce/openshift-cluster')
l---------playbooks/gce/openshift-cluster/filter_plugins1
-rw-r--r--playbooks/gce/openshift-cluster/launch.yml62
-rw-r--r--playbooks/gce/openshift-cluster/launch_instances.yml37
-rw-r--r--playbooks/gce/openshift-cluster/terminate.yml25
-rw-r--r--playbooks/gce/openshift-cluster/vars.yml1
5 files changed, 126 insertions, 0 deletions
diff --git a/playbooks/gce/openshift-cluster/filter_plugins b/playbooks/gce/openshift-cluster/filter_plugins
new file mode 120000
index 000000000..99a95e4ca
--- /dev/null
+++ b/playbooks/gce/openshift-cluster/filter_plugins
@@ -0,0 +1 @@
+../../../filter_plugins \ No newline at end of file
diff --git a/playbooks/gce/openshift-cluster/launch.yml b/playbooks/gce/openshift-cluster/launch.yml
new file mode 100644
index 000000000..ba9d58a74
--- /dev/null
+++ b/playbooks/gce/openshift-cluster/launch.yml
@@ -0,0 +1,62 @@
+---
+- name: Launch instance(s)
+ hosts: localhost
+ connection: local
+ gather_facts: no
+
+ vars_files:
+ - vars.yml
+
+ tasks:
+ - set_fact: k8s_type="master"
+
+ - name: "Generate master instance names(s)"
+ set_fact: scratch="{{ cluster_id }}-{{ k8s_type }}-{{ '%05x' |format( 1048576 |random) }}"
+ register: instance_names_output
+ with_sequence: start=1 end={{ masters }}
+
+ # These set_fact's cannot be combined
+ - set_fact:
+ instance_names_string: "{% for item in instance_names_output.results %}{{item.ansible_facts.scratch}} {% endfor %}"
+
+ - set_fact:
+ master_names: "{{ instance_names_string.strip().split(' ') }}"
+
+ - include: launch_instances.yml
+ vars:
+ instances: "{{ master_names }}"
+ cluster: "{{ cluster_id }}"
+ type: "{{ k8s_type }}"
+ group_name: "tag_env-host-type-{{ cluster_id }}-openshift-master"
+
+ - set_fact: k8s_type="node"
+
+ - name: "Generate node instance names(s)"
+ set_fact: scratch="{{ cluster_id }}-{{ k8s_type }}-{{ '%05x' |format( 1048576 |random) }}"
+ register: instance_names_output
+ with_sequence: start=1 end={{ nodes }}
+
+ # These set_fact's cannot be combined
+ - set_fact:
+ instance_names_string: "{% for item in instance_names_output.results %}{{item.ansible_facts.scratch}} {% endfor %}"
+
+ - set_fact:
+ node_names: "{{ instance_names_string.strip().split(' ') }}"
+
+ - include: launch_instances.yml
+ vars:
+ instances: "{{ node_names }}"
+ cluster: "{{ cluster_id }}"
+ type: "{{ k8s_type }}"
+ group_name: "tag_env-host-type-{{ cluster_id }}-openshift-node"
+
+
+- include: ../openshift-master/config.yml
+ vars:
+ oo_host_group_exp: "{{ master_names }}"
+ oo_env: "{{ cluster_id }}"
+
+- include: ../openshift-node/config.yml
+ vars:
+ oo_host_group_exp: "{{ node_names }}"
+ oo_env: "{{ cluster_id }}"
diff --git a/playbooks/gce/openshift-cluster/launch_instances.yml b/playbooks/gce/openshift-cluster/launch_instances.yml
new file mode 100644
index 000000000..ff19b94d8
--- /dev/null
+++ b/playbooks/gce/openshift-cluster/launch_instances.yml
@@ -0,0 +1,37 @@
+
+- set_fact:
+ machine_type: "{{ lookup('env', 'gce_machine_type') |default('n1-standard-1', true) }}"
+ machine_image: "{{ lookup('env', 'gce_machine_image') |default('libra-rhel7', true) }}"
+
+- name: Launch instance(s)
+ gce:
+ instance_names: "{{ instances }}"
+ machine_type: "{{ machine_type }}"
+ image: "{{ machine_image }}"
+ service_account_email: "{{ lookup('env', 'gce_service_account_email_address') }}"
+ pem_file: "{{ lookup('env', 'gce_service_account_pem_file_path') }}"
+ project_id: "{{ lookup('env', 'gce_project_id') }}"
+ tags:
+ - "created-by-{{ cluster }}"
+ - "env-{{ cluster }}"
+ - "host-type-{{ type }}"
+ - "env-host-type-{{ cluster }}-openshift-{{ type }}"
+ register: gce
+
+- name: Add new instances public IPs
+ add_host: "hostname={{ item.name }} ansible_ssh_host={{ item.public_ip }} groups={{ group_name }}"
+ with_items: gce.instance_data
+
+- name: Wait for ssh
+ wait_for: "port=22 host={{ item.public_ip }}"
+ with_items: gce.instance_data
+
+- debug: var=gce
+
+- name: Wait for root user setup
+ command: "ssh -o StrictHostKeyChecking=no -o PasswordAuthentication=no -o ConnectTimeout=10 -o UserKnownHostsFile=/dev/null root@{{ item.public_ip }} echo root user is setup"
+ register: result
+ until: result.rc == 0
+ retries: 20
+ delay: 10
+ with_items: gce.instance_data
diff --git a/playbooks/gce/openshift-cluster/terminate.yml b/playbooks/gce/openshift-cluster/terminate.yml
new file mode 100644
index 000000000..eff52a807
--- /dev/null
+++ b/playbooks/gce/openshift-cluster/terminate.yml
@@ -0,0 +1,25 @@
+---
+- name: Terminate instance(s)
+ hosts: localhost
+
+ vars_files:
+ - vars.yml
+
+ tasks:
+ - debug: msg="Retrieve node names"
+ - debug: msg="Retrieve master names"
+ - debug: var=groups
+
+- include: ../openshift-node/terminate.yml
+ vars:
+ oo_host_group_exp: 'groups["tag_env-host-type-{{ cluster_id }}-openshift-node"]'
+ gce_service_account_email: "1043659492591-r0tpbf8q4fbb9dakhjfhj89e4m1ld83t@developer.gserviceaccount.com"
+ gce_pem_file: "~/.gce/openshift-gce-devel_priv_key.pem"
+ gce_project_id: "openshift-gce-devel"
+
+- include: ../openshift-master/terminate.yml
+ vars:
+ oo_host_group_exp: 'groups["tag_env-host-type-{{ cluster_id }}-openshift-master"]'
+ gce_service_account_email: "1043659492591-r0tpbf8q4fbb9dakhjfhj89e4m1ld83t@developer.gserviceaccount.com"
+ gce_pem_file: "~/.gce/openshift-gce-devel_priv_key.pem"
+ gce_project_id: "openshift-gce-devel"
diff --git a/playbooks/gce/openshift-cluster/vars.yml b/playbooks/gce/openshift-cluster/vars.yml
new file mode 100644
index 000000000..ed97d539c
--- /dev/null
+++ b/playbooks/gce/openshift-cluster/vars.yml
@@ -0,0 +1 @@
+---