From 614dc4ff5a975be8438c9e034c84dba3410c0a20 Mon Sep 17 00:00:00 2001 From: Michael Gugino Date: Fri, 29 Sep 2017 15:03:09 -0400 Subject: Make provisioning steps more reusable Reorganizing and making some of the plays more reusable. --- roles/openshift_aws/README.md | 2 - roles/openshift_aws/defaults/main.yml | 1 - roles/openshift_aws/tasks/build_ami.yml | 48 ------------------ roles/openshift_aws/tasks/master_facts.yml | 22 +++++++++ roles/openshift_aws/tasks/provision.yml | 8 --- roles/openshift_aws/tasks/provision_instance.yml | 63 ++++++++++++++++++++++++ roles/openshift_aws/tasks/setup_master_group.yml | 35 +++++++++++++ 7 files changed, 120 insertions(+), 59 deletions(-) delete mode 100644 roles/openshift_aws/tasks/build_ami.yml create mode 100644 roles/openshift_aws/tasks/master_facts.yml create mode 100644 roles/openshift_aws/tasks/provision_instance.yml create mode 100644 roles/openshift_aws/tasks/setup_master_group.yml (limited to 'roles') diff --git a/roles/openshift_aws/README.md b/roles/openshift_aws/README.md index 696efbea5..ff96081fe 100644 --- a/roles/openshift_aws/README.md +++ b/roles/openshift_aws/README.md @@ -23,7 +23,6 @@ From this role: | openshift_aws_ami_copy_wait | False | openshift_aws_users | [] | openshift_aws_launch_config_name | {{ openshift_aws_clusterid }}-{{ openshift_aws_node_group_type }} -| openshift_aws_create_vpc | False | openshift_aws_node_group_type | master | openshift_aws_elb_cert_arn | '' | openshift_aws_kubernetes_cluster_status | owned @@ -72,7 +71,6 @@ Example Playbook vars: openshift_aws_clusterid: test openshift_aws_region: us-east-1 - openshift_aws_create_vpc: true ``` License diff --git a/roles/openshift_aws/defaults/main.yml b/roles/openshift_aws/defaults/main.yml index ca39c1aec..f668cf4c8 100644 --- a/roles/openshift_aws/defaults/main.yml +++ b/roles/openshift_aws/defaults/main.yml @@ -1,5 +1,4 @@ --- -openshift_aws_create_vpc: True openshift_aws_create_s3: True openshift_aws_create_iam_cert: True openshift_aws_create_security_groups: True diff --git a/roles/openshift_aws/tasks/build_ami.yml b/roles/openshift_aws/tasks/build_ami.yml deleted file mode 100644 index 48555e5da..000000000 --- a/roles/openshift_aws/tasks/build_ami.yml +++ /dev/null @@ -1,48 +0,0 @@ ---- -- when: openshift_aws_create_vpc | bool - name: create a vpc - include: vpc.yml - -- when: openshift_aws_users | length > 0 - name: create aws ssh keypair - include: ssh_keys.yml - -- when: openshift_aws_create_security_groups | bool - name: Create compute security_groups - include: security_group.yml - -- name: query vpc - ec2_vpc_net_facts: - region: "{{ openshift_aws_region }}" - filters: - 'tag:Name': "{{ openshift_aws_vpc_name }}" - register: vpcout - -- name: fetch the default subnet id - ec2_vpc_subnet_facts: - region: "{{ openshift_aws_region }}" - filters: - "tag:Name": "{{ openshift_aws_subnet_name }}" - vpc-id: "{{ vpcout.vpcs[0].id }}" - register: subnetout - -- name: create instance for ami creation - ec2: - assign_public_ip: yes - region: "{{ openshift_aws_region }}" - key_name: "{{ openshift_aws_ssh_key_name }}" - group: "{{ openshift_aws_build_ami_group }}" - instance_type: m4.xlarge - vpc_subnet_id: "{{ subnetout.subnets[0].id }}" - image: "{{ openshift_aws_base_ami }}" - volumes: - - device_name: /dev/sdb - volume_type: gp2 - volume_size: 100 - delete_on_termination: true - wait: yes - exact_count: 1 - count_tag: - Name: "{{ openshift_aws_base_ami_name }}" - instance_tags: - Name: "{{ openshift_aws_base_ami_name }}" diff --git a/roles/openshift_aws/tasks/master_facts.yml b/roles/openshift_aws/tasks/master_facts.yml new file mode 100644 index 000000000..6e716d11a --- /dev/null +++ b/roles/openshift_aws/tasks/master_facts.yml @@ -0,0 +1,22 @@ +--- +- name: fetch elbs + ec2_elb_facts: + region: "{{ openshift_aws_region }}" + names: + - "{{ item }}" + with_items: + - "{{ openshift_aws_clusterid }}-master-external" + - "{{ openshift_aws_clusterid }}-master-internal" + delegate_to: localhost + register: elbs + +- debug: var=elbs + +- name: set fact + set_fact: + openshift_master_cluster_hostname: "{{ elbs.results[1].elbs[0].dns_name }}" + osm_custom_cors_origins: + - "{{ elbs.results[1].elbs[0].dns_name }}" + - "console.{{ openshift_aws_clusterid | default('default') }}.openshift.com" + - "api.{{ openshift_aws_clusterid | default('default') }}.openshift.com" + with_items: "{{ groups['masters'] }}" diff --git a/roles/openshift_aws/tasks/provision.yml b/roles/openshift_aws/tasks/provision.yml index a2920b744..a8518d43a 100644 --- a/roles/openshift_aws/tasks/provision.yml +++ b/roles/openshift_aws/tasks/provision.yml @@ -1,16 +1,8 @@ --- -- when: openshift_aws_create_vpc | bool - name: create default vpc - include: vpc.yml - - when: openshift_aws_create_iam_cert | bool name: create the iam_cert for elb certificate include: iam_cert.yml -- when: openshift_aws_users | length > 0 - name: create aws ssh keypair - include: ssh_keys.yml - - when: openshift_aws_create_s3 | bool name: create s3 bucket for registry include: s3.yml diff --git a/roles/openshift_aws/tasks/provision_instance.yml b/roles/openshift_aws/tasks/provision_instance.yml new file mode 100644 index 000000000..1384bae59 --- /dev/null +++ b/roles/openshift_aws/tasks/provision_instance.yml @@ -0,0 +1,63 @@ +--- +- name: query vpc + ec2_vpc_net_facts: + region: "{{ openshift_aws_region }}" + filters: + 'tag:Name': "{{ openshift_aws_vpc_name }}" + register: vpcout + +- name: fetch the default subnet id + ec2_vpc_subnet_facts: + region: "{{ openshift_aws_region }}" + filters: + "tag:Name": "{{ openshift_aws_subnet_name }}" + vpc-id: "{{ vpcout.vpcs[0].id }}" + register: subnetout + +- name: create instance for ami creation + ec2: + assign_public_ip: yes + region: "{{ openshift_aws_region }}" + key_name: "{{ openshift_aws_ssh_key_name }}" + group: "{{ openshift_aws_build_ami_group }}" + instance_type: m4.xlarge + vpc_subnet_id: "{{ openshift_aws_subnet_id | default(subnetout.subnets[0].id) }}" + image: "{{ openshift_aws_base_ami }}" + volumes: + - device_name: /dev/sdb + volume_type: gp2 + volume_size: 100 + delete_on_termination: true + wait: yes + exact_count: 1 + count_tag: + Name: "{{ openshift_aws_base_ami_name }}" + instance_tags: + Name: "{{ openshift_aws_base_ami_name }}" + +- name: fetch newly created instances + ec2_remote_facts: + region: "{{ openshift_aws_region }}" + filters: + "tag:Name": "{{ openshift_aws_base_ami_name }}" + instance-state-name: running + register: instancesout + retries: 20 + delay: 3 + until: instancesout.instances|length > 0 + +- name: wait for ssh to become available + wait_for: + port: 22 + host: "{{ instancesout.instances[0].public_ip_address }}" + timeout: 300 + search_regex: OpenSSH + +- name: Pause 10 seconds to ensure ssh actually accepts logins + pause: + seconds: 20 + +- name: add host to nodes + add_host: + groups: nodes + name: "{{ instancesout.instances[0].public_dns_name }}" diff --git a/roles/openshift_aws/tasks/setup_master_group.yml b/roles/openshift_aws/tasks/setup_master_group.yml new file mode 100644 index 000000000..90233a689 --- /dev/null +++ b/roles/openshift_aws/tasks/setup_master_group.yml @@ -0,0 +1,35 @@ +--- +- name: Alert user to variables needed - clusterid + debug: + msg: "openshift_aws_clusterid={{ openshift_aws_clusterid }}" + +- name: Alert user to variables needed - region + debug: + msg: "openshift_aws_region={{ openshift_aws_region }}" + +- name: fetch newly created instances + ec2_remote_facts: + region: "{{ openshift_aws_region }}" + filters: + "tag:clusterid": "{{ openshift_aws_clusterid }}" + "tag:host-type": master + instance-state-name: running + register: instancesout + retries: 20 + delay: 3 + until: instancesout.instances|length > 0 + +- name: add new master to masters group + add_host: + groups: "masters,etcd,nodes" + name: "{{ item.public_ip_address }}" + hostname: "{{ openshift_aws_clusterid }}-master-{{ item.id[:-5] }}" + with_items: "{{ instancesout.instances }}" + +- name: wait for ssh to become available + wait_for: + port: 22 + host: "{{ item.public_ip_address }}" + timeout: 300 + search_regex: OpenSSH + with_items: "{{ instancesout.instances }}" -- cgit v1.2.3 From ca90c960f14824608e546f71ef777f19ce818c43 Mon Sep 17 00:00:00 2001 From: Michael Gugino Date: Fri, 29 Sep 2017 16:44:01 -0400 Subject: fix master-facts for provisioning --- roles/openshift_aws/tasks/master_facts.yml | 4 ++-- roles/openshift_aws/tasks/setup_master_group.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'roles') diff --git a/roles/openshift_aws/tasks/master_facts.yml b/roles/openshift_aws/tasks/master_facts.yml index 6e716d11a..737cfc7a6 100644 --- a/roles/openshift_aws/tasks/master_facts.yml +++ b/roles/openshift_aws/tasks/master_facts.yml @@ -5,8 +5,8 @@ names: - "{{ item }}" with_items: - - "{{ openshift_aws_clusterid }}-master-external" - - "{{ openshift_aws_clusterid }}-master-internal" + - "{{ openshift_aws_elb_name }}-external" + - "{{ openshift_aws_elb_name }}-internal" delegate_to: localhost register: elbs diff --git a/roles/openshift_aws/tasks/setup_master_group.yml b/roles/openshift_aws/tasks/setup_master_group.yml index 90233a689..166f3b938 100644 --- a/roles/openshift_aws/tasks/setup_master_group.yml +++ b/roles/openshift_aws/tasks/setup_master_group.yml @@ -22,14 +22,14 @@ - name: add new master to masters group add_host: groups: "masters,etcd,nodes" - name: "{{ item.public_ip_address }}" + name: "{{ item.public_dns_name }}" hostname: "{{ openshift_aws_clusterid }}-master-{{ item.id[:-5] }}" with_items: "{{ instancesout.instances }}" - name: wait for ssh to become available wait_for: port: 22 - host: "{{ item.public_ip_address }}" + host: "{{ item.public_dns_name }}" timeout: 300 search_regex: OpenSSH with_items: "{{ instancesout.instances }}" -- cgit v1.2.3