首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >pysphere - ansible的麻烦

pysphere - ansible的麻烦
EN

Stack Overflow用户
提问于 2016-08-03 15:18:00
回答 2查看 1.5K关注 0票数 1

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

代码语言:javascript
复制
- 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

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

代码语言:javascript
复制
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“模块丢失了。我已经用命令检查过了:

代码语言:javascript
复制
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

然后我进行了“升级”,并得到了以下消息:

代码语言:javascript
复制
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

所以它似乎已经安装了,而且是最新的,为什么我会收到这个错误信息?我怎么才能修复我的角色现在工作得很好呢?天啊,安赛普快把我逼疯了..

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

致以亲切的问候,基尔曼

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

代码语言:javascript
复制
---
- 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

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

代码语言:javascript
复制
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

斗争是真实的。

EN

回答 2

Stack Overflow用户

发布于 2016-08-03 15:33:07

一般情况下,您应该在本地ansible计算机上执行配置模块,如vsphere_guest

我怀疑172.20.22.5实际上是你的ESX主机,ansible试图从那里执行模块,而pysphere肯定是不存在的。

使用:

代码语言:javascript
复制
- hosts: localhost
  tasks:
    - vsphere_guest:
         ...
票数 0
EN

Stack Overflow用户

发布于 2016-10-16 20:13:47

在macOS /OSX上再次遇到这个问题...这似乎与PYTHONPATH有关。

我的.profile里有这个

代码语言:javascript
复制
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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38736888

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档