Skip to content

Instantly share code, notes, and snippets.

@gowatana
Created July 12, 2023 23:02
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/86d87787b755228b9e7be5c14bb3e809 to your computer and use it in GitHub Desktop.
Save gowatana/86d87787b755228b9e7be5c14bb3e809 to your computer and use it in GitHub Desktop.
---
- name: Get VMC on AWS cost
hosts: localhost
gather_facts: false
vars_files:
- id_and_key.yml
tasks:
- name: get access token
ansible.builtin.uri:
url: "https://console.cloud.vmware.com/csp/gateway/am/api/auth/api-tokens/authorize"
method: POST
headers:
Accept: "application/json"
Content-Type: "application/x-www-form-urlencoded"
body: "refresh_token={{ api_key }}"
body_format: json
status_code: 200
register: token
- name: get cost info
ansible.builtin.uri:
url: "https://console.cloud.vmware.com/csp/gateway/commerce/api/v1/orgs/{{ org_id }}/estimated-charges"
method: GET
headers:
Accept: "application/json"
csp-auth-token: "{{ token.json.access_token }}"
status_code: 200
register: cost_info
- name: output cost info
debug:
msg: "{{ lookup('pipe', 'date +\"%Y-%m-%d %H:%M:%S\"') }} {{ cost_info.json.totalPayments }} {{ cost_info.json.currency }}"
@gowatana
Copy link
Author

下記の投稿むけ。

VMware Cloud on AWS のコストを情報を REST API で見てみる。(curl / Ansible)
https://vm.gowatana.jp/entry/2023/07/13/084828

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