使用 Ansible 将 RAM 和 CPU 添加到 VMWare 虚拟机不起作用

问题描述 投票:0回答:1

我使用ansible在VMWare上部署虚拟机,我可以部署/删除虚拟机并添加/调整现有磁盘的大小。但我无法添加RAM和CPU,我尝试了下面的两种方法,但出现错误。

第一种方法:

---
- block:
  - name: Set common parameters
    set_fact:
      common_params:
        vcenter_hostname: '{{ vcenter_hostname }}'
        vcenter_password: '{{ vcenter_pass }}'
        vcenter_username: '{{ vcenter_user }}'
        vcenter_validate_certs: false

  - name: Look up the VM called test_vm1 in the inventory  
    vmware.vmware_rest.vcenter_vm_info:      
      filter_names: "{{ hostname }}"      
      vars: "{{ common_params }}"
    register: search_result 

  - name: Collect information about a specific VM
    vmware.vmware_rest.vcenter_vm_info:
      vm: '{{ search_result.value[0].vm }}'
      vars: "{{ common_params }}"
    register: hostname_info

  - name: Increase the memory of a VM
    vmware.vmware_rest.vcenter_vm_hardware_memory:
      vm: '{{ hostname_info.id }}'
      size_MiB: "{{ ram-new-size}}"
      hot_add_enabled: true
      vars: "{{ common_params }}"
    register: _result

  - name: Dedicate one core to the VM
    vmware.vmware_rest.vcenter_vm_hardware_cpu:
      vm: '{{ hostname_info.id }}'
      count: "{{ new-nb-cpu }}"
      hot_add_enabled: true
      vars: "{{ common_params }}"    
    register: _result 

  delegate_to: localhost
  ignore_errors: true

我遇到了这个错误:

 "msg": "Failed to import the required Python library (aiohttp) on serverbdd's Python /usr/bin/python3. Please read the module documentation and install it in the appropriate location. If the required library is installed, but Ansible is using the wrong Python interpreter, please consult the documentation on ansible_python_interpreter"

第二种方法:

- name: Deploy VM from template
  vmware_guest:
    hostname: '{{ vcenter_hostname }}'
    username: '{{ vcenter_user }}'
    password: '{{ vcenter_pass }}'
    validate_certs: no
    datacenter: '{{ vcenter_datacenter }}'
    name: '{{ inventory_hostname }}'
    state: "poweredon"
    validate_certs: no
    folder: '{{ vcenter_folder }}'
    hardware:
      memory_mb: '{{ guest_memory }}'
      num_cpus: '{{ guest_vcpu }}'
  delegate_to: localhost

我通过 Jenkins 管道运行我的剧本。 您看到我的代码中有任何错误吗?或者我应该使用另一个 VMWare 模块? 先谢谢你了

jenkins ansible vmware
1个回答
0
投票

根据错误信息

Failed to import the required Python library (aiohttp)

vcenter_vm_hardware_memory
模块 – 更新虚拟机的内存相关设置文档和 要求

执行此模块的主机需要以下要求。

aiohttp


您似乎尚未在运行时/执行环境中安装它,例如通过

pip install aiohttp

© www.soinside.com 2019 - 2024. All rights reserved.