diff --git a/roles/clusterbuild/cluster_hosts/tasks/gce.yml b/roles/clusterbuild/cluster_hosts/tasks/gce.yml index e3f21735..3ded9c67 100644 --- a/roles/clusterbuild/cluster_hosts/tasks/gce.yml +++ b/roles/clusterbuild/cluster_hosts/tasks/gce.yml @@ -44,7 +44,7 @@ when: rescuing_instance is defined and cluster_hosts_flat | json_query('[? hostname == `' + rescuing_instance + '`]') | length == 0 - name: Get GCP instance facts - gcp_compute_instance_facts: + gcp_compute_instance_info: zone: "{{cluster_vars.region}}-{{item}}" filters: - "name = {{cluster_name}}*" @@ -54,14 +54,14 @@ service_account_file: "{{gcp_credentials_file}}" scopes: ["https://www.googleapis.com/auth/compute.readonly"] with_items: "{{ cluster_vars[buildenv].hosttype_vars | json_query('*.az|[]') | unique }}" - register: gcp_compute_instance_facts + register: gcp_compute_instance_info delegate_to: localhost run_once: true - set_fact: - running_instance_fact: "{{gcp_compute_instance_facts.results | json_query('[*].items[].{name: name, deploy_status: labels.deploy_status}')}}" - current_cluter_size: "{{gcp_compute_instance_facts.results | json_query('[*].items[]') | length}}" + running_instance_fact: "{{gcp_compute_instance_info.results | json_query('[*].resources[].{name: name, deploy_status: labels.deploy_status}')}}" + current_cluter_size: "{{gcp_compute_instance_info.results | json_query('[*].resources[]') | length}}" run_once: true - name: Update cluster_hosts_flat with running_instance_fact data @@ -103,7 +103,7 @@ delegate_to: localhost run_once: true vars: - deploy_status_tag: "{{gcp_compute_instance_facts.results | json_query('[].items[?name==`' + item.hostname + '`].labels.deploy_status | [] | [0]')}}" + deploy_status_tag: "{{gcp_compute_instance_info.results | json_query('[].resources[?name==`' + item.hostname + '`].labels.deploy_status | [] | [0]')}}" with_items: "{{cluster_hosts_flat}}" when: deploy_status_tag != "" @@ -120,13 +120,13 @@ delegate_to: localhost run_once: true vars: - created_instance_name: "{{gcp_compute_instance_facts.results | json_query('[].items[?name==`' + item.hostname + '`].name | [] | [0]')}}" - deploy_status_tag: "{{gcp_compute_instance_facts.results | json_query('[].items[?name==`' + item.hostname + '`].labels.deploy_status | [] | [0]')}}" + created_instance_name: "{{gcp_compute_instance_info.results | json_query('[].resources[?name==`' + item.hostname + '`].name | [] | [0]')}}" + deploy_status_tag: "{{gcp_compute_instance_info.results | json_query('[].resources[?name==`' + item.hostname + '`].labels.deploy_status | [] | [0]')}}" with_items: "{{cluster_hosts_flat}}" when: created_instance_name != "" - name: Get GCP instance facts - gcp_compute_instance_facts: + gcp_compute_instance_info: zone: "{{cluster_vars.region}}-{{item.az_name}}" filters: - "name = {{item.hostname}}" @@ -136,12 +136,12 @@ service_account_file: "{{gcp_credentials_file}}" scopes: ["https://www.googleapis.com/auth/compute.readonly"] with_items: "{{cluster_hosts_flat}}" - register: gcp_compute_instance_facts_updated + register: gcp_compute_instance_info_updated delegate_to: localhost - set_fact: - current_release_per_instance: "{{gcp_compute_instance_facts_updated.results | json_query(\"[].items[].{value: metadata.items[?key==`release`].value | [0], key: name}\") | items2dict}}" - current_deploy_status_per_instance: "{{gcp_compute_instance_facts_updated.results | json_query(\"[].items[].{value: labels.deploy_status, key: name}\") | items2dict}}" + current_release_per_instance: "{{gcp_compute_instance_info_updated.results | json_query(\"[].resources[].{value: metadata.items[?key==`release`].value | [0], key: name}\") | items2dict}}" + current_deploy_status_per_instance: "{{gcp_compute_instance_info_updated.results | json_query(\"[].resources[].{value: labels.deploy_status, key: name}\") | items2dict}}" - name: update cluster_hosts_flat with current release and deploy_status set_fact: diff --git a/roles/clusterbuild/config/tasks/main.yml b/roles/clusterbuild/config/tasks/main.yml index 982cc5f4..71fc5fff 100644 --- a/roles/clusterbuild/config/tasks/main.yml +++ b/roles/clusterbuild/config/tasks/main.yml @@ -190,5 +190,3 @@ run_once: true with_items: "{{ cluster_hosts_flat }}" when: cluster_vars.dns_server == "route53" and instance_to_create is undefined and rescuing_instance is undefined - delegate_to: localhost - run_once: true diff --git a/roles/clusterbuild/create/tasks/gce.yml b/roles/clusterbuild/create/tasks/gce.yml index 756f1f6a..c9fe5d21 100644 --- a/roles/clusterbuild/create/tasks/gce.yml +++ b/roles/clusterbuild/create/tasks/gce.yml @@ -26,31 +26,31 @@ - name: Create GCP firewalls block: - name: GCP network facts - gcp_compute_network_facts: + gcp_compute_network_info: filters: - "name = {{cluster_vars[buildenv].vpc_network_name}}" project: "{{cluster_vars.project_id}}" auth_kind: "serviceaccount" service_account_file: "{{gcp_credentials_file}}" scopes: ["https://www.googleapis.com/auth/compute.readonly"] - register: gcp_compute_network_facts + register: gcp_compute_network_info - name: "Assert that {{cluster_vars[buildenv].vpc_network_name}} network exists" - assert: { that: "gcp_compute_network_facts['items'] | length > 0", msg: "The {{cluster_vars[buildenv].vpc_network_name}} network must exist (create with ' -e create_gce_network=true')" } + assert: { that: "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')" } - name: GCP subnetwork facts - gcp_compute_subnetwork_facts: + gcp_compute_subnetwork_info: filters: - "name = {{cluster_vars[buildenv].vpc_subnet_name}}" project: "{{cluster_vars.project_id}}" auth_kind: "serviceaccount" service_account_file: "{{gcp_credentials_file}}" scopes: ["https://www.googleapis.com/auth/compute.readonly"] - register: gcp_compute_subnetwork_facts + register: gcp_compute_subnetwork_info when: (cluster_vars[buildenv].vpc_subnet_name is defined) and (cluster_vars[buildenv].vpc_subnet_name != "") - name: "Assert that {{cluster_vars[buildenv].vpc_subnet_name}} subnet exists" - assert: { that: "gcp_compute_subnetwork_facts['items'] | length > 0", msg: "The {{cluster_vars[buildenv].vpc_subnet_name}} subnet must exist" } + assert: { that: "gcp_compute_subnetwork_info['resources'] | length > 0", msg: "The {{cluster_vars[buildenv].vpc_subnet_name}} subnet must exist" } when: (cluster_vars[buildenv].vpc_subnet_name is defined) and (cluster_vars[buildenv].vpc_subnet_name != "") - name: Create GCP cluster firewalls @@ -61,7 +61,7 @@ description: "{{ item.description }}" source_ranges: "{{ item.source_ranges | default([]) }}" source_tags: "{{ item.source_tags | default([]) }}" - network: "{{gcp_compute_network_facts['items'][0]}}" + network: "{{gcp_compute_network_info['resources'][0]}}" auth_kind: "serviceaccount" service_account_file: "{{gcp_credentials_file}}" project: "{{cluster_vars.project_id}}" @@ -93,8 +93,8 @@ startup-script: "#! /bin/bash\n\n#Whitelist my inbound IPs\n[ -f /etc/sshguard/whitelist ] && echo x.x.x.x/26 >>/etc/sshguard/whitelist && /bin/systemctl restart sshguard" ssh-keys: "{{ gce_ssh_username }}: {{ gce_ssh_pubkey }} {{ gce_ssh_username }}" network_interfaces: - - network: "{{ gcp_compute_network_facts['items'][0] | default({}) }}" - subnetwork: "{{ gcp_compute_subnetwork_facts['items'][0] | default({}) }}" + - network: "{{ gcp_compute_network_info['items'][0] | default({}) }}" + subnetwork: "{{ gcp_compute_subnetwork_info['resources'][0] | default({}) }}" access_configs: "{%- if cluster_vars.assign_public_ip == 'yes' -%}[{\"name\": \"External NAT\", \"type\": \"ONE_TO_ONE_NAT\"}]{%- else -%}[]{%- endif -%}" zone: "{{cluster_vars.region}}-{{item.az_name}}" can_ip_forward : "{{cluster_vars.ip_forward}}" @@ -184,7 +184,7 @@ # Need this because the gcp_compute_instance module does not return all the facts if the instance is already existing (only if newly created) # Note: 'scopes' comes from here (https://developers.google.com/identity/protocols/googlescopes#computev1) - name: Get GCP instance facts - gcp_compute_instance_facts: + gcp_compute_instance_info: zone: "{{cluster_vars.region}}-{{item.az_name}}" filters: - "name = {{item.hostname}}" @@ -193,16 +193,16 @@ service_account_file: "{{gcp_credentials_file}}" scopes: ["https://www.googleapis.com/auth/compute.readonly"] with_items: "{{cluster_hosts_flat}}" - register: gcp_compute_instance_facts + register: gcp_compute_instance_info run_once: true - # - debug: msg={{gcp_compute_instance_facts}} + # - debug: msg={{gcp_compute_instance_info}} - set_fact: dynamic_inventory_flat: | {%- if cluster_vars.inventory_ip == 'private' -%} - {{ gcp_compute_instance_facts.results | json_query('[*].items[].{hosttype: metadata.items[?key==`hosttype`].value|[0], hostname: name, private_ip: networkInterfaces[0].networkIP, public_ip: networkInterfaces[0].accessConfigs[0].natIP, inventory_ip: networkInterfaces[0].networkIP}') }} + {{ gcp_compute_instance_info.results | json_query('[*].resources[].{hosttype: metadata.items[?key==`hosttype`].value|[0], hostname: name, private_ip: networkInterfaces[0].networkIP, public_ip: networkInterfaces[0].accessConfigs[0].natIP, inventory_ip: networkInterfaces[0].networkIP}') }} {%- else -%} - {{ gcp_compute_instance_facts.results | json_query('[*].items[].{hosttype: metadata.items[?key==`hosttype`].value|[0], hostname: name, private_ip: networkInterfaces[0].networkIP, public_ip: networkInterfaces[0].accessConfigs[0].natIP, inventory_ip: networkInterfaces[0].accessConfigs[0].natIP}') }} + {{ gcp_compute_instance_info.results | json_query('[*].resources[].{hosttype: metadata.items[?key==`hosttype`].value|[0], hostname: name, private_ip: networkInterfaces[0].networkIP, public_ip: networkInterfaces[0].accessConfigs[0].natIP, inventory_ip: networkInterfaces[0].accessConfigs[0].natIP}') }} {%- endif -%} diff --git a/roles/clusterbuild/readiness/tasks/remove_maintenance_mode.yml b/roles/clusterbuild/readiness/tasks/remove_maintenance_mode.yml index 44e23f9f..7a2aa861 100644 --- a/roles/clusterbuild/readiness/tasks/remove_maintenance_mode.yml +++ b/roles/clusterbuild/readiness/tasks/remove_maintenance_mode.yml @@ -39,7 +39,7 @@ - block: - name: Get GCP instance facts - gcp_compute_instance_facts: + gcp_compute_instance_info: zone: "{{cluster_vars.region}}-{{item.az_name}}" filters: - "name = {{item.hostname}}*" @@ -49,7 +49,7 @@ service_account_file: "{{gcp_credentials_file}}" scopes: ["https://www.googleapis.com/auth/compute.readonly"] with_items: "{{cluster_hosts_flat}}" - register: gcp_compute_instance_facts + register: gcp_compute_instance_info delegate_to: localhost - name: delete maintenance_mode label @@ -65,7 +65,7 @@ delegate_to: localhost run_once: true vars: - maintenance_mode_tag: "{{gcp_compute_instance_facts.results | json_query('[].items[?name==`' + item.hostname + '`].labels.maintenance_mode | [] | [0]')}}" + maintenance_mode_tag: "{{gcp_compute_instance_info.results | json_query('[].resources[?name==`' + item.hostname + '`].labels.maintenance_mode | [] | [0]')}}" with_items: "{{cluster_hosts_flat}}" when: maintenance_mode_tag != "" diff --git a/roles/clusterbuild/redeploy/tasks/gce-gather-instance-to-stop.yml b/roles/clusterbuild/redeploy/tasks/gce-gather-instance-to-stop.yml index 9b3ab199..47d57ef0 100755 --- a/roles/clusterbuild/redeploy/tasks/gce-gather-instance-to-stop.yml +++ b/roles/clusterbuild/redeploy/tasks/gce-gather-instance-to-stop.yml @@ -3,7 +3,7 @@ - debug: msg="Stop {{host_to_stop.hostname}}, release {{release_to_stop}}" - name: gcp_gather | Get GCP instance facts - gcp_compute_instance_facts: + gcp_compute_instance_info: zone: "{{cluster_vars.region}}-{{cluster_hosts_flat | json_query('[? hostname == `' + host_to_stop.hostname + '`].az_name|[0]')}}" filters: - "name = {{host_to_stop.hostname}}*" @@ -12,10 +12,10 @@ auth_kind: "serviceaccount" service_account_file: "{{gcp_credentials_file}}" scopes: ["https://www.googleapis.com/auth/compute.readonly"] - register: existing_gcp + register: gcp_compute_instance_info delegate_to: localhost run_once: true - name: "set argument variables for {{mainclusteryml}}" set_fact: - instance_to_create: "{{ existing_gcp | json_query('items[0].name') | regex_replace('-(?!.*-).*') + '-'+epoch_time}}" + instance_to_create: "{{ gcp_compute_instance_info | json_query('resources[0].name') | regex_replace('-(?!.*-).*') + '-'+epoch_time}}" diff --git a/roles/clusterbuild/redeploy/tasks/gce_del.yml b/roles/clusterbuild/redeploy/tasks/gce_del.yml index e630c39c..7d9f96d1 100644 --- a/roles/clusterbuild/redeploy/tasks/gce_del.yml +++ b/roles/clusterbuild/redeploy/tasks/gce_del.yml @@ -3,7 +3,7 @@ - name: Delete GCP instance block: - name: Get GCP instance facts - gcp_compute_instance_facts: + gcp_compute_instance_info: zone: "{{cluster_vars.region}}-{{item.az_name}}" filters: - "name = {{item.hostname | regex_replace('-(?!.*-).*')}}*" @@ -13,13 +13,13 @@ service_account_file: "{{gcp_credentials_file}}" scopes: ["https://www.googleapis.com/auth/compute.readonly"] with_items: "{{cluster_hosts_flat}}" - register: gcp_compute_instance_facts + register: gcp_compute_instance_info delegate_to: localhost run_once: true - name: Remove deletion protection command: "gcloud compute instances update {{item.name}} --no-deletion-protection --zone {{item.zone | regex_replace('.*/(.*)$', '\\1')}}" - with_items: "{{gcp_compute_instance_facts.results | json_query('[].items[]')}}" + with_items: "{{gcp_compute_instance_info.results | json_query('[].resources[]')}}" delegate_to: localhost run_once: true when: "cluster_vars[buildenv].deletion_protection == 'yes'" @@ -37,8 +37,8 @@ delegate_to: localhost run_once: true vars: - maintenance_mode_tag: "{{gcp_compute_instance_facts.results | json_query('[].items[?name==`' + item.name + '`].labels.maintenance_mode | [] | [0]')}}" - with_items: "{{gcp_compute_instance_facts.results | json_query('[].items[]')}}" + maintenance_mode_tag: "{{gcp_compute_instance_info.results | json_query('[].resources[?name==`' + item.name + '`].labels.maintenance_mode | [] | [0]')}}" + with_items: "{{gcp_compute_instance_info.results | json_query('[].resources[]')}}" when: maintenance_mode_tag != "" - name: remove_maintenance_mode @@ -53,7 +53,7 @@ state: present delegate_to: localhost run_once: true - with_items: "{{gcp_compute_instance_facts.results | json_query('[].items[]')}}" + with_items: "{{gcp_compute_instance_info.results | json_query('[].resources[]')}}" - name: Delete GCE VMs asynchronously gcp_compute_instance: @@ -64,7 +64,7 @@ service_account_file: "{{gcp_credentials_file}}" state: "absent" register: gcp_compute_instance - with_items: "{{gcp_compute_instance_facts.results | json_query('[].items[]')}}" + with_items: "{{gcp_compute_instance_info.results | json_query('[].resources[]')}}" async: 7200 poll: 0 diff --git a/roles/clusterbuild/redeploy/tasks/gce_rescue.yml b/roles/clusterbuild/redeploy/tasks/gce_rescue.yml index 66e9cb0e..cfb89d8a 100644 --- a/roles/clusterbuild/redeploy/tasks/gce_rescue.yml +++ b/roles/clusterbuild/redeploy/tasks/gce_rescue.yml @@ -4,7 +4,7 @@ - debug: msg="Rescuing" - name: gce_restore | Get GCP instance facts - gcp_compute_instance_facts: + gcp_compute_instance_info: zone: "{{cluster_vars.region}}-{{item.az_name}}" filters: - "name = {{item.hostname | regex_replace('-(?!.*-).*')}}*" @@ -13,18 +13,18 @@ service_account_file: "{{gcp_credentials_file}}" scopes: ["https://www.googleapis.com/auth/compute.readonly"] with_items: "{{cluster_hosts_flat}}" - register: rollback_instances + register: gcp_compute_instance_info delegate_to: localhost run_once: true - name: gce_restore | set hosts_to_rollback_stopped - set_fact: hosts_to_rollback_stopped={{rollback_instances | json_query('results[].items[?labels.deploy_status == `old` && status==`TERMINATED`].name | []') | list | sort(reverse=True)}} + set_fact: hosts_to_rollback_stopped={{gcp_compute_instance_info | json_query('results[].resources[?labels.deploy_status == `old` && status==`TERMINATED`].name | []') | list | sort(reverse=True)}} - name: gce_restore | set expected nodes set_fact: remove_first: "{{hosts_running|int - current_cluter_size|int}}" vars: - hosts_running: "{{rollback_instances | json_query('results[].items[?status==`RUNNING`].name | []') | length}}" + hosts_running: "{{gcp_compute_instance_info | json_query('results[].resources[?status==`RUNNING`].name | []') | length}}" - name: gce_restore | remove spare instance (if exixsts) block: @@ -32,13 +32,13 @@ - set_fact: host_to_redeploy: "{'hostname': \"{{host_to_redeploy_hostname}}\"}" vars: - host_to_redeploy_hostname: "{{rollback_instances | json_query('results[].items[?labels.deploy_status == `new` && status==`RUNNING`].name | []') | list | sort(reverse=True) | first}}" + host_to_redeploy_hostname: "{{gcp_compute_instance_info | json_query('results[].resources[?labels.deploy_status == `new` && status==`RUNNING`].name | []') | list | sort(reverse=True) | first}}" - set_fact: j_recover_arg: "[?starts_with(@, '{{host_to_redeploy.hostname | regex_replace('-(?!.*-).*')}}')] | [0]" - set_fact: - host_to_recover: "{{rollback_instances | json_query('results[*].items[].name') | difference([host_to_redeploy.hostname])| to_json | from_json | json_query(j_recover_arg)}}" + host_to_recover: "{{gcp_compute_instance_info | json_query('results[*].resources[].name') | difference([host_to_redeploy.hostname])| to_json | from_json | json_query(j_recover_arg)}}" - name: Replace CNAME nsupdate: diff --git a/roles/clusterbuild/redeploy/tasks/gce_stop_instance.yml b/roles/clusterbuild/redeploy/tasks/gce_stop_instance.yml index 01f0a1ce..5624b932 100644 --- a/roles/clusterbuild/redeploy/tasks/gce_stop_instance.yml +++ b/roles/clusterbuild/redeploy/tasks/gce_stop_instance.yml @@ -7,7 +7,7 @@ block: - name: Get GCP instance facts - gcp_compute_instance_facts: + gcp_compute_instance_info: zone: "{{cluster_vars.region}}-{{host_to_stop.hostname | regex_replace('.*-([a-z])[0-9]-.*', '\\1')}}" filters: - "name = {{host_to_stop.hostname}}*" @@ -16,7 +16,7 @@ auth_kind: "serviceaccount" service_account_file: "{{gcp_credentials_file}}" scopes: ["https://www.googleapis.com/auth/compute.readonly"] - register: gcp_compute_instance_facts + register: gcp_compute_instance_info delegate_to: localhost - name: Delete maintenance_mode label @@ -32,7 +32,7 @@ delegate_to: localhost run_once: true vars: - maintenance_mode_tag: "{{gcp_compute_instance_facts | json_query('items[?name==`' + host_to_stop.hostname + '`].labels.maintenance_mode | [] | [0]')}}" + maintenance_mode_tag: "{{gcp_compute_instance_info | json_query('resources[?name==`' + host_to_stop.hostname + '`].labels.maintenance_mode | [] | [0]')}}" when: maintenance_mode_tag != "" - name: Set_maintenance_mode