|
| 1 | +--- |
| 2 | + |
| 3 | +- name: Configure Azure NAT Gateway |
| 4 | + become: false |
| 5 | + connection: local |
| 6 | + hosts: localhost |
| 7 | + gather_facts: false |
| 8 | + vars: |
| 9 | + kubeconfig: "{{ lookup('env', 'KUBECONFIG') }}" |
| 10 | + resource_prefix: "coco" |
| 11 | + tasks: |
| 12 | + - name: Get Azure credentials |
| 13 | + kubernetes.core.k8s_info: |
| 14 | + kind: Secret |
| 15 | + namespace: openshift-cloud-controller-manager |
| 16 | + name: azure-cloud-credentials |
| 17 | + register: azure_credentials |
| 18 | + retries: 20 |
| 19 | + delay: 5 |
| 20 | + |
| 21 | + - name: Get Azure credentials |
| 22 | + kubernetes.core.k8s_info: |
| 23 | + kind: ConfigMap |
| 24 | + namespace: openshift-cloud-controller-manager |
| 25 | + name: cloud-conf |
| 26 | + register: azure_cloud_conf |
| 27 | + retries: 20 |
| 28 | + delay: 5 |
| 29 | + |
| 30 | + - name: Set facts |
| 31 | + ansible.builtin.set_fact: |
| 32 | + azure_subscription_id: "{{ (azure_cloud_conf.resources[0]['data']['cloud.conf'] | from_json)['subscriptionId'] }}" |
| 33 | + azure_tenant_id: "{{ (azure_cloud_conf.resources[0]['data']['cloud.conf'] | from_json)['tenantId'] }}" |
| 34 | + azure_resource_group: "{{ (azure_cloud_conf.resources[0]['data']['cloud.conf'] | from_json)['vnetResourceGroup'] }}" |
| 35 | + azure_client_id: "{{ azure_credentials.resources[0]['data']['azure_client_id'] | b64decode }}" |
| 36 | + azure_client_secret: "{{ azure_credentials.resources[0]['data']['azure_client_secret'] | b64decode }}" |
| 37 | + azure_vnet: "{{ (azure_cloud_conf.resources[0]['data']['cloud.conf'] | from_json)['vnetName'] }}" |
| 38 | + azure_subnet: "{{ (azure_cloud_conf.resources[0]['data']['cloud.conf'] | from_json)['subnetName'] }}" |
| 39 | + coco_public_ip_name: "{{ resource_prefix }}-pip" |
| 40 | + coco_nat_gateway_name: "{{ resource_prefix }}-nat-gateway" |
| 41 | + no_log: true |
| 42 | + |
| 43 | + - name: Create Public IP for NAT Gateway |
| 44 | + azure_rm_publicipaddress: |
| 45 | + subscription_id: "{{ azure_subscription_id }}" |
| 46 | + tenant: "{{ azure_tenant_id }}" |
| 47 | + client_id: "{{ azure_client_id }}" |
| 48 | + secret: "{{ azure_client_secret }}" |
| 49 | + resource_group: "{{ azure_resource_group }}" |
| 50 | + name: "{{ coco_public_ip_name }}" |
| 51 | + sku: "standard" |
| 52 | + allocation_method: "static" |
| 53 | + |
| 54 | + - name: Retrieve Public IP for NAT Gateway |
| 55 | + azure_rm_publicipaddress_info: |
| 56 | + subscription_id: "{{ azure_subscription_id }}" |
| 57 | + tenant: "{{ azure_tenant_id }}" |
| 58 | + client_id: "{{ azure_client_id }}" |
| 59 | + secret: "{{ azure_client_secret }}" |
| 60 | + resource_group: "{{ azure_resource_group }}" |
| 61 | + name: "{{ coco_public_ip_name }}" |
| 62 | + register: coco_gw_public_ip |
| 63 | + |
| 64 | + - name: Create NAT Gateway |
| 65 | + azure.azcollection.azure_rm_natgateway: |
| 66 | + subscription_id: "{{ azure_subscription_id }}" |
| 67 | + tenant: "{{ azure_tenant_id }}" |
| 68 | + client_id: "{{ azure_client_id }}" |
| 69 | + secret: "{{ azure_client_secret }}" |
| 70 | + resource_group: "{{ azure_resource_group }}" |
| 71 | + name: "{{ coco_nat_gateway_name }}" |
| 72 | + idle_timeout_in_minutes: 10 |
| 73 | + sku: |
| 74 | + name: standard |
| 75 | + public_ip_addresses: |
| 76 | + - "{{ coco_gw_public_ip.publicipaddresses[0].id }}" |
| 77 | + register: coco_natgw |
| 78 | + |
| 79 | + - name: Update the worker subnet to associate NAT gateway |
| 80 | + azure.azcollection.azure_rm_subnet: |
| 81 | + subscription_id: "{{ azure_subscription_id }}" |
| 82 | + tenant: "{{ azure_tenant_id }}" |
| 83 | + client_id: "{{ azure_client_id }}" |
| 84 | + secret: "{{ azure_client_secret }}" |
| 85 | + resource_group: "{{ azure_resource_group }}" |
| 86 | + name: "{{ azure_subnet }}" |
| 87 | + virtual_network_name: "{{ azure_vnet }}" |
| 88 | + nat_gateway: "{{ coco_nat_gateway_name }}" |
| 89 | +... |
0 commit comments