使用Packstack和Ansible部署新VM



我已经安装了Packstack和Ansible 2.7.5,我想使用Ansible进行测试并部署VM。我正在使用以下代码:

--- #Deploy an instance
- name: Deploy an instance
hosts: localhost
gather_facts: false
tasks: 
- name: Deploy an instance
os_server: 
state: present
auth: 
auth_url: http://127.0.0.1:5000/v2.0/
username: admin
password: 712e207207aa4083 
project_name: admin 
name: webserver
image: cirros
key_name: root
timeout: 200  
flavor: 1
nics:
- net-id: fa6af4e6-c44e-439c-a91c-03bcae55e587
meta:
hostname: webserver.localdomain

当我运行它时,我得到以下错误:

TASK [Deploy an instance] *****************************************************************************************************************************************************************************************
fatal: [localhost]: FAILED! => {"changed": false, "msg": "To utilize this module, the installed version ofthe openstacksdk library MUST be >=0.12.0"}
to retry, use: --limit @/home/dante/Openstack/deployment.retry
PLAY RECAP ********************************************************************************************************************************************************************************************************
localhost                  : ok=0    changed=0    unreachable=0    failed=1   

我也尝试安装Openstacksdk 0.12.0,但我得到了一些其他与依赖关系有关的错误:

[dante@localhost Openstack]$ sudo pip install openstacksdk==0.12.0
...
Installing collected packages: ipaddress, os-service-types, PyYAML, openstacksdk
Found existing installation: ipaddress 1.0.16
Cannot uninstall 'ipaddress'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

有什么方法可以纠正吗?或者,如果这个模块是新的,并且有太多错误,有其他方法可以使用Ansible在Openstack中创建VM吗?我也检查了nova_compute模块的版本,但它说这个Ansible模块在Ansible 2.0之后不推荐使用。

谨致问候,罗曼

尽管在hosts:islocalhost中,您仍然需要告诉它连接类型https://docs.ansible.com/ansible/latest/user_guide/playbooks_delegation.html因此,您可以使用delegate_to:localhost或connection:localhost。这对于与API对话或不需要ssh连接来完成任务的任何模块都是必需的。例如aws、gitlab、github、nios模块。

最终通过安装openstacksdk及其所有依赖项解决了这个问题。这也是代码:

--- #Deploy an instance
- name: Deploy an instance
hosts: localhost
gather_facts: false
tasks: 
- name: Deploy an instance
os_server: 
state: present
auth: 
auth_url: http://<URL TAKEN FROM SOURCE FILE> 
username: <USERNAME>
password: <PASSWORD> 
name: webserver
image: <ID OF THE IMAGE>
timeout: 700  
flavor: 1
auto_floating_ip: yes
register: webserver

最新更新