Ansible uri 모듈과 Power Cloud API를 사용하여 IBM Cloud PowerSystems Virtual Server 볼륨 생성

API를 직접 실행하면 galaxy collection이나 플러그인을 거치지 않고 IBM Cloud PowerSystems Virtual Severs를 조작할 수 있다고 생각하고 Ansible uri 모듈에서 Power Cloud API 실행을 확인한 로그입니다.

환경:



· IBM Cloud PowerSystems Virtual Server 서비스
참고: IBM Cloud Docs: IBM Power Systems Virtual Server 개요

・Ansible 2.9.9 (from Local Mac)

· 전제가 되는 API 키 취득: IBM Cloud Docs: API 키 만들기
· 전제 CRN (클라우드 리소스 이름) 획득 : IBM Cloud Docs 클라우드 리소스 이름

· 전제 인스턴스 ID 얻기 : IBM Cloud Docs : 인스턴스 ID 얻기

사용할 PowerCloud API, Ansible uri module



· PowerCloud API
사용할 API : Power Cloud API "Create a new data volume"

・Ansible uri module

참고: Ansible "uri module"

실행할 Playbook



uri_volume_create.yml을 다음과 같이 만들었습니다.

uri_volume_create.yml
---
- name: POWER VSI IAM TOKEN
  hosts: localhost
  gather_facts : no

  tasks: 
  - name: Get IAM access token  #<= TOKEN の発行                      
    uri:
      url: https://iam.cloud.ibm.com/identity/token
      method: POST
      headers:
        Accept: application/json
        Content-Type: application/x-www-form-urlencoded
      body: 
           grant_type: urn:ibm:params:oauth:grant-type:apikey
           apikey: < API key を入力 > 
      body_format: form-urlencoded
      validate_certs: no
    register: auth_token

  - name: Set Variable OS_TOKEN
    set_fact: 
      OS_TOKEN: "{{ auth_token.json.access_token }}"

  - name: Print OS_TOKEN  #<= TOKEN の確認
    debug:
        var: OS_TOKEN

  - name: Create Volume  #<= ボリュームの作成
    uri:
      url: https://us-south.power-iaas.cloud.ibm.com/pcloud/v1/cloud-instances/< 事前に取得した instance_id >/volumes
      method: POST
      status_code: [200, 202]   #<= なしで実行すると 202 が返りAnsible実行がfailed となったので追加しています。
      headers:
        Authorization: Bearer {{ OS_TOKEN }}
        Content-Type: application/json
        CRN: "< CRN を入力> "
      body_format: json
      body: 
         "diskType": "tier3"               #<= ディスク・タイプ(tier1 , tier3 など)
         "name": "ansible_testvol"         #<= volume 名 (任意)
         "size": 10                        #<= サイズ GB (任意)
         "shareable": true                 #<= 共有設定 (true or false)

실행


$ ansible-playbook uri_volume_create.yml
[WARNING]: Unable to parse /Users/c_u/Desktop/ansible_power_iaas/inventory as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

PLAY [POWER VSI IAM TOKEN] **********************************************************************************************************************************************************

TASK [Get auth token] ***************************************************************************************************************************************************************
ok: [localhost]

TASK [Set Variable OS_TOKEN] ********************************************************************************************************************************************************
ok: [localhost]

TASK [Print OS_TOKEN] ***************************************************************************************************************************************************************
ok: [localhost] => {
    "OS_TOKEN": "xxxx TOKEN の長い文字列の表示 xxxx"
}

TASK [Create Volume] **************************************************************************************************************************************************************
ok: [localhost]

PLAY RECAP **************************************************************************************************************************************************************************
localhost                  : ok=4    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

확인



작성되었음을 IBM cloud 콘솔에서 확인했습니다.


다른 API에서도 실행할 수 있습니까?

이상입니다.

좋은 웹페이지 즐겨찾기