使用Packstack和Ansible部署新的VM

时间:2018-07-26 09:03:53

标签: ansible virtual-machine openstack

我已经安装了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 2.0之后不推荐使用此Ansible模块。

最好的问候, 罗曼(Romain)

2 个答案:

答案 0 :(得分:0)

尽管在您的主机中:localhost,您仍然需要告诉它连接类型https://docs.ansible.com/ansible/latest/user_guide/playbooks_delegation.html,以便可以使用委托_至:localhost或连接:localhost。与API通讯或不需要ssh连接即可完成任务的所有模块都需要此功能。例如,aws,gitlab,github,nios模块。

答案 1 :(得分:0)

通过安装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