Skip to content

Instantly share code, notes, and snippets.

@gowatana
Created March 24, 2023 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gowatana/9dc6ae9b4f64e5705ea33cc9e829046e to your computer and use it in GitHub Desktop.
Save gowatana/9dc6ae9b4f64e5705ea33cc9e829046e to your computer and use it in GitHub Desktop.
- name: Get Edge Gateways
ansible.builtin.uri:
url: "https://{{ var_host }}/cloudapi/1.0.0/edgeGateways"
method: GET
force_basic_auth: true
headers:
Accept: "application/json;version={{ var_api_version }}"
Authorization: "Bearer {{ token.x_vmware_vcloud_access_token }}"
status_code: 200
validate_certs: "{{ var_verify_ssl_certs }}"
register: edge_gateways
- name: Set Edge Gateway ID
ansible.builtin.set_fact:
edge_gateway_id: "{{ (edge_gateways.json['values'] | selectattr('name', '==', edge_gw_name) | first).id }}"
- name: Get Edge Gateway NAT Rules
ansible.builtin.uri:
url: "https://{{ var_host }}/cloudapi/1.0.0/edgeGateways/{{ edge_gateway_id }}/nat/rules"
method: GET
force_basic_auth: true
headers:
Accept: "application/json;version={{ var_api_version }}"
Authorization: "Bearer {{ token.x_vmware_vcloud_access_token }}"
status_code: 200
validate_certs: "{{ var_verify_ssl_certs }}"
register: edge_gateway_nat_rules
- name: Set NAT Rule ID
ansible.builtin.set_fact:
nat_rule_id: "{{ (edge_gateway_nat_rules.json['values'] | selectattr('name', '==', var_nat_rule_name) | first).id | default('NA') }}"
- name: Output NAT Rule ID
ansible.builtin.debug:
var: nat_rule_id
- name: Delete Edge Gateway NAT Rule {{ var_nat_rule_name }}
ansible.builtin.uri:
url: "https://{{ var_host }}/cloudapi/1.0.0/edgeGateways/{{ edge_gateway_id }}/nat/rules/{{ nat_rule_id }}"
method: DELETE
force_basic_auth: true
headers:
Accept: "application/json;version={{ var_api_version }}"
Authorization: "Bearer {{ token.x_vmware_vcloud_access_token }}"
status_code: 202
validate_certs: "{{ var_verify_ssl_certs }}"
when: nat_rule_id != "NA"
@gowatana
Copy link
Author

下記の投稿むけ。

VMware Cloud Director 10.4 を Ansible で操作してみる。Part-06 複数の DNAT VM を作成するPlaybook 例
https://vm.gowatana.jp/entry/2023/03/25/043925

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment