我正在尝试通过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所以它似乎已经安装了,而且是最新的,为什么我会收到这个错误信息?我怎么才能修复我的角色现在工作得很好呢?天啊,安赛普快把我逼疯了..
我希望你们能帮助我,提前谢谢!
致以亲切的问候,基尔曼
编辑:所以我用旧的东西写了一个新的剧本,新的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斗争是真实的。
发布于 2016-08-03 15:33:07
一般情况下,您应该在本地ansible计算机上执行配置模块,如vsphere_guest。
我怀疑172.20.22.5实际上是你的ESX主机,ansible试图从那里执行模块,而pysphere肯定是不存在的。
使用:
- hosts: localhost
tasks:
- vsphere_guest:
...发布于 2016-10-16 20:13:47
在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
https://stackoverflow.com/questions/38736888
复制相似问题