安装OpenStack SDK
pip install openstacksdk
安装Ansible
pip install ansible
创建一个Ansible playbook文件,例如 create_instance.yml
,并添加以下内容:
---
- hosts: localhost
gather_facts: no
tasks:
- name: Create an instance
os_server:
state: present
auth:
auth_url: http://<auth_url>:<auth_port>/v3
username: <username>
password: <password>
project_name: <project_name>
project_domain_name: <project_domain_name>
user_domain_name: <user_domain_name>
name: <instance_name>
image_name: <image_name>
flavor_name: <flavor_name>
key_name: <key_name>
network_name: <network_name>
security_groups: <security_groups>
timeout: 200
register: instance
- name: Print instance details
debug:
var: instance
替换 <auth_url>
、<auth_port>
、<username>
、<password>
、<project_name>
、<project_domain_name>
、<user_domain_name>
、<instance_name>
、<image_name>
、<flavor_name>
、<key_name>
、<network_name>
和 <security_groups>
为您的OpenStack环境信息和云主机配置信息。
运行Ansible playbook:
ansible-playbook create_instance.yml
等待Ansible playbook执行完成,您将在OpenStack上创建一台云主机。
标签:name,instance,Ansible,playbook,OpenStack,SDK From: https://www.cnblogs.com/wang-hongwei/p/17414000.html