2016-08-03 73 views
1

我想通過Ansible在我的ESXi主機上部署VM。 我使用下面的角色是:麻煩pysphere - 能夠

- vsphere_guest: 
    vcenter_hostname: emea-esx-s18t.****.net 
    username: **** 
    password: **** 
    guest: newvm001 
    state: powered_off 
    vm_extra_config: 
     vcpu.hotadd: yes 
     mem.hotadd: yes 
     notes: This is a test VM 
    vm_disk: 
     disk1: 
     size_gb: 10 
     type: thin 
     datastore: **** 
    vm_nic: 
     nic1: 
     type: vmxnet3 
     network: VM Network 
     network_type: standard 
    vm_hardware: 
     memory_mb: 4096 
     num_cpus: 4 
     osid: windows7Server64Guest 
     scsi: paravirtual 
    esxi: 
     datacenter: MyDatacenter 
     hostname: esx-s18t.****.net 

當我通過一個劇本,我得到下面的消息現在執行這個角色:

[email protected]:~/ansible# ansible-playbook -i Inventory vmware_deploy.yml 

PLAY *************************************************************************** 

TASK [setup] ******************************************************************* 
ok: [172.20.22.5] 

TASK [vmware : vsphere_guest] ************************************************** 
fatal: [172.20.22.5]: FAILED! => {"changed": false, "failed": true, "msg": "pysphere module required"} 

PLAY RECAP ********************************************************************* 
172.20.22.5    : ok=1 changed=0 unreachable=0 failed=1 

所以它似乎是「pysphere」模塊缺失。我已經檢查了用命令:

[email protected]:~/ansible# pip install pysphere 
Requirement already satisfied (use --upgrade to upgrade): pysphere in /usr/local/lib/python2.7/dist-packages/pysphere-0       .1.7-py2.7.egg 

然後我做了「升級」,並收到以下消息回:

[email protected]:~/ansible# pip install pysphere --upgrade 
Requirement already up-to-date: pysphere in /usr/local/lib/python2.7/dist-packages/pysphere-0.1.7-py2.7.egg 

所以它似乎是它已經被安裝並且其高達到目前爲止,爲什麼我會收到此錯誤消息呢? 我該如何解決它,我的上帝該死的角色現在正常工作? 耶穌,Ansible讓我發瘋..

我希望你們可以幫助我,在此先感謝!

親切的問候, kgierman

編輯: 所以我writen一個新劇本與舊的東西,新的playbool lookes像這樣(我已經添加了本地主機和連接本地的東西):

--- 
- hosts: localhost 
    connection: local 
    tasks: 
    vsphere_guest: 
     vcenter_hostname: emea-esx-s18t.****.net 
      username: **** 
      password: **** 
      guest: newvm001 
      state: powered_off 
     vm_extra_config: 
      vcpu.hotadd: yes 
      mem.hotadd: yes 
      notes: This is a test VM 
     vm_disk: 
      disk1: 
      size_gb: 10 
      type: thin 
      datastore: **** 
     vm_nic: 
      nic1: 
      type: vmxnet3 
      network: VM Network 
      network_type: standard 
     vm_hardware: 
      memory_mb: 4096 
      num_cpus: 4 
      osid: windows7Server64Guest 
      scsi: paravirtual 
     esxi: 
      datacenter: MyDatacenter 
      hostname: esx-s18t.****.net 

所以,當我執行這個劇本我得到以下錯誤:

[email protected]:~/ansible# ansible-playbook vmware2.yml 
ERROR! Syntax Error while loading YAML. 


The error appears to have been in '/root/ansible/vmware2.yml': line 7, column 19, but may 
be elsewhere in the file depending on the exact syntax problem. 

The offending line appears to be: 

     vcenter_hostname: emea-esx-s18t.sddc-hwl-family.net 
      username: root 
       ^here 

的鬥爭是真實-.-

回答

0

您通常應該在本地計算機上執行配置模塊,例如vsphere_guest
我懷疑172.20.22.5實際上是你的ESX主機,並且有理由嘗試從那裏執行模塊,pysphere肯定不存在。
用途:

- hosts: localhost 
    tasks: 
    - vsphere_guest: 
     ... 
+0

沒錯ypu're權,172.20.22.5是ESXi主機,但如果我想部署一個虛擬機有(事業存在的vCenter和東西) - 但在ESXi操作系統Ubuntu是另一回事,那麼我怎麼能通過VSphere上的Ansible創建一個虛擬機呢? –

+0

您可以將其指定爲'vcenter_hostname'參數 - 可負責的模塊將從本地主機連接到它並創建請求的虛擬機。 –

+0

對不起,我不明白你的意思是:/ 「你指定它爲vcenter_hostname參數」,你能給我一個例子嗎? –

0

就遇到了這個問題再次在MacOS/OSX ... 這似乎是有關PYTHONPATH

我有這個在我的.profile

export PYTHONPATH="/usr/local/lib/python2.7/site-packages" 

[ ... further down ... ] 

export PYTHONPATH="/usr/local/Cellar/ansible/2.1.2.0/libexec/lib/python2.7/site-packages:/usr/local/Cellar/ansible/2.2.1.0/libexec/vendor/lib/python2.7/site-packages:$PYTHONPATH" 

PYTHONPATH第一行就是pysphere和其他系統模塊駐留。
也請注意Ansible的特定版本
無論如何,這似乎解決了這個問題。

來源:https://github.com/debops/debops-tools/issues/159#issuecomment-236536195