[英]I am having some issue while creating VM from ansible
我正在使用 Ansible 版本 2。 2.9.9 和 Python 版本 3.6.9; 而且我也安装了请求模块,但是每次运行我的代码时,都会出现 Mo 模块名称请求的错误,我也将 ansible_pythin_interpreter 更改为 python 3 但它并没有帮助我。 请通过我的代码 go 并在这里帮助我。
Traceback (most recent call last):
File "/tmp/ansible_vmware_guest_payload_evshxlga/ansible_vmware_guest_payload.zip/ansible/module_utils/vmware.py", line 24, in <module>
import requests
ImportError: No module named 'requests'
"msg": "Failed to import the required Python library (requests) on Python /user/bin/python. 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"
- hosts: vm
# tasks:
#connection: local
#gather_facts: no
vars_prompt:
- name: myuser
prompt: Enter the UserName
private: no
- name: mypass
prompt: Enter the Password
- name: vc_name
prompt: Enter the vCenter/ESXi HostName
private: no
- name: guest_name
prompt: Enter the Guest VM Name
private: no
- name: hdd
prompt: Enter the HardDrive Space you want to use
private: no
- name: ram
prompt: Enter the RAM in MB
private: no
- name: cpu
prompt: Enter the number of processor you want to use
private: no
- name: ip_addr
prompt: Enter the Ip address you want to specify
private: no
- name: os_system
private: no
prompt: |
Which os do you want to use?
1- Windows Server
2- CentOS_7
3- CentOs_8
4- Ubuntu
5- Others
tasks:
set_fact: os_system == "Win server 2012.iso"
when: (os_system == "1")
set_fact: os_system == "CentOS-7-x86_64-Minimal-1804.iso"
when: (os_systen == "2")
set_fact: os_system == "CentOS-8-x86_64-1905-dvd1.iso"
when: (os_system == "3")
set_fact : os_system == "ubuntu-16.04.6-server-amd64.iso"
when: (os_system == "4")
remote_user: root
tasks:
# - name: Create a VM
delegate_to: localhost
- vmware_guest:
hostname: "{{ vc_name }}"
username: "{{ myuser }}"
password: "{{ mypass }}"
validate_certs: no
folder: /DC1/vm/
name: "{{guest_name}}"
state: poweredon
guest_id: "{{guest_name}}"
# This is hostname of particular ESXi server on which user wants VM to be deployed
esxi_hostname: "{{ vc_name }}"
disk:
- size_gb: "{{hdd}}"
type: thin
datastore: datastore1
hardware:
memory_mb: "{{ram}}"
num_cpus: "{{cpu}}"
scsi: paravirtual
networks:
- name: VM Network
# mac: aa:bb:dd:aa:00:14
ip: "{{ip_addr}}"
netmask: 255.255.255.0
device_type: vmnic0
wait_for_ip_address: yes
cdrom:
type: iso
iso_path: "vmfs/volumes/datastore1/Iso/{{os_system}}"
您必须安装请求库。 您只需在 CMD 或终端中输入此命令即可安装它。
pip install requests
它将修复ImportError: No module named 'requests'
这个问题已经解决,我在我的剧本中添加了 delegate_to: localhost 并解决了 Import Error: Request Module failed 的问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.