fengjian
作者fengjian2022-03-25 15:41
系统工程师, ips

使用Ansible HMC module创建和启停K1 Power分区

字数 3994阅读 2058评论 0赞 0

Ansible 是 Red Hat 赞助的一个开源社区项目,是实现 IT 自动化运维的最简单的方法,同时也是一种可以从系统运维人员到开发人员的跨整个 IT 团队使用的自动化语言。通过使用 Ansible 的自动化能力,能为系统管理员节省宝贵的时间,减轻运维负担的同时也降低了运维风险。目前, Ansible 已完全支持 K1 Power ,红帽在其官网及开源社区都发布了针对 K1 Power 平台的 Ansible 套件,包括可用于 AIX 、 IBM i 、 VIOS 、 HMC 的各种模块,

Ansible HMC collection 中的 powervm_lpar_instance 模块可以用来管理 K1 Power 的分区,包括启停、创建、删除、查看分区信息。以下是针对 HMC 的 powervm_lpar_instance 模块的测试。

注意使用该模块需要在 Ansible 管理节点安装 python3 和 lxml 。

测试示例如下:

1.安装 Ansible 、 python3 和 lxml

powervm_lpar_instance 模块需要使用 python3 和 lxml ,必须安装

2.使用 ansible-galaxy 安装 Ansible HMC collection

安装前查看 COLLECTIONS_PATHS

ansible-config dump | grep collections

COLLECTIONS_PATHS(default) = ['/.ansible/collections', '/usr/share/ansible/collections']

ansible-galaxy 默认使用第一路径,如果要安装到后面的目录,使用 -p 参数设置,安装命令如下

ansible-galaxy collection install --force ibm.power_hmc

Process install dependency map
Starting collection install process
Installing 'ibm.power_hmc:1.4.0' to '/.ansible/collections/ansible_collections/ibm/power_hmc'

当前 collection 版本 1.4.0 ,安装目录为 /.ansible/collections/ansible_collections/ibm/power_hmc

3.准备 playbook ,分别实现分区启停、创建分区、删除分区功能

使用 powervm_lpar_instance 启停分区,代码如下:

- hosts: 
  - localhost

  tasks:
  - name: Partition Management
    ibm.power_hmc.powervm_lpar_instance:
      hmc_host: '172.16.100.23'
      hmc_auth:
         username: hscroot
         password: ********
      system_name: Power-S924-11-SN7874C30
      vm_name: rhel76_vmr-2e
      action: "{{ ACTION }}"

  - name: GET Partition Status
    ibm.power_hmc.powervm_lpar_instance:
      hmc_host: '172.16.100.23'
      hmc_auth:
         username: hscroot
         password: ********
      system_name: Power-S924-11-SN7874C30
      vm_name: rhel76_vmr-2e
      state: facts
    register: lpar_status

  - name: Print Partition State 
    debug: msg="Partition State is {{ lpar_status.partition_info.PartitionState }}"

启动分区执行结果:

ansible-playbook -e 'ACTION="poweron"' ./hmc_lpar.yml


关闭分区执行结果:

ansible-playbook -e 'ACTION="shutdown"' ./hmc_lpar.yml


使用 powervm_lpar_instance 创建分区,代码如下:

- hosts: 
  - localhost
  gather_facts: no

  tasks:
  - name: Create an AIX/Linux logical partition 
    ibm.power_hmc.powervm_lpar_instance:
      hmc_host: '172.16.100.23'
      hmc_auth:
         username: hscroot
         password: ********
      system_name: Power-S924-11-SN7874C30
      vm_name: ansible_create_lpar
      volume_config:
         - vios_name: VIOS924a
           volume_name: hdisk5
         - vios_name: VIOS924b
           volume_name: hdisk5
      virt_network_config:
         - network_name: sea
      npiv_config:
         - vios_name: VIOS924a
           fc_port: fcs0
         - vios_name: VIOS924b
           fc_port: fcs0
      os_type: aix_linux
      state: present

  - name: GET Partition Status
    ibm.power_hmc.powervm_lpar_instance:
      hmc_host: '172.16.100.23'
      hmc_auth:
         username: hscroot
         password: ********
      system_name: Power-S924-11-SN7874C30
      vm_name: ansible_create_lpar
      state: facts
    register: lpar_status

  - name: Print Partition State 
    debug: msg="{{ lpar_status.partition_info }}"

说明:双 vios , rootvg 使用 vscsi, 分别从两个 vios 中 mapping ,同时创建 npiv 。VIOS 分区的名称大小写敏感,需要注意。

执行结果:

ansible-playbook ./hmc_create_lpar.yml


使用 powervm_lpar_instance 删除分区,代码如下:

- hosts: 
  - localhost

  tasks:
  - name: delete an AIX/Linux logical partition 
    ibm.power_hmc.powervm_lpar_instance:
      hmc_host: '172.16.100.23'
      hmc_auth:
         username: hscroot
         password: ********
      system_name: Power-S924-11-SN7874C30
      vm_name: ansible_create_lpar
      state: absent

  - name: GET Partition Status
    ibm.power_hmc.powervm_lpar_instance:
      hmc_host: '172.16.100.23'
      hmc_auth:
         username: hscroot
         password: ********
      system_name: Power-S924-11-SN7874C30
      vm_name: ansible_create_lpar
      state: facts
    register: lpar_status

  - name: Print Partition State 
    debug: msg="{{ lpar_status.partition_info }}"

执行结果:

ansible-playbook ./hmc_del_lpar.yml

如果觉得我的文章对您有用,请点赞。您的支持将鼓励我继续创作!

0

添加新评论0 条评论

Ctrl+Enter 发表

作者其他文章

相关文章

相关问题

相关资料

X社区推广