blob: c8cb643bc0e6c6bfabe1cd5d287ed6980cf0f436 [file] [log] [blame]
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
# license agreements; and to You under the Apache License, Version 2.0.
---
# boot_instances.yml
# TODO, in "with_instance" loops, the "instance" variable that is passed in gets unset, look up the proper way to do nested loops
- name: set vars
set_fact:
name: "{{instance.name}}"
flavor: "{{instance.flavor | default (default_flavor, true) }}"
volume_env: "{{ lookup('env', 'OS_WSK_' + instance.name|upper + '_VOLUME')}}"
volume_dict: "{{instance.volume | default({})}}"
# instance: "{{instances | selectattr('name', 'equalto', 'db') | list | first}}"
- name: create volume
os_volume:
state: present
size: "{{volume_env | default( volume_dict.size )}}"
display_name: "{{name}}-{{item}}_volume"
wait: yes
with_sequence: count={{instance.num_instances}}
when: (volume_env and volume_env != "") or (volume_dict and volume_dict.size)
- name: launch an instance
os_server:
validate_certs: False
name: "{{name}}-{{item}}"
state: present
auth: "{{auth}}"
nics:
- net-id: "{{net_id}}"
#- net-name: "{{net_name}}"
image: "{{image}}"
flavor: "{{item.flavor | default (flavor) }}"
key_name: "{{key_name}}"
security_groups: "{{security_groups}}"
auto_ip: no
wait: yes
register: instance_info
with_sequence: count={{instance.num_instances}}
- name: attach volume to host
os_server_volume:
server: "{{name}}-{{item}}"
state: present
volume: "{{name}}-{{item}}_volume"
wait: yes
# register: volume_info
with_sequence: count={{instance.num_instances}}
when: (volume_env and volume_env != "") or (volume_dict and volume_dict.size)
# - add_host: ansible_ssh_host={{ item.server.private_v4 }} groups={{name}}
# with_items: instance_info.results
# - local_action: add_host ansible_ssh_host={{ item.server.private_v4 }} groupname={{name}}
# with_items: instance_info.results
- shell: "grep -e {{name}} {{hosts_dir}}/hosts"
ignore_errors: True
register: hosts_file
# TODO, should render the hosts file from a template by using the add_host module commented below with a template
- shell: "echo [{{name}}] >> {{hosts_dir}}/hosts"
when: "{{hosts_file.rc}} != 0"
- lineinfile: insertafter="^{{name}}" line="{{item.server.networks.itervalues().next()[0]}} block_device={{item.server.volumes[0].device }}" dest="{{hosts_dir}}/hosts"
with_items: instance_info.results
when: (volume_env and volume_env != "") or (volume_dict and volume_dict.size)
- lineinfile: insertafter="^{{name}}" line="{{item.server.networks.itervalues().next()[0]}}" dest="{{hosts_dir}}/hosts"
with_items: instance_info.results
when: (not volume_env or volume_env == "" ) and (not volume_dict or not volume_dict.size)