jenkins 使用Ansible将RAM和CPU添加到VMWare VM不起作用

f45qwnt8  于 2023-10-17  发布在  Jenkins
关注(0)|答案(1)|浏览(99)

我用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模块?提前感谢您

e37o9pze

e37o9pze1#

根据错误信息

  • Failed to import the required Python library (aiohttp)*

以及vcenter_vm_hardware_memory module – Updates the memory-related settings of a virtual machine文档和要求

  • 执行此模块的主机需要满足以下要求。*
  • aiohttp*

看起来你还没有在你的运行时/执行环境中安装它,例如通过pip install aiohttp

相关问题