IBM Cloud PowerSystems Virtual Server를 Ansible(galaxy: ibm.cloudcollection)로 배포

ansible-falaxy ibm.cloudcollection을 사용하여 Ansible에서 PowerVirtualServer(AIX)를 배치한 실행 로그입니다.

다음 코드를 참조합니다.
htps : // 기주 b. 이 m / BM-C ぉ d / 안시 b ぇ - ぇ c 치 온 - bm / t ree / vs

실행 환경



Amsible Host: Local PC (Mac)
Ansible version : 2.9.9
파이썬 : 3.8.3

배포 대상 환경



IBM Cloud PowerVirtualServer 서비스

playbook 작성을 위한 준비



· ssh public key를 작성하십시오.

· Public Network 사전 정의 (CLI or GUI)
  (* playbook 내에서의 작성도 가능했습니다만, 시간이 걸려 timeout error 가 발생했기 때문에,
 사전 정의로 변경했습니다. )

참고:
· IBM Power Systems Virtual Servers CLI 플러그인

· ibmcloud pi network-create-public 명령

실행



시나리오 : AIX를 배포하고 ansible로 ssh 연결

1) 실행 환경에서 ansible-galaxy ibm.cloudcollection 설치
$ ansible-galaxy collection install ibm.cloudcollection
Process install dependency map
Starting collection install process
Installing 'ibm.cloudcollection:1.13.1' to '/Users/test/.ansible/collections/ansible_collections/ibm/cloudcollection'

2) power_instance_id 사전 취득 (IBM Cloud 대상 계정에 CLI 로그인 후 ibmcloud pi sl 실행)
$ ibmcloud pi service-list
Listing services under account IBM - <USER ACCOUNT>  as user <login user> ..
ID                                                                                                                    Name
crn:v1:bluemix:public:power-iaas:us-south:a/52xxxxx0f3a4109ac0dxxx44xxxx6:<power_instance_id>   <Service Name>

"power_instance_id"의 ​​위치를 ​​메모에 둡니다.

・참고: ibmcloud pi service-list 명령

3) Public 네트워크의 ID 취득(ibmcloud pi networks)
$ ibmcloud pi networks
Listing networks under account IBM - ACCOUNT NAME as user test...
ID                                     Name                       Address
xxxx-39da-xxxx-84a1-xxxxx   demo-power-vm001-network   /pcloud/v1/cloud-instances/axxxfb6b4xxxx2b62xxxc3/networks/1fxxxxxxa-xxx45-84a1-xxxxd8f4xxx

ID 열의 값을 메모에 둔다.

4) 사용할 이미지의 ID 얻기(ibmcloud pi images 실행)
$ ibmcloud pi images | grep 7200-04-01
xxxxxxxx-cxxc-4xxb-xx4e-7e4xxxxxx   7200-04-01                       /pcloud/v1/cloud-instances/adxxxxxxxx6b4xxxxx000a2xxxxx3/images/dxxxxx49-xx5c-xxxxx-xx4e-7exxxxx

좌단의 값을 메모에 삼킨다.

5) 실행할 playbook 준비 (create_vm.yml)

create_vm.yml
---
- name: POWER VSI Creation Demo
  hosts: localhost
  collections:
   - ibm.cloudcollection
  vars:
    pi_name: demo-power-vm001                       #VM名
    sys_type: e880                      #サーバー・タイプ
    pi_image_id: "xxxxxxxx-cxxc-4xxb-xx4e-7e4xxxxxx"         # 4)で確認したimage idを記載
    proc_type: shared               # プロセッサー・タイプ
    processors: "0.2"           # CPU
    memory: "2"                         # Memory(GB)
    pi_cloud_instance_id: "ef5xxxx-0e8c-42xxx7-81xxx-45b96xxxxfd"  # 2)で確認したpower_instance_idを記載
    ssh_public_key: "<ssh key public key の文字列>"
    pi_network_id: "xxxx-39da-xxxx-84a1-xxxxx"   # 3)で確認したpublic networkの idを記載

  tasks:
    - name: Add new SSH Key
      ibm_pi_key:
        pi_key_name: "{{ pi_name }}-ssh-key"
        pi_ssh_key: "{{ ssh_public_key }}"
        pi_cloud_instance_id: "{{ pi_cloud_instance_id }}"
      register: pi_ssh_key_create_output

    - name: Create a POWER Virtual Server Instance
      ibm_pi_instance:
        state: available
        pi_memory: "{{ memory }}"
        pi_processors: "{{ processors }}"
        pi_instance_name: "{{ pi_name }}"
        pi_proc_type: "{{ proc_type }}"
        pi_image_id: "{{ pi_image_id }}"
        pi_volume_ids: []
        pi_network_ids: "{{ pi_network_id }}"
        pi_key_pair_name: "{{ pi_name }}-ssh-key"
        pi_sys_type: "{{ sys_type }}"
        pi_replication_policy: none
        pi_replication_scheme: suffix
        pi_replicants: "1"
        pi_cloud_instance_id: "{{ pi_cloud_instance_id }}"
        id: "{{ pi_instance.resource.id | default(omit) }}"
      register: pi_instance_create_output

    - name: Save new Power VSI fact
      set_fact:
        cacheable: True
        pi_instance: "{{ pi_instance_create_output.resource }}"
      when: pi_instance_create_output.resource is defined

    - name: Print Public IP Address
      debug:
        var: pi_instance.addresses[0].external_ip

    - name: Add VSI to Ansible inventory
      add_host:
        name: "{{ pi_instance.addresses[0].external_ip }}"
        ansible_user: root
        groups: new_vsi
        ansible_ssh_extra_args: -o StrictHostKeyChecking=no

- name: Connect to VSI
  hosts: new_vsi
  gather_facts: False
  tasks:
    - name: Wait for VSI to become reachable over SSH
      wait_for_connection:

    - name: Collect OS login message
      command: cat /etc/motd
      register: os_motd

    - name: Print MOTD
      debug:
        var: os_motd.stdout_lines

6) ansible.cfg 준비

ansible.cfg
[default]
remote_user = root
private_key_file = ./id_rsa_demo_vm001    # デプロイするVMに登録した ssh-key のprivate key を指定

7) 실행 환경에서 IC_API_KEY export

IBM Cloud API Key 작성 참고: API 키 작성
h tps : // c ぉ d. 이 bm. 코 m/도 cs/아코응 t? 토피 c = 아코 톤 t 우세라 피케 y & ぉ 카 ぇ = 그럼 # c 레테 _ 우세 r_ 케 y

Ansible 실행 환경의 터미널에서 IC_API_KEY 변수를 export합니다.
export IC_API_KEY=<API KEY>

(* API KEY 부분은 실제 값으로 바뀝니다)

8) 배포 실행
$ ansible-playbook create_vm.yml
[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 Creation Demo] ***************************************************************************************************

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

TASK [Add new SSH Key] ***********************************************************************************************************
changed: [localhost]

TASK [Create a POWER Virtual Server Instance] ************************************************************************************
changed: [localhost]

TASK [Save new Power VSI fact] ***************************************************************************************************
ok: [localhost]

TASK [Print Public IP Address] ***************************************************************************************************
ok: [localhost] => {
    "pi_instance.addresses[0].external_ip": "XXX.XXX.XX.XXX"
}

TASK [Add VSI to Ansible inventory] **********************************************************************************************
changed: [localhost]

PLAY [Connect to VSI] ************************************************************************************************************

TASK [Wait for VSI to become reachable over SSH] *********************************************************************************
ok: [XXX.XXX.XX.XXX]

TASK [Collect OS login message] **************************************************************************************************
[WARNING]: Platform aix on host XXX.XXX.XX.XXX is using the discovered Python interpreter at /usr/bin/python, but future
installation of another Python interpreter could change this. See
https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more information.
changed: [XXX.XXX.XX.XXX]

TASK [Print MOTD] ****************************************************************************************************************
ok: [XXX.XXX.XX.XXX] => {
    "os_motd.stdout_lines": [
        "*******************************************************************************",
        "*                                                                             *",
        "*                                                                             *",
        "*  Welcome to AIX Version 7.2!                                                *",
        "*                                                                             *",
        "*                                                                             *",
        "*  Please see the README file in /usr/lpp/bos for information pertinent to    *",
        "*  this release of the AIX Operating System.                                  *",
        "*                                                                             *",
        "*                                                                             *",
        "*******************************************************************************"
    ]
}

PLAY RECAP ***********************************************************************************************************************
XXX.XXX.XX.XXX             : ok=3    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
localhost                  : ok=6    changed=3    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

성공했습니다!

9) GUI로 확인
· ssh_key가 등록되었습니다.


· VM이 생성되었습니다.


요약



Ansible Collection ibm.cloudcollection에서 PowerVirtualServer를 배포할 수 있음을 확인했습니다.
Ansible 변수(이미지 등)를 변경하면 IBM i 및 Linux도 배치할 수 있습니다.

이번에 시도하지 않은 private 네트워크 생성, 연결, 볼륨 생성, 연결 및 AIX에 대한 ansible 구성 변경은 향후 숙제입니다.

관련 문서: ibmcloud CLI에서 IBM PowerSystems Virtual Server on IBM Cloud 서비스에 AIX 서버 배치

이상.

좋은 웹페이지 즐겨찾기