Skip to content

Instantly share code, notes, and snippets.

@gowatana
Created March 20, 2023 14:21
Show Gist options
  • Save gowatana/d0f51cafe325bda56177c99850000076 to your computer and use it in GitHub Desktop.
Save gowatana/d0f51cafe325bda56177c99850000076 to your computer and use it in GitHub Desktop.
- name: Delete VCD Edge Gateway NAT Rule
hosts: localhost
gather_facts: false
vars:
var_host: "lab-vcd-31.vcd.go-lab.jp"
var_org: "demo-org-01"
var_user: "org-01-admin@demo-org-01"
var_password: "VMware1!"
var_api_version: "37.0"
var_verify_ssl_certs: false
var_edge_gw_name: "org-01-edge-01"
var_nat_rule_name: "dnat-103"
tasks:
- name: get Token
ansible.builtin.uri:
url: "https://{{ var_host }}/cloudapi/1.0.0/sessions"
user: "{{ var_user }}"
password: "{{ var_password }}"
method: POST
force_basic_auth: true
headers:
Accept: "application/json;version={{ var_api_version }}"
status_code: 200
validate_certs: "{{ var_verify_ssl_certs }}"
register: token
- 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
set_fact:
edge_gateway_id: "{{ (edge_gateways.json['values'] | selectattr('name', '==', var_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
set_fact:
nat_rule_id: "{{ (edge_gateway_nat_rules.json['values'] | selectattr('name', '==', var_nat_rule_name) | first).id }}"
- name: output NAT Rule ID
debug:
var: nat_rule_id
- name: Delete Edge Gateway NAT Rule
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
@gowatana
Copy link
Author

下記の投稿むけ。

VMware Cloud Director 10.4 を Ansible で操作してみる。Part-05 Edge Gateway NAT ルールの作成 / 削除
https://vm.gowatana.jp/entry/2023/03/20/234855

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