使用 Packstack 和 Ansible 部署新虚拟机
Deploying a new VM using Packstack and Ansible
我已经安装了 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: 是 localhost,你仍然需要告诉它连接类型 https://docs.ansible.com/ansible/latest/user_guide/playbooks_delegation.html 这样你就可以使用 delegate_to: localhost 或 connection: localhost 。这对于与 API 对话或不需要 ssh 连接来完成任务的任何模块都是必需的。例如aws、gitlab、github、nios modules.
最后通过安装 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
我已经安装了 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: 是 localhost,你仍然需要告诉它连接类型 https://docs.ansible.com/ansible/latest/user_guide/playbooks_delegation.html 这样你就可以使用 delegate_to: localhost 或 connection: localhost 。这对于与 API 对话或不需要 ssh 连接来完成任务的任何模块都是必需的。例如aws、gitlab、github、nios modules.
最后通过安装 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