pysphere的问题 - ansible

时间:2016-08-03 07:18:00

标签: module automation ansible vmware

我正在尝试通过Ansible在我的ESXi主机上部署VM。 我正在使用以下角色:

- 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

当我现在通过剧本执行此角色时,我收到以下消息:

root@ansible1:~/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”模块缺失了。我已经用命令检查了它:

root@ansible1:~/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

然后我做了“升级”并收到以下消息:

root@ansible1:~/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

所以它似乎已经安装并且它是最新的,为什么我会收到此错误信息呢? 我怎么能解决它,我该死的角色现在工作得很好? 耶稣,安西斯让我发疯..

我希望你们能帮助我,提前谢谢!

亲切的问候, kgierman

编辑: 所以我用旧的东西写了一个新的剧本,新的playbool看起来像这样(我添加了你的localhost和连接本地的东西):

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

所以当我执行这个剧本时,我得到以下错误:

root@ansible1:~/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
斗争是真实的 - .-

2 个答案:

答案 0 :(得分:0)

您通常应该在本地ansible机器上执行vsphere_guest等配置模块 我怀疑172.20.22.5实际上是你的ESX主机,并且可以尝试从那里执行模块,其中pysphere肯定不存在。
使用:

- hosts: localhost
  tasks:
    - vsphere_guest:
         ...

答案 1 :(得分: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