Skip to content

Instantly share code, notes, and snippets.

@gowatana
Last active March 20, 2023 15:09
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save gowatana/110b75eb3ca966c9c6e3ee98d7d89d75 to your computer and use it in GitHub Desktop.
- name: List VCD Edge Gateway NAT Rules
hosts: localhost
gather_facts: false
vars:
var_host: "lab-vcd-31.vcd.go-lab.jp"
var_org: "demo-org-01"
#var_user: "administrator@system"
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"
tasks:
- name: get Token
ansible.builtin.uri:
url: "https://{{ var_host }}/cloudapi/1.0.0/sessions"
#url: "https://{{ var_host }}/cloudapi/1.0.0/sessions/provider"
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: output token
# debug:
# var: 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: output edge_gateways
# debug:
# var: 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: output Edge Gateway ID
debug:
var: edge_gateway_id
- name: get Edge Gateway {{ var_edge_gw_name }} 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: output Edge Gateway NAT Rules
debug:
var: edge_gateway_nat_rules.json['values']
@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