LoginSignup
1
0

More than 1 year has passed since last update.

"Ansible を使用した PowerVC の自動化" の試行

Last updated at Posted at 2021-01-02

こちらの Tutorial: Ansible を使用した PowerVC の自動化 を参照し、PowerVC での Ansible 操作を試してみました。

** PowerVC のベースは OpenStack のため、Ansible の OpenStack プラグインを使ってある程度操作が可能です。


環境

Ansible Server: Local Mac PC (ansible version 2.9.9)
target: PowerVC_Server -> 前の記事で導入した PowerVC 2.0 サーバー(OS RHEL 8.3)


準備

①ssh鍵交換

1) Local Mac PC で ssh-keygen コマンド で ssh key を作成
2) PowerVC_Server に public key を転送
3) PowerVC_Server の /root/.ssh/authorized_keys を作成し、2) で転送した pubic key を追記


②ssh の configファイルの設定
Local Mac の /.ssh/config に以下の設定する

  Host PowerVC_Server
  HostName xx.xx.xx.xx
  User root
  IdentityFile ~/.ssh/id_rsa          #<= ①で作成した secret keyを指定

これでパスワード入力なしで Local Mac PC と PowerVC_Server が ssh 接続できるようになりました。


③サンプル・モジュールをダウンロードする
https://github.com/ppc64le/devops-automation/tree/master/ansible/powervc

ダウンロードしたモジュールを移動し、配置した場所を ansible 実行ディレクトリとしています。


④inventory の設定

invenrory ファイルを以下のように設定します。

[test]
PowerVC_Server ansible_python_interpreter=/usr/bin/python3

⑤ansible.cfg の設定

ansible.cfg
[defaults]
inventory = ./inventory
interpreter_python=/usr/bin/python
remote_user = root
[inventory]

interpreter_python=/usr/bin/python

⑥ PowerVC_Server から /opt/ibm/powervc/powervcrc と/etc/pki/tls/certs/powervc.crt をAnsible 実行サーバーである Local Mac PC に取得し、実行ディレクトリに配置します。

powervcrc 内の powervc.crt の指定を配置場所に変更します。

$ cat powervcrc
# Copy this file to your user's home directory and edit as necessary.
# In particular, you may wish to set these values:
#    - OS_USERNAME     : Your PowerVC user name
#    - OS_PASSWORD     : Your PowerVC password. If not set, openstack CLIs
#                        will prompt for the password as needed.
#    - OS_PROJECT_NAME : If you have multiple projects, specify which project
#                        you want to access; else you can leave this as
#                        ibm-default.
#
# NOTE: You should not add your password to this file until/unless its file
# permissions prevent other users from reading it. This is one reason to copy
# the file to your home directory and edit it there. Or you may wish to not
# add your password at all and have the CLI prompt you, as noted above.

export OS_IDENTITY_API_VERSION=3
export OS_AUTH_URL=https://xx.xx.xx.xx:5000/v3/
export OS_CACERT=./powervc.crt                   #<= 配置場所に記載変更
export OS_REGION_NAME=RegionOne
export OS_PROJECT_DOMAIN_NAME=Default
export OS_PROJECT_NAME=ibm-default
export OS_TENANT_NAME=$OS_PROJECT_NAME
export OS_USER_DOMAIN_NAME=Default
#export OS_USERNAME=
#export OS_PASSWORD=
export OS_COMPUTE_API_VERSION=2.46
export OS_NETWORK_API_VERSION=2.0
export OS_IMAGE_API_VERSION=2
export OS_VOLUME_API_VERSION=3

稼働検証

実行ディレクトリに配置しているファイルのご参考

$ ls -l
-rw-r--r--  1 user  staff   205 Dec 17 15:03 ansible.cfg
-rw-r--r--  1 user  staff  1154 Sep 18 23:22 create_vm.yml
-rw-r--r--  1 user  staff   469 Sep 16 17:27 imagelist.yml
-rw-r--r--  1 user  staff    58 Dec 17 16:09 inventory
-rw-r--r--  1 user  staff   451 Sep 18 23:22 list_flavors.yml
-rw-r--r--  1 user  staff   468 Sep 18 23:22 list_images.yml
-rw-r--r--  1 user  staff   246 Sep 18 23:21 list_network.yml
-rw-r--r--  1 user  staff    60 Sep 16 16:14 openstack.yml
-rw-r--r--  1 user  staff  1192 Dec 12 09:52 powervc.crt
-r--r--r--  1 user  staff  1267 Dec 17 14:55 powervcrc
-rw-r--r--  1 user  staff   135 Sep 27 21:44 service.yml

① 環境変数の設定

$ source powervcrc
$ export OS_USERNAME=root
$ export OS_PASSWORD= "PowerVC_Serverの PowerVC 実行ユーザー password"

② 疎通確認

ping モジュールを実行します。

$ ansible test -m ping
PowerVC_Server | SUCCESS => {
    "changed": false,
    "ping": "pong"
}

-> Ansibleサーバー(Local Mac PC) と PowerVC_Server が疎通しました^^

③ モジュール確認

サンプル・ファイルlist_falvors.yml を実行してみます。

---
- name: List available PowerVC Flavors
  hosts: localhost
  tasks:
    - name: Retrieve list of all public flavors
      os_flavor_info:
        vcpus: ">=4"   # Optional filters
        ram: ">16000"  # See module docs for more options
      register: result

    - name: Print flavor list
      debug:
        msg: "{{ result | json_query('openstack_flavors[?is_public==`true`].
              {name: name, id: id, ram: ram, vcpus: vcpus}') }}"

"vcpus" が 4 以上、RAM 16000 以上を result として表示します。

$ ansible-playbook list_flavors.yml

PLAY [List available PowerVC Flavors] ********************************************************************************************

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

TASK [Retrieve list of all public flavors] ***************************************************************************************
ok: [localhost]

TASK [Print flavor list] *********************************************************************************************************
ok: [localhost] => {
    "msg": [
        {
            "id": "xxxxx8ba-xxxx-4162-9ccd-xxxxxxxxxxx ",
            "name": "large",
            "ram": 32768,
            "vcpus": 8
        },
        {
            "id": "xxxxx8bb-e759-xxxx-a341-xxxxxxxxxxx ",
            "name": "xlarge",
            "ram": 65536,
            "vcpus": 16
        },
        {
            "id": "xxxxxace-xxxx-43c8-9292-xxxxxxxxxxx ",
            "name": "medium",
            "ram": 16384,
            "vcpus": 4
        },
        {
            "id": "xxxxxb-460e-xxxx-9c9a-xxxxxxxxxxx ",
            "name": "xxlarge",
            "ram": 131072,
            "vcpus": 32
        }
    ]
}

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

-> 結果が返ってきました。
vcpu >=4, RAM >= 16000 です。


PowerVC_Server 上で、openstack コマンドで flavor を確認します。

PowerVC でのOpenStack操作は、AIX 技術情報にある資料 PowerVC_OpenStack command Hint & Tips をご参考ください。

flavor list 確認

[root@PowerVC_Server]# cd /opt/ibm/powervc
[root@PowerVC_Server]# source powervcrc
[root@PowerVC_Server]# export OS_USERNAME=root
[root@PowerVC_Server]# export OS_PASSWORD="PowerVC_Serverの PowerVC 実行ユーザー password"

[root@PowerVC_Server]# openstack flavor list
+-------------------------------------+---------+--------+------+-----------+-------+-----------+
| ID                                  | Name    |    RAM | Disk | Ephemeral | VCPUs | Is Public |
+-------------------------------------+---------+--------+------+-----------+-------+-----------+
| xxxxxxx-xxxx-xxx2-9ccd-6dxxxxxxxxx  | large   |  32768 |    0 |         0 |     8 | True      |
| xxxxxxx-9a1d-xxxe-a69d-xxxxxxxxxxx  | tiny    |   4096 |    0 |         0 |     1 | True      |
| xxxxxxx-xxxx-xxx7-a341-xxxxxxxxxxx  | xlarge  |  65536 |    0 |         0 |    16 | True      |
| 74913ace-xxxx-xxx8-9292-xxxxxxxxxx  | medium  |  16384 |    0 |         0 |     4 | True      |
| xxxxxxxxx-d434-xxxf-8d6d-xxxxxxxxx  | small   |   8192 |    0 |         0 |     2 | True      |
| xxxxxxx-xxxx-xxxf-9c9a-xxxxxxxxxxx  | xxlarge | 131072 |    0 |         0 |    32 | True      |
+-------------------------------------+---------+--------+------+-----------+-------+-----------+
[root@PowerVC_Server]#

vcpu < 4, RAM < 16000 である tiny、small も存在していることが確認できます。


終わりに

Ansible の OpenStack Pluginを利用してPowerVC で サンプル・ファイル list_flavors.yml を実行しました。

今回は list_flavors.yml のみ確認でしたが、いずれプロビジョニングも検証できればと思います。

以上です。

1
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
1
0