Hello,
I am trying to launch/create multiple instances and attach multiple
volumes with a loop but not having much luck. I can get it to work if
I define each instance/volume but who wants to do that? Ideally I
would set a var that says something like make 100 instances. Below is
an example of what I currently have. How to I transfor these into
loops?
---
- name: launch compute instances
hosts: localhost
vars:
auth_url: "
http://controller:35357/v2.0/"
username:
password:
project:
image: CentOS-7-x86_64-GenericCloud-1601
key: key
timeout: 200
flavor: m1.large
security: default
volume_size: 1
volumes_storage1:
- storage1_vdb
- storage1_vdc
- storage1_vdd
- storage1_vde
- storage1_vdf
- storage1_vdg
- storage1_vdh
- storage1_vdi
- storage1_vdj
- storage1_vdk
tasks:
- name: create {{ volume_size }}g storage1_vdb
os_volume:
state: present
auth:
auth_url: "{{ auth_url }}"
username: "{{ username }}"
password: "{{ password }}"
project_name: "{{ project }}"
size: "{{ volume_size }}"
display_name: storage1_vdb
- name: launch sql
os_server:
state: present
auth:
auth_url: "{{ auth_url }}"
username: "{{ username }}"
password: "{{ password }}"
project_name: "{{ project }}"
name: sql1
image: "{{ image }}"
key_name: "{{ key }}"
timeout: "{{ timeout }}"
flavor: "{{ flavor }}"
security_groups: "{{ security }}"
- name: launch storage1
os_server:
state: present
auth:
auth_url: "{{ auth_url }}"
username: "{{ username }}"
password: "{{ password }}"
project_name: "{{ project }}"
name: storage1
image: "{{ image }}"
key_name: "{{ key }}"
timeout: "{{ timeout }}"
flavor: "{{ flavor }}"
security_groups: "{{ security }}"
volumes:
"{{ volumes_storage1 }}"