0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Ansible uri モジュールを使用してPowerVC API で token を発行する

Last updated at Posted at 2022-08-17

はじめに

PowerVC で Ansible の uri モジュールを用いて API での token 発行方法を確認しました。

参考:Supported OpenStack Identity (Keystone) APIs


環境

・PowerVC 2.0.1 (RHEL 8.4, ppc64le on S824)
・Ansible 2.13.1, python 3.10.5 (Mac に導入して実行)


実行スクリプト

次の tokenissue.yml を作成。

tokenissue.yml
---
- name: token issue
  hosts: localhost
  tasks:
   - name: Get auth token
     uri:
       url: "https://<PowerVC IP address>:5000/v3/auth/tokens"    #<= 要編集
       method: POST
       headers:
         Accept: application/json
       body: "{{ lookup('template', 'token.json') }}"      #<= token.jsonは外部ファイル
       body_format: json
       return_content: yes
       status_code: 201
       validate_certs: no
     register: auth_token

   - name: Set Variable OS_TOKEN
     set_fact: OS_TOKEN="{{ auth_token.x_subject_token }}"

   - name: show previous stdout
     debug:   
       msg: "{{ OS_TOKEN }}"

tokenissue.yml の中で呼んでいる token.jsonは以下です。

token.json
{
    "auth":{
       "scope":{
          "project":{
             "name":"ibm-default",
             "domain":{
                "name":"Default"
             }
          }
       },
       "identity":{
          "methods":[
             "password"
          ],
          "password":{
             "user":{
                "domain":{
                   "name":"Default"
                },
                "name":"<user name>",                  #<= 要編集, 実行ユーザー
                "password":"<user password>"           #<= 要編集 実行ユーザーのパスワード
             }
          }
       }
    }
}

実行

PowerVC サーバーに対して tokenissue.yml を実行します。
(ansible.cfg, inventory の書き方は省略します)

$ ansible-playbook tokenissue.yml

PLAY [token issue] *******************************************************************************************************************

TASK [Gathering Facts] ***************************************************************************************************************
ok: [localhost]

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

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

TASK [show previous stdout] **********************************************************************************************************
ok: [localhost] => {
    "msg": "gAAAAABi_DACmemTb-Vrk5PUaIUktUxxxxTs0jiNGc2xB2lF3G4J_QOYrmtdZ6trLxxxxxcvonS9XqE9dsSWSjnYCTg_Xl0tpxxxxx12pLVX4XQ__xc7fOHGPvDlE9pa3xxxxxROQqKPl3Kpzvxwfuek30801b_w"
}

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

Ansible uri モジュールで token 発行 API を実行し、OS_TOKEN 変数として fact で代入することができました。
こちらを使用して、他のAPIを実行する方法を確認しようと思います。

以上です。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?