Skip to content

Commit

Permalink
Rename cloud_type from GCE to GCP, clarify throughout (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrikohlson authored May 5, 2020
1 parent 50ed598 commit 77612cd
Show file tree
Hide file tree
Showing 20 changed files with 64 additions and 64 deletions.
10 changes: 5 additions & 5 deletions EXAMPLE/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ ansible-playbook -u ubuntu --private-key=/home/<user>/.ssh/<rsa key> cluster.yml
```
### GCP:
```
ansible-playbook -u <username> --private-key=/home/<user>/.ssh/<rsa key> cluster.yml -e buildenv=sandbox -e clusterid=vtp_gce_euw1 [email protected]
ansible-playbook -u <username> --private-key=/home/<user>/.ssh/<rsa key> cluster.yml -e buildenv=sandbox -e clusterid=vtp_gce_euw1 [email protected] --tags=clusterverse_clean -e clean=_all_ -e release_version=v1.0.
ansible-playbook -u <username> --private-key=/home/<user>/.ssh/<rsa key> cluster.yml -e buildenv=sandbox -e clusterid=vtp_gce_euw1 [email protected] -e clean=_all_
ansible-playbook -u <username> --private-key=/home/<user>/.ssh/<rsa key> cluster.yml -e buildenv=sandbox -e clusterid=vtp_gcp_euw1 [email protected]
ansible-playbook -u <username> --private-key=/home/<user>/.ssh/<rsa key> cluster.yml -e buildenv=sandbox -e clusterid=vtp_gcp_euw1 [email protected] --tags=clusterverse_clean -e clean=_all_ -e release_version=v1.0.
ansible-playbook -u <username> --private-key=/home/<user>/.ssh/<rsa key> cluster.yml -e buildenv=sandbox -e clusterid=vtp_gcp_euw1 [email protected] -e clean=_all_
```

### Mandatory command-line variables:
Expand All @@ -73,7 +73,7 @@ ansible-playbook -u <username> --private-key=/home/<user>/.ssh/<rsa key> cluster
+ `-e prometheus_node_exporter_install=false` - Does not install the prometheus node_exporter
+ `-e static_journal=true` - Creates /var/log/journal directory, which will keep a permanent record of journald logs in systemd machines (normally ephemeral)
+ `-e filebeat_install=false` - Does not install filebeat
+ `-e create_gce_network=true` - Create GCP network and subnetwork (probably needed if creating from scratch and using public network)
+ `-e create_gcp_network=true` - Create GCP network and subnetwork (probably needed if creating from scratch and using public network)

### Tags
+ `clusterverse_clean`: Deletes all VMs and security groups (also needs `-e clean=[current|retiring|redeployfail|_all_]` on command line)
Expand All @@ -92,7 +92,7 @@ ansible-playbook -u ubuntu --private-key=/home/<user>/.ssh/<rsa key> redeploy.ym
```
### GCP:
```
ansible-playbook -u <username> --private-key=/home/<user>/.ssh/<rsa key> redeploy.yml -e buildenv=sandbox -e clusterid=vtp_gce_euw1 [email protected] -e canary=none
ansible-playbook -u <username> --private-key=/home/<user>/.ssh/<rsa key> redeploy.yml -e buildenv=sandbox -e clusterid=vtp_gcp_euw1 [email protected] -e canary=none
```

### Mandatory command-line variables:
Expand Down
6 changes: 3 additions & 3 deletions EXAMPLE/clusterverse_label_upgrade_v1-v2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
tasks_from: get_cluster_hosts_state.yml

- block:
- name: clusterverse_label_upgrade_v1-v2 | Add lifecycle_state and cluster_suffix label to AWS VM
- name: clusterverse_label_upgrade_v1-v2 | Add lifecycle_state and cluster_suffix label to AWS EC2 VM
ec2_tag:
aws_access_key: "{{cluster_vars[buildenv].aws_access_key}}"
aws_secret_key: "{{cluster_vars[buildenv].aws_secret_key}}"
Expand All @@ -25,7 +25,7 @@
with_items: "{{ hosts_to_relabel }}"
when: cluster_vars.type == "aws"

- name: clusterverse_label_upgrade_v1-v2 | Add lifecycle_state and cluster_suffix label to GCE VM
- name: clusterverse_label_upgrade_v1-v2 | Add lifecycle_state and cluster_suffix label to GCP GCE VM
gce_labels:
resource_name: "{{item.name}}"
project_id: "{{cluster_vars.project_id}}"
Expand All @@ -37,6 +37,6 @@
cluster_suffix: "{{ item.name | regex_replace('^.*-(.*)$', '\\1') }}"
state: present
with_items: "{{ hosts_to_relabel }}"
when: cluster_vars.type == "gce"
when: cluster_vars.type == "gcp"
vars:
hosts_to_relabel: "{{ cluster_hosts_state | json_query(\"[?!(tagslabels.cluster_suffix) || !(tagslabels.lifecycle_state)]\") }}"
4 changes: 2 additions & 2 deletions EXAMPLE/group_vars/_skel/cluster_vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ cluster_name: "{{app_name}}-{{buildenv}}" # Identifies the cluster within
#_region: *region


### GCE example
### GCP example
#cluster_vars:
# type: &cloud_type "gce"
# type: &cloud_type "gcp"
# image: "projects/ubuntu-os-cloud/global/images/ubuntu-1804-bionic-v20191113"
# region: &region "europe-west1"
# dns_zone_internal: "c.{{gcp_credentials_json.project_id}}.internal"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ bind9:
cluster_name: "{{app_name}}-{{buildenv}}" # Identifies the cluster within the cloud environment

cluster_vars:
type: &cloud_type "gce"
type: &cloud_type "gcp"
image: "projects/ubuntu-os-cloud/global/images/ubuntu-1804-bionic-v20191113"
region: &region "europe-west1"
dns_zone_internal: "c.{{gcp_credentials_json.project_id}}.internal"
Expand Down
2 changes: 1 addition & 1 deletion EXAMPLE/jenkinsfiles/Jenkinsfile_exec_deploy
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pipeline {
agent any
parameters {
booleanParam(name: 'GENUINE_BUILD', defaultValue: false, description: 'Tick the box to run the job')
string(name: 'CLUSTER_ID', defaultValue:"vtp_aws_euw1", description: "MANDATORY FIELD - 'vtp_aws_euw1', 'csc_aws_euw1', 'vtp_gce_euw1', 'vtp_lsd_slo' - Specify which cloud/on-prem environment you want to deploy to")
string(name: 'CLUSTER_ID', defaultValue:"vtp_aws_euw1", description: "MANDATORY FIELD - 'vtp_aws_euw1', 'csc_aws_euw1', 'vtp_gcp_euw1', 'vtp_lsd_slo' - Specify which cloud/on-prem environment you want to deploy to")
choice(name: 'DEPLOY_ENV', choices: ['sandbox', 'dev', 'stage', 'prod'], description: "Choose an environment to deploy")
choice(name: 'DEPLOY_TYPE', choices: ['Deploy', 'ReDeploy', 'Clean'], description: "Choose the deploy type")
string(name: 'CANARY', defaultValue:"none", description: "MANDATORY FIELD - 'start', 'finish', 'none' - Specify whether to start or finish a canary deploy, or 'none' deploy")
Expand Down
2 changes: 1 addition & 1 deletion EXAMPLE/jenkinsfiles/Jenkinsfile_exec_release_deploy
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pipeline {
agent any
parameters {
booleanParam(name: 'GENUINE_BUILD', defaultValue: false, description: 'Tick the box to run the job')
string(name: 'CLUSTER_ID', defaultValue:"vtp_aws_euw1", description: "MANDATORY FIELD - 'vtp_aws_euw1', 'csc_aws_euw1', 'vtp_gce_euw1', 'vtp_lsd_slo' - Specify which cloud/on-prem environment you want to deploy your release to")
string(name: 'CLUSTER_ID', defaultValue:"vtp_aws_euw1", description: "MANDATORY FIELD - 'vtp_aws_euw1', 'csc_aws_euw1', 'vtp_gcp_euw1', 'vtp_lsd_slo' - Specify which cloud/on-prem environment you want to deploy your release to")
choice(name: 'DEPLOY_ENV', choices: ['sandbox', 'tools', 'dev', 'stage', 'prod'], description: "Choose an environment to deploy")
string(name: 'CANARY', defaultValue:"none", description: "MANDATORY FIELD - 'start', 'finish', 'none' - Specify whether to start or finish a canary deploy, or 'none' deploy")
string(name: 'MYHOSTTYPES', defaultValue:"", description: "master,slave - In redeployment you can define which host type you like to redeploy. If not defined it will redeploy all host types")
Expand Down
2 changes: 1 addition & 1 deletion _dependencies/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@
- assert: { that: "'{%- for hosttype in cluster_vars[buildenv].hosttype_vars -%}{% if ('version' in cluster_vars[buildenv].hosttype_vars[hosttype]) and (not cluster_vars[buildenv].hosttype_vars[hosttype].version is regex('^[a-z\\d\\-_]{0,63}$')) %}{{cluster_vars[buildenv].hosttype_vars[hosttype].version}}{% endif %}{%- endfor -%}' == ''", fail_msg: "Please ensure cluster_vars[{{buildenv}}].hosttype_vars[hosttype].version is in the set [a-z\\d\\-_], and <63 characters long." }

- assert: { that: "(cluster_vars.assign_public_ip == 'yes' and cluster_vars.inventory_ip == 'public') or (cluster_vars.inventory_ip == 'private')", msg: "If inventory_ip=='public', 'assign_public_ip' must be 'yes'" }
when: cluster_vars.type == "gce" or cluster_vars.type == "aws"
when: cluster_vars.type == "gcp" or cluster_vars.type == "aws"
6 changes: 3 additions & 3 deletions clean/tasks/clean_networking.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
project: "{{cluster_vars.project_id}}"
with_items: "{{ cluster_vars.firewall_rules }}"

- name: clean/networking/gcp | Delete the GCP network (if -e create_gce_network=true)
- name: clean/networking/gcp | Delete the GCP network (if -e create_gcp_network=true)
gcp_compute_network:
name: "{{cluster_vars[buildenv].vpc_network_name}}"
auth_kind: "serviceaccount"
service_account_file: "{{gcp_credentials_file}}"
project: "{{cluster_vars.project_id}}"
state: absent
when: create_gce_network is defined and create_gce_network|bool
when: cluster_vars.type == "gce"
when: create_gcp_network is defined and create_gcp_network|bool
when: cluster_vars.type == "gcp"
10 changes: 5 additions & 5 deletions clean/tasks/clean_vms.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
when: cluster_vars.type == "aws"

- block:
- name: clean/del_vms/gce | Remove deletion protection
- name: clean/del_vms/gcp | Remove deletion protection
command: "gcloud compute instances update {{item.name}} --no-deletion-protection --zone {{ item.regionzone }}"
when: cluster_vars[buildenv].deletion_protection | bool
with_items: "{{ hosts_to_clean }}"

# - name: clean/del_vms/gce | Remove deletion protection (broken until https://github.com/ansible-collections/ansible_collections_google/pull/163 gets into a release)
# - name: clean/del_vms/gcp | Remove deletion protection (broken until https://github.com/ansible-collections/ansible_collections_google/pull/163 gets into a release)
# gcp_compute_instance:
# name: "{{item.name}}"
# project: "{{cluster_vars.project_id}}"
Expand All @@ -41,7 +41,7 @@
# deletion_protection: 'no'
# with_items: "{{ hosts_to_clean }}"

- name: clean/del_vms/gce | Delete GCE VM
- name: clean/del_vms/gcp | Delete GCE VM
gcp_compute_instance:
name: "{{item.name}}"
project: "{{cluster_vars.project_id}}"
Expand All @@ -54,12 +54,12 @@
async: 7200
poll: 0

- name: clean/del_vms/gce | Wait for gce VM deletion to complete
- name: clean/del_vms/gcp | Wait for GCE VM deletion to complete
async_status:
jid: "{{ item.ansible_job_id }}"
register: async_jobs
until: async_jobs.finished
retries: 300
with_items: "{{r__gcp_compute_instance.results}}"
when: cluster_vars.type == "gce"
when: cluster_vars.type == "gcp"
when: hosts_to_clean | length
10 changes: 5 additions & 5 deletions cluster_hosts/tasks/get_cluster_hosts_state.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

- name: get_cluster_hosts_state/aws | Get AWS cluster_hosts_state
block:
- name: get_cluster_hosts_state/aws | Get existing AWS instance info
- name: get_cluster_hosts_state/aws | Get existing EC2 instance info
ec2_instance_info:
filters:
"tag:cluster_name": "{{cluster_name}}"
Expand All @@ -19,9 +19,9 @@
cluster_hosts_state: "{{r__ec2_instance_info.instances | json_query(\"[].{name: tags.Name, regionzone: placement.availability_zone, tagslabels: tags, instance_id: instance_id, instance_state: state.name}\") }}"
when: cluster_vars.type == "aws"

- name: get_cluster_hosts_state/gce | Get GCE cluster_hosts_state
- name: get_cluster_hosts_state/gcp | Get GCP cluster_hosts_state
block:
- name: get_cluster_hosts_state/gce | Get existing GCE instance info (per AZ)
- name: get_cluster_hosts_state/gcp | Get existing GCE instance info (per AZ)
gcp_compute_instance_info:
zone: "{{cluster_vars.region}}-{{item}}"
filters:
Expand All @@ -35,7 +35,7 @@
delegate_to: localhost
run_once: true

- name: get_cluster_hosts_state/gce | Set cluster_hosts_state with correct regionzone (remove url)
- name: get_cluster_hosts_state/gcp | Set cluster_hosts_state with correct regionzone (remove url)
set_fact:
cluster_hosts_state: |
{% set res = _cluster_hosts_state__urlregion -%}
Expand All @@ -45,7 +45,7 @@
{{ res }}
vars:
_cluster_hosts_state__urlregion: "{{r__gcp_compute_instance_info.results | json_query(\"[?resources[?labels]].resources[].{name: name, regionzone: zone, tagslabels: labels, instance_id: id, instance_state: status}\") }}"
when: cluster_vars.type == "gce"
when: cluster_vars.type == "gcp"

- name: get_cluster_hosts_state/vmware | Get VMware cluster_hosts_state
block:
Expand Down
6 changes: 3 additions & 3 deletions cluster_hosts/tasks/get_cluster_hosts_target.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,17 @@
when: cluster_vars.type == "aws"


- name: get_cluster_hosts_target/gce | GCE-specific modifications to cluster_hosts_target - add rootvol size
- name: get_cluster_hosts_target/gcp | GCP-specific modifications to cluster_hosts_target - add rootvol size
block:
- name: get_cluster_hosts_target/gce | Update cluster_hosts_target with rootvol_size
- name: get_cluster_hosts_target/gcp | Update cluster_hosts_target with rootvol_size
set_fact:
cluster_hosts_target: |
{% set res = cluster_hosts_target -%}
{%- for host in res -%}
{%- set _dummy = host.update({'rootvol_size': cluster_vars[buildenv].hosttype_vars[host.hosttype].rootvol_size | string}) -%}
{%- endfor %}
{{ res }}
when: cluster_vars.type == "gce"
when: cluster_vars.type == "gcp"

- name: get_cluster_hosts_target | cluster_hosts_target
debug: msg={{cluster_hosts_target}}
18 changes: 9 additions & 9 deletions create/tasks/gce.yml → create/tasks/gcp.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---

- name: create/gcp | Create GCP network and subnetwork (if -e create_gce_network=true)
- name: create/gcp | Create GCP network and subnetwork (if -e create_gcp_network=true)
block:
- name: create/gcp | Create GCP host network (if -e create_gce_network=true)
- name: create/gcp | Create GCP host network (if -e create_gcp_network=true)
gcp_compute_network:
name: "{{cluster_vars[buildenv].vpc_network_name}}"
auto_create_subnetworks: "{%- if cluster_vars[buildenv].vpc_subnet_name is defined and cluster_vars[buildenv].vpc_subnet_name != '' -%} false {%- else -%} true {%- endif -%}"
Expand All @@ -11,15 +11,15 @@
service_account_file: "{{gcp_credentials_file}}"
register: r__gcp_compute_network

- name: create/gcp | Create GCP host subnetwork (if -e create_gce_network=true)
- name: create/gcp | Create GCP host subnetwork (if -e create_gcp_network=true)
gcp_compute_subnetwork:
name: "{{cluster_vars[buildenv].vpc_subnet_name}}"
network: "{{r__gcp_compute_network}}"
project: "{{cluster_vars.project_id}}"
auth_kind: "serviceaccount"
service_account_file: "{{gcp_credentials_file}}"
when: (cluster_vars[buildenv].vpc_subnet_name is defined) and (cluster_vars[buildenv].vpc_subnet_name != "")
when: create_gce_network is defined and create_gce_network|bool
when: create_gcp_network is defined and create_gcp_network|bool


- name: create/gcp | Create GCP firewalls
Expand All @@ -35,7 +35,7 @@
register: r__gcp_compute_network_info

- name: "Assert that {{cluster_vars[buildenv].vpc_network_name}} network exists"
assert: { that: "r__gcp_compute_network_info['resources'] | length > 0", msg: "The {{cluster_vars[buildenv].vpc_network_name}} network must exist (create with ' -e create_gce_network=true')" }
assert: { that: "r__gcp_compute_network_info['resources'] | length > 0", msg: "The {{cluster_vars[buildenv].vpc_network_name}} network must exist (create with ' -e create_gcp_network=true')" }

- name: create/gcp | Get GCP subnetwork facts
gcp_compute_subnetwork_info:
Expand Down Expand Up @@ -115,17 +115,17 @@
async: 7200
poll: 0

- name: create/gcp | Wait for gce instance creation to complete
- name: create/gcp | Wait for GCE instance creation to complete
async_status:
jid: "{{ item.ansible_job_id }}"
register: gce_jobs
until: gce_jobs.finished
register: gcp_jobs
until: gcp_jobs.finished
delay: 3
retries: 300
with_items: "{{gcp_compute_instance.results}}"

- name: create/gcp | Set a fact containing the newly-created hosts
set_fact:
cluster_hosts_created: "{{ gce_jobs.results | json_query(\"[?item.changed==`true`].item.item\") }}"
cluster_hosts_created: "{{ gcp_jobs.results | json_query(\"[?item.changed==`true`].item.item\") }}"


6 changes: 3 additions & 3 deletions create/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
include_tasks: aws.yml
when: cluster_vars.type == "aws"

- name: Create GCE cluster
include_tasks: gce.yml
when: cluster_vars.type == "gce"
- name: Create GCP cluster
include_tasks: gcp.yml
when: cluster_vars.type == "gcp"
File renamed without changes.
6 changes: 3 additions & 3 deletions dynamic_inventory/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
include_tasks: aws.yml
when: cluster_vars.type == "aws"

- name: dynamic_inventory | Derive dynamic inventory for GCE cluster
include_tasks: gce.yml
when: cluster_vars.type == "gce"
- name: dynamic_inventory | Derive dynamic inventory for GCP cluster
include_tasks: gcp.yml
when: cluster_vars.type == "gcp"

- assert: { that: "dynamic_inventory_flat is defined", msg: "dynamic_inventory_flat is not defined" }

Expand Down
8 changes: 4 additions & 4 deletions readiness/tasks/remove_maintenance_mode.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---

- block:
- name: remove_maintenance_mode/aws | Get existing AWS instance info
- name: remove_maintenance_mode/aws | Get existing AWS EC2 instance info
ec2_instance_info:
filters:
"tag:cluster_name": "{{cluster_name}}"
Expand All @@ -27,7 +27,7 @@
when: cluster_vars.type == "aws"

- block:
- name: remove_maintenance_mode/gce | Get existing GCE instance info (per AZ)
- name: remove_maintenance_mode/gcp | Get existing GCP GCE instance info (per AZ)
gcp_compute_instance_info:
zone: "{{cluster_vars.region}}-{{item}}"
filters:
Expand All @@ -42,7 +42,7 @@
run_once: true

# Use this because the gce_labels command does not replace existing labels. https://github.com/ansible/ansible/pull/59891
- name: remove_maintenance_mode/gce | Set maintenance_mode to false
- name: remove_maintenance_mode/gcp | Set maintenance_mode to false
gcp_compute_instance:
name: "{{item.name}}"
project: "{{cluster_vars.project_id}}"
Expand All @@ -55,4 +55,4 @@
with_items: "{{ r__gcp_compute_instance_info.results | json_query(\"[?resources[?labels]].resources[]\") }}"
delegate_to: localhost
run_once: true
when: cluster_vars.type == "gce"
when: cluster_vars.type == "gcp"
12 changes: 6 additions & 6 deletions redeploy/__common/tasks/poweroff_vms.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
debug: msg="{{hosts_to_stop}}"

- block:
- name: poweroff_vms | Power-off AWS VM(s) and set maintenance_mode=true
- name: poweroff_vms | Power-off AWS EC2 VM(s) and set maintenance_mode=true
block:
- name: poweroff_vms | Set maintenance_mode label on AWS VM(s)
ec2_tag:
Expand All @@ -16,7 +16,7 @@
maintenance_mode: "true"
with_items: "{{ hosts_to_stop }}"

- name: poweroff_vms | Power-off AWS VM(s)
- name: poweroff_vms | Power-off AWS EC2 VM(s)
ec2:
aws_access_key: "{{cluster_vars[buildenv].aws_access_key}}"
aws_secret_key: "{{cluster_vars[buildenv].aws_secret_key}}"
Expand All @@ -29,9 +29,9 @@
when: cluster_vars.type == "aws"


- name: poweroff_vms | Power-off GCE VMs asynchronously
- name: poweroff_vms | Power-off GCP GCE VMs asynchronously
block:
- name: poweroff_vms | Power-off GCE VM(s) and set maintenance_mode=true
- name: poweroff_vms | Power-off GCP GCE VM(s) and set maintenance_mode=true
gcp_compute_instance:
name: "{{item.name}}"
project: "{{cluster_vars.project_id}}"
Expand All @@ -46,12 +46,12 @@
async: 7200
poll: 0

- name: poweroff_vms | Wait for gce instance(s) to power-off
- name: poweroff_vms | Wait for GCP GCE instance(s) to power-off
async_status:
jid: "{{ item.ansible_job_id }}"
register: async_jobs
until: async_jobs.finished
retries: 300
with_items: "{{r__gcp_compute_instance.results}}"
when: cluster_vars.type == "gce"
when: cluster_vars.type == "gcp"
when: hosts_to_stop | length
Loading

0 comments on commit 77612cd

Please sign in to comment.