summaryrefslogtreecommitdiffstats
path: root/playbooks/aws/openshift-cluster
diff options
context:
space:
mode:
Diffstat (limited to 'playbooks/aws/openshift-cluster')
l---------playbooks/aws/openshift-cluster/filter_plugins1
-rw-r--r--playbooks/aws/openshift-cluster/launch.yml62
-rw-r--r--playbooks/aws/openshift-cluster/launch_instances.yml62
-rw-r--r--playbooks/aws/openshift-cluster/list.yml17
l---------playbooks/aws/openshift-cluster/roles1
-rw-r--r--playbooks/aws/openshift-cluster/terminate.yml14
-rw-r--r--playbooks/aws/openshift-cluster/update.yml13
-rw-r--r--playbooks/aws/openshift-cluster/vars.yml1
8 files changed, 171 insertions, 0 deletions
diff --git a/playbooks/aws/openshift-cluster/filter_plugins b/playbooks/aws/openshift-cluster/filter_plugins
new file mode 120000
index 000000000..99a95e4ca
--- /dev/null
+++ b/playbooks/aws/openshift-cluster/filter_plugins
@@ -0,0 +1 @@
+../../../filter_plugins \ No newline at end of file
diff --git a/playbooks/aws/openshift-cluster/launch.yml b/playbooks/aws/openshift-cluster/launch.yml
new file mode 100644
index 000000000..3561c1803
--- /dev/null
+++ b/playbooks/aws/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: master_names_output
+ with_sequence: start=1 end={{ num_masters }}
+
+ # These set_fact's cannot be combined
+ - set_fact:
+ master_names_string: "{% for item in master_names_output.results %}{{ item.ansible_facts.scratch }} {% endfor %}"
+
+ - set_fact:
+ master_names: "{{ master_names_string.strip().split(' ') }}"
+
+ - include: launch_instances.yml
+ vars:
+ instances: "{{ master_names }}"
+ cluster: "{{ cluster_id }}"
+ type: "{{ k8s_type }}"
+
+ - set_fact: k8s_type="node"
+
+ - name: Generate node instance names(s)
+ set_fact: scratch={{ cluster_id }}-{{ k8s_type }}-{{ '%05x' |format( 1048576 |random) }}
+ register: node_names_output
+ with_sequence: start=1 end={{ num_nodes }}
+
+ # These set_fact's cannot be combined
+ - set_fact:
+ node_names_string: "{% for item in node_names_output.results %}{{ item.ansible_facts.scratch }} {% endfor %}"
+
+ - set_fact:
+ node_names: "{{ node_names_string.strip().split(' ') }}"
+
+ - include: launch_instances.yml
+ vars:
+ instances: "{{ node_names }}"
+ cluster: "{{ cluster_id }}"
+ type: "{{ k8s_type }}"
+
+- hosts: "tag_env_{{ cluster_id }}"
+ roles:
+ - openshift_repos
+ - os_update_latest
+
+- include: ../openshift-master/config.yml
+ vars:
+ oo_host_group_exp: "groups[\"tag_env-host-type_{{ cluster_id }}-openshift-master\"]"
+
+- include: ../openshift-node/config.yml
+ vars:
+ oo_host_group_exp: "groups[\"tag_env-host-type_{{ cluster_id }}-openshift-node\"]"
+
+- include: list.yml
diff --git a/playbooks/aws/openshift-cluster/launch_instances.yml b/playbooks/aws/openshift-cluster/launch_instances.yml
new file mode 100644
index 000000000..e4d5952fd
--- /dev/null
+++ b/playbooks/aws/openshift-cluster/launch_instances.yml
@@ -0,0 +1,62 @@
+---
+- set_fact:
+ machine_type: "{{ lookup('env', 'ec2_instance_type')|default('m3.large', true) }}"
+ machine_image: "{{ lookup('env', 'ec2_ami')|default('ami-307b3658', true) }}"
+ machine_region: "{{ lookup('env', 'ec2_region')|default('us-east-1', true) }}"
+ machine_keypair: "{{ lookup('env', 'ec2_keypair')|default('libra', true) }}"
+ created_by: "{{ lookup('env', 'LOGNAME')|default(cluster, true) }}"
+ env: "{{ cluster }}"
+ host_type: "{{ type }}"
+ env_host_type: "{{ cluster }}-openshift-{{ type }}"
+
+- name: Launch instance(s)
+ ec2:
+ state: present
+ region: "{{ machine_region }}"
+ keypair: "{{ machine_keypair }}"
+ group: ['public']
+ instance_type: "{{ machine_type }}"
+ image: "{{ machine_image }}"
+ count: "{{ instances | oo_len }}"
+ wait: yes
+ instance_tags:
+ created-by: "{{ created_by }}"
+ env: "{{ env }}"
+ host-type: "{{ host_type }}"
+ env-host-type: "{{ env_host_type }}"
+ register: ec2
+
+- name: Add Name tag to instances
+ ec2_tag: resource={{ item.1.id }} region={{ machine_region }} state=present
+ with_together:
+ - instances
+ - ec2.instances
+ args:
+ tags:
+ Name: "{{ item.0 }}"
+
+- set_fact:
+ instance_groups: tag_created-by_{{ created_by }}, tag_env_{{ env }}, tag_host-type_{{ host_type }}, tag_env-host-type_{{ env_host_type }}
+
+- name: Add new instances groups and variables
+ add_host:
+ hostname: "{{ item.0 }}"
+ ansible_ssh_host: "{{ item.1.dns_name }}"
+ groups: "{{ instance_groups }}"
+ ec2_private_ip_address: "{{ item.1.private_ip }}"
+ ec2_ip_address: "{{ item.1.public_ip }}"
+ with_together:
+ - instances
+ - ec2.instances
+
+- name: Wait for ssh
+ wait_for: "port=22 host={{ item.dns_name }}"
+ with_items: ec2.instances
+
+- name: Wait for root user setup
+ command: "ssh -o StrictHostKeyChecking=no -o PasswordAuthentication=no -o ConnectTimeout=10 -o UserKnownHostsFile=/dev/null root@{{ item.dns_name }} echo root user is setup"
+ register: result
+ until: result.rc == 0
+ retries: 20
+ delay: 10
+ with_items: ec2.instances
diff --git a/playbooks/aws/openshift-cluster/list.yml b/playbooks/aws/openshift-cluster/list.yml
new file mode 100644
index 000000000..08e9e2df4
--- /dev/null
+++ b/playbooks/aws/openshift-cluster/list.yml
@@ -0,0 +1,17 @@
+---
+- name: Generate oo_list_hosts group
+ hosts: localhost
+ gather_facts: no
+ tasks:
+ - set_fact: scratch_group=tag_env_{{ cluster_id }}
+ when: cluster_id != ''
+ - set_fact: scratch_group=all
+ when: scratch_group is not defined
+ - add_host: name={{ item }} groups=oo_list_hosts
+ with_items: groups[scratch_group] | difference(['localhost'])
+
+- name: List Hosts
+ hosts: oo_list_hosts
+ gather_facts: no
+ tasks:
+ - debug: msg="public:{{hostvars[inventory_hostname].ec2_ip_address}} private:{{hostvars[inventory_hostname].ec2_private_ip_address}}"
diff --git a/playbooks/aws/openshift-cluster/roles b/playbooks/aws/openshift-cluster/roles
new file mode 120000
index 000000000..20c4c58cf
--- /dev/null
+++ b/playbooks/aws/openshift-cluster/roles
@@ -0,0 +1 @@
+../../../roles \ No newline at end of file
diff --git a/playbooks/aws/openshift-cluster/terminate.yml b/playbooks/aws/openshift-cluster/terminate.yml
new file mode 100644
index 000000000..39607633a
--- /dev/null
+++ b/playbooks/aws/openshift-cluster/terminate.yml
@@ -0,0 +1,14 @@
+---
+- name: Terminate instance(s)
+ hosts: localhost
+
+ vars_files:
+ - vars.yml
+
+- include: ../openshift-node/terminate.yml
+ vars:
+ oo_host_group_exp: 'groups["tag_env-host-type_{{ cluster_id }}-openshift-node"]'
+
+- include: ../openshift-master/terminate.yml
+ vars:
+ oo_host_group_exp: 'groups["tag_env-host-type_{{ cluster_id }}-openshift-master"]'
diff --git a/playbooks/aws/openshift-cluster/update.yml b/playbooks/aws/openshift-cluster/update.yml
new file mode 100644
index 000000000..90ecdc6ab
--- /dev/null
+++ b/playbooks/aws/openshift-cluster/update.yml
@@ -0,0 +1,13 @@
+---
+- hosts: "tag_env_{{ cluster_id }}"
+ roles:
+ - openshift_repos
+ - os_update_latest
+
+- include: ../openshift-master/config.yml
+ vars:
+ oo_host_group_exp: "groups[\"tag_env-host-type_{{ cluster_id }}-openshift-master\"]"
+
+- include: ../openshift-node/config.yml
+ vars:
+ oo_host_group_exp: "groups[\"tag_env-host-type_{{ cluster_id }}-openshift-node\"]"
diff --git a/playbooks/aws/openshift-cluster/vars.yml b/playbooks/aws/openshift-cluster/vars.yml
new file mode 100644
index 000000000..ed97d539c
--- /dev/null
+++ b/playbooks/aws/openshift-cluster/vars.yml
@@ -0,0 +1 @@
+---