skip to Main Content

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.

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"

I have uploaded my code as well

- 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}}"  

2

Answers


  1. Chosen as BEST ANSWER

    this issue has been solved, I added delegate_to: localhost to my playbook and it solved the issue of Import Error : Request Module failed


  2. You have to install requests library. You can install it by just entering this command in CMD or Terminal.

    pip install requests
    

    It will fix ImportError: No module named 'requests'

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search