I am using Ansible version2. 2.9.9 and Python version 3.6.9; and I have installed requests modules too but every time I run my code I ger error of Mo Module name requests, I have changed the ansible_pythin_interpreter to python 3 as well but it didn’t heled me. Please go through my code and help me here.
JavaScript
x
7
1
Traceback (most recent call last):
2
File "/tmp/ansible_vmware_guest_payload_evshxlga/ansible_vmware_guest_payload.zip/ansible/module_utils/vmware.py", line 24, in <module>
3
import requests
4
ImportError: No module named 'requests'
5
6
"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"
7
I have uploaded my code as well
JavaScript
1
84
84
1
- hosts: vm
2
# tasks:
3
#connection: local
4
#gather_facts: no
5
vars_prompt:
6
- name: myuser
7
prompt: Enter the UserName
8
private: no
9
- name: mypass
10
prompt: Enter the Password
11
- name: vc_name
12
prompt: Enter the vCenter/ESXi HostName
13
private: no
14
- name: guest_name
15
prompt: Enter the Guest VM Name
16
private: no
17
- name: hdd
18
prompt: Enter the HardDrive Space you want to use
19
private: no
20
- name: ram
21
prompt: Enter the RAM in MB
22
private: no
23
- name: cpu
24
prompt: Enter the number of processor you want to use
25
private: no
26
- name: ip_addr
27
prompt: Enter the Ip address you want to specify
28
private: no
29
- name: os_system
30
private: no
31
prompt: |
32
Which os do you want to use?
33
1- Windows Server
34
2- CentOS_7
35
3- CentOs_8
36
4- Ubuntu
37
5- Others
38
tasks:
39
set_fact: os_system == "Win server 2012.iso"
40
when: (os_system == "1")
41
set_fact: os_system == "CentOS-7-x86_64-Minimal-1804.iso"
42
when: (os_systen == "2")
43
set_fact: os_system == "CentOS-8-x86_64-1905-dvd1.iso"
44
when: (os_system == "3")
45
set_fact : os_system == "ubuntu-16.04.6-server-amd64.iso"
46
when: (os_system == "4")
47
48
49
remote_user: root
50
51
tasks:
52
# - name: Create a VM
53
delegate_to: localhost
54
55
- vmware_guest:
56
hostname: "{{ vc_name }}"
57
username: "{{ myuser }}"
58
password: "{{ mypass }}"
59
validate_certs: no
60
folder: /DC1/vm/
61
name: "{{guest_name}}"
62
state: poweredon
63
guest_id: "{{guest_name}}"
64
# This is hostname of particular ESXi server on which user wants VM to be deployed
65
esxi_hostname: "{{ vc_name }}"
66
disk:
67
- size_gb: "{{hdd}}"
68
type: thin
69
datastore: datastore1
70
hardware:
71
memory_mb: "{{ram}}"
72
num_cpus: "{{cpu}}"
73
scsi: paravirtual
74
networks:
75
- name: VM Network
76
# mac: aa:bb:dd:aa:00:14
77
ip: "{{ip_addr}}"
78
netmask: 255.255.255.0
79
device_type: vmnic0
80
wait_for_ip_address: yes
81
cdrom:
82
type: iso
83
iso_path: "vmfs/volumes/datastore1/Iso/{{os_system}}"
84
Advertisement
Answer
You have to install requests library. You can install it by just entering this command in CMD or Terminal.
JavaScript
1
2
1
pip install requests
2
It will fix ImportError: No module named 'requests'