我得到了一个文件,该文件创建了X个具有不同操作系统和风格的虚拟机。
---
- hosts: localhost
vars:
http_port: 80
max_clients: 200
tasks:
- name: create VM
os_server:
name: "{{ item.name }}"
state: present
image: "{{ item.image }}"
boot_from_volume: True
security_groups: ssh
flavor: "{{ item.flavor }}"
key_name: mykey
region_name: "{{ lookup('env', 'OS_REGION_NAME') }}"
nics:
- net-name: private
wait: yes
register: instances
with_items:
- { name: Debian Jessie, image: Debian Jessie 8 , flavor: c1.small, loginame: debian }
- { name: Debian Stretch, image: Debian Stretch 9 , flavor: c1.small, loginame: debian }
- { name: ubuntu Xenial, image: Ubuntu Xenial 16.04 , flavor: c1.small, loginame: ubuntu }
- { name: ubuntu Trusty, image: Ubuntu Trusty 14.04 , flavor: c1.small, loginame: ubuntu }
- { name: Fedora, image: Fedora 25 , flavor: c1.small, loginame: fedora }
- { name: CentOS, image: CentOS 7 , flavor: c1.small, loginame: centos }
- { name: Rstudio, image: RStudio Appliance , flavor: c1.small, loginame: ubuntu }
- { name: Spark Zepellin, image: Spark Zeppelin , flavor: m1.medium, loginame: ubuntu }
现在我想把它分成两个文件:main。yaml和vars。亚马尔。
主要的yaml正在创建VM和VAR。yaml应该提供参数。
我该怎么做?我试图导入它,但无法使其正常工作。
***************************主要。亚马尔**********************************************
---
- hosts: localhost
vars:
http_port: 80
max_clients: 200
tasks:
- import_vars: vars.yaml
- name: create VM
os_server:
name: "{{ item.name }}"
state: present
image: "{{ item.image }}"
boot_from_volume: True
security_groups: ssh
flavor: "{{ item.flavor }}"
key_name: mykey
region_name: "{{ lookup('env', 'OS_REGION_NAME') }}"
nics:
- net-name: private
wait: yes
register: instances
***************************变量。亚马尔**********************************************
---
with_items:
- { name: Debian Jessie, image: Debian Jessie 8 , flavor: c1.small, loginame: debian }
- { name: Debian Stretch, image: Debian Stretch 9 , flavor: c1.small, loginame: debian }
- { name: ubuntu Xenial, image: Ubuntu Xenial 16.04 , flavor: c1.small, loginame: ubuntu }
- { name: ubuntu Trusty, image: Ubuntu Trusty 14.04 , flavor: c1.small, loginame: ubuntu }
- { name: Fedora, image: Fedora 25 , flavor: c1.small, loginame: fedora }
- { name: CentOS, image: CentOS 7 , flavor: c1.small, loginame: centos }
- { name: Rstudio, image: RStudio Appliance , flavor: c1.small, loginame: ubuntu }
- { name: Spark Zepellin, image: Spark Zeppelin , flavor: m1.medium, loginame: ubuntu }