| 1 |
--- |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
- name: Create a network |
| 17 |
google.cloud.gcp_compute_network: |
| 18 |
name: network-instancetemplate |
| 19 |
project: "{{ gcp_project }}" |
| 20 |
auth_kind: "{{ gcp_cred_kind }}" |
| 21 |
service_account_file: "{{ gcp_cred_file | default(omit) }}" |
| 22 |
auto_create_subnetworks: true |
| 23 |
state: present |
| 24 |
register: network |
| 25 |
- name: Create a address |
| 26 |
google.cloud.gcp_compute_address: |
| 27 |
name: address-instancetemplate |
| 28 |
region: us-central1 |
| 29 |
project: "{{ gcp_project }}" |
| 30 |
auth_kind: "{{ gcp_cred_kind }}" |
| 31 |
service_account_file: "{{ gcp_cred_file | default(omit) }}" |
| 32 |
state: present |
| 33 |
register: address |
| 34 |
- name: Create a instance template |
| 35 |
google.cloud.gcp_compute_instance_template: |
| 36 |
name: "{{ resource_name }}" |
| 37 |
properties: |
| 38 |
disks: |
| 39 |
- auto_delete: "true" |
| 40 |
boot: "true" |
| 41 |
initialize_params: |
| 42 |
source_image: projects/ubuntu-os-cloud/global/images/family/ubuntu-minimal-2204-lts |
| 43 |
machine_type: n1-standard-1 |
| 44 |
network_interfaces: |
| 45 |
- network: "{{ network }}" |
| 46 |
access_configs: |
| 47 |
- name: test-config |
| 48 |
type: ONE_TO_ONE_NAT |
| 49 |
nat_ip: "{{ address }}" |
| 50 |
project: "{{ gcp_project }}" |
| 51 |
auth_kind: "{{ gcp_cred_kind }}" |
| 52 |
service_account_file: "{{ gcp_cred_file | default(omit) }}" |
| 53 |
state: present |
| 54 |
register: instancetemplate |
| 55 |
- name: Create a instance group manager |
| 56 |
google.cloud.gcp_compute_instance_group_manager: |
| 57 |
name: "{{ resource_name }}" |
| 58 |
base_instance_name: test1-child |
| 59 |
instance_template: "{{ instancetemplate }}" |
| 60 |
target_size: 3 |
| 61 |
zone: us-central1-a |
| 62 |
project: "{{ gcp_project }}" |
| 63 |
auth_kind: "{{ gcp_cred_kind }}" |
| 64 |
service_account_file: "{{ gcp_cred_file | default(omit) }}" |
| 65 |
state: present |
| 66 |
register: igm |
| 67 |
- name: Delete a autoscaler |
| 68 |
google.cloud.gcp_compute_autoscaler: |
| 69 |
name: "{{ resource_name }}" |
| 70 |
zone: us-central1-a |
| 71 |
target: "{{ igm }}" |
| 72 |
autoscaling_policy: |
| 73 |
max_num_replicas: 5 |
| 74 |
min_num_replicas: 1 |
| 75 |
cool_down_period_sec: 60 |
| 76 |
cpu_utilization: |
| 77 |
utilization_target: !!float "0.5" |
| 78 |
project: "{{ gcp_project }}" |
| 79 |
auth_kind: "{{ gcp_cred_kind }}" |
| 80 |
service_account_file: "{{ gcp_cred_file | default(omit) }}" |
| 81 |
state: absent |
| 82 |
|
| 83 |
- name: Create a autoscaler |
| 84 |
google.cloud.gcp_compute_autoscaler: |
| 85 |
name: "{{ resource_name }}" |
| 86 |
zone: us-central1-a |
| 87 |
target: "{{ igm }}" |
| 88 |
autoscaling_policy: |
| 89 |
max_num_replicas: 5 |
| 90 |
min_num_replicas: 1 |
| 91 |
cool_down_period_sec: 60 |
| 92 |
cpu_utilization: |
| 93 |
utilization_target: !!float "0.5" |
| 94 |
project: "{{ gcp_project }}" |
| 95 |
auth_kind: "{{ gcp_cred_kind }}" |
| 96 |
service_account_file: "{{ gcp_cred_file | default(omit) }}" |
| 97 |
state: present |
| 98 |
register: result |
| 99 |
- name: Assert changed is true |
| 100 |
ansible.builtin.assert: |
| 101 |
that: |
| 102 |
- result.changed == true |
| 103 |
- name: Verify that autoscaler was created |
| 104 |
google.cloud.gcp_compute_autoscaler_info: |
| 105 |
filters: |
| 106 |
- name = {{ resource_name }} |
| 107 |
zone: us-central1-a |
| 108 |
project: "{{ gcp_project }}" |
| 109 |
auth_kind: "{{ gcp_cred_kind }}" |
| 110 |
service_account_file: "{{ gcp_cred_file | default(omit) }}" |
| 111 |
scopes: |
| 112 |
- https://www.googleapis.com/auth/compute |
| 113 |
register: results |
| 114 |
- name: Verify that command succeeded |
| 115 |
ansible.builtin.assert: |
| 116 |
that: |
| 117 |
- results['resources'] | length == 1 |
| 118 |
|
| 119 |
- name: Create a autoscaler that already exists |
| 120 |
google.cloud.gcp_compute_autoscaler: |
| 121 |
name: "{{ resource_name }}" |
| 122 |
zone: us-central1-a |
| 123 |
target: "{{ igm }}" |
| 124 |
autoscaling_policy: |
| 125 |
max_num_replicas: 5 |
| 126 |
min_num_replicas: 1 |
| 127 |
cool_down_period_sec: 60 |
| 128 |
cpu_utilization: |
| 129 |
utilization_target: !!float "0.5" |
| 130 |
project: "{{ gcp_project }}" |
| 131 |
auth_kind: "{{ gcp_cred_kind }}" |
| 132 |
service_account_file: "{{ gcp_cred_file | default(omit) }}" |
| 133 |
state: present |
| 134 |
register: result |
| 135 |
- name: Assert changed is false |
| 136 |
ansible.builtin.assert: |
| 137 |
that: |
| 138 |
- result.changed == false |
| 139 |
|
| 140 |
- name: Delete a autoscaler |
| 141 |
google.cloud.gcp_compute_autoscaler: |
| 142 |
name: "{{ resource_name }}" |
| 143 |
zone: us-central1-a |
| 144 |
target: "{{ igm }}" |
| 145 |
autoscaling_policy: |
| 146 |
max_num_replicas: 5 |
| 147 |
min_num_replicas: 1 |
| 148 |
cool_down_period_sec: 60 |
| 149 |
cpu_utilization: |
| 150 |
utilization_target: !!float "0.5" |
| 151 |
project: "{{ gcp_project }}" |
| 152 |
auth_kind: "{{ gcp_cred_kind }}" |
| 153 |
service_account_file: "{{ gcp_cred_file | default(omit) }}" |
| 154 |
state: absent |
| 155 |
register: result |
| 156 |
- name: Assert changed is true |
| 157 |
ansible.builtin.assert: |
| 158 |
that: |
| 159 |
- result.changed == true |
| 160 |
- name: Verify that autoscaler was deleted |
| 161 |
google.cloud.gcp_compute_autoscaler_info: |
| 162 |
filters: |
| 163 |
- name = {{ resource_name }} |
| 164 |
zone: us-central1-a |
| 165 |
project: "{{ gcp_project }}" |
| 166 |
auth_kind: "{{ gcp_cred_kind }}" |
| 167 |
service_account_file: "{{ gcp_cred_file | default(omit) }}" |
| 168 |
scopes: |
| 169 |
- https://www.googleapis.com/auth/compute |
| 170 |
register: results |
| 171 |
- name: Verify that command succeeded |
| 172 |
ansible.builtin.assert: |
| 173 |
that: |
| 174 |
- results['resources'] | length == 0 |
| 175 |
|
| 176 |
- name: Delete a autoscaler that does not exist |
| 177 |
google.cloud.gcp_compute_autoscaler: |
| 178 |
name: "{{ resource_name }}" |
| 179 |
zone: us-central1-a |
| 180 |
target: "{{ igm }}" |
| 181 |
autoscaling_policy: |
| 182 |
max_num_replicas: 5 |
| 183 |
min_num_replicas: 1 |
| 184 |
cool_down_period_sec: 60 |
| 185 |
cpu_utilization: |
| 186 |
utilization_target: !!float "0.5" |
| 187 |
project: "{{ gcp_project }}" |
| 188 |
auth_kind: "{{ gcp_cred_kind }}" |
| 189 |
service_account_file: "{{ gcp_cred_file | default(omit) }}" |
| 190 |
state: absent |
| 191 |
register: result |
| 192 |
- name: Assert changed is false |
| 193 |
ansible.builtin.assert: |
| 194 |
that: |
| 195 |
- result.changed == false |
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
- name: Delete a instance group manager |
| 200 |
google.cloud.gcp_compute_instance_group_manager: |
| 201 |
name: "{{ resource_name }}" |
| 202 |
base_instance_name: test1-child |
| 203 |
instance_template: "{{ instancetemplate }}" |
| 204 |
target_size: 3 |
| 205 |
zone: us-central1-a |
| 206 |
project: "{{ gcp_project }}" |
| 207 |
auth_kind: "{{ gcp_cred_kind }}" |
| 208 |
service_account_file: "{{ gcp_cred_file | default(omit) }}" |
| 209 |
state: absent |
| 210 |
register: igm |
| 211 |
ignore_errors: true |
| 212 |
- name: Delete a instance template |
| 213 |
google.cloud.gcp_compute_instance_template: |
| 214 |
name: "{{ resource_name }}" |
| 215 |
properties: |
| 216 |
disks: |
| 217 |
- auto_delete: "true" |
| 218 |
boot: "true" |
| 219 |
initialize_params: |
| 220 |
source_image: projects/ubuntu-os-cloud/global/images/family/ubuntu-minimal-2204-lts |
| 221 |
machine_type: n1-standard-1 |
| 222 |
network_interfaces: |
| 223 |
- network: "{{ network }}" |
| 224 |
access_configs: |
| 225 |
- name: test-config |
| 226 |
type: ONE_TO_ONE_NAT |
| 227 |
nat_ip: "{{ address }}" |
| 228 |
project: "{{ gcp_project }}" |
| 229 |
auth_kind: "{{ gcp_cred_kind }}" |
| 230 |
service_account_file: "{{ gcp_cred_file | default(omit) }}" |
| 231 |
state: absent |
| 232 |
register: instancetemplate |
| 233 |
ignore_errors: true |
| 234 |
- name: Delete a address |
| 235 |
google.cloud.gcp_compute_address: |
| 236 |
name: address-instancetemplate |
| 237 |
region: us-central1 |
| 238 |
project: "{{ gcp_project }}" |
| 239 |
auth_kind: "{{ gcp_cred_kind }}" |
| 240 |
service_account_file: "{{ gcp_cred_file | default(omit) }}" |
| 241 |
state: absent |
| 242 |
register: address |
| 243 |
ignore_errors: true |
| 244 |
- name: Delete a network |
| 245 |
google.cloud.gcp_compute_network: |
| 246 |
name: network-instancetemplate |
| 247 |
project: "{{ gcp_project }}" |
| 248 |
auth_kind: "{{ gcp_cred_kind }}" |
| 249 |
service_account_file: "{{ gcp_cred_file | default(omit) }}" |
| 250 |
auto_create_subnetworks: true |
| 251 |
state: absent |
| 252 |
register: network |
| 253 |
ignore_errors: true |