194 lines
6.2 KiB
YAML
Executable File
194 lines
6.2 KiB
YAML
Executable File
---
|
|
- name: Get start timestamp
|
|
set_fact: starttime="{{ ansible_date_time }}"
|
|
|
|
- name: Retrieve specified flavor
|
|
os_flavor_facts:
|
|
auth: "{{ auth }}"
|
|
region_name: "{{ app_env.region_name }}"
|
|
availability_zone: "{{ app_env.availability_zone }}"
|
|
validate_certs: "{{ app_env.validate_certs }}"
|
|
name: "{{ app_env.flavor_name }}"
|
|
|
|
- name: Create a key-pair
|
|
os_keypair:
|
|
state: "present"
|
|
auth: "{{ auth }}"
|
|
region_name: "{{ app_env.region_name }}"
|
|
availability_zone: "{{ app_env.availability_zone }}"
|
|
validate_certs: "{{ app_env.validate_certs }}"
|
|
name: "lampstack"
|
|
public_key_file: "{{ app_env.public_key_file }}"
|
|
|
|
- name: Create volume
|
|
os_volume:
|
|
state: present
|
|
auth: "{{ auth }}"
|
|
region_name: "{{ app_env.region_name }}"
|
|
availability_zone: "{{ app_env.availability_zone }}"
|
|
validate_certs: "{{ app_env.validate_certs }}"
|
|
size: "{{ app_env.volume_size }}"
|
|
wait: yes
|
|
display_name: db_volume
|
|
|
|
- name: Create security group
|
|
os_security_group:
|
|
state: present
|
|
auth: "{{ auth }}"
|
|
region_name: "{{ app_env.region_name }}"
|
|
availability_zone: "{{ app_env.availability_zone }}"
|
|
validate_certs: "{{ app_env.validate_certs }}"
|
|
name: lampstack_sg
|
|
description: security group for lampstack
|
|
|
|
- name: Add security rules
|
|
os_security_group_rule:
|
|
state: present
|
|
auth: "{{ auth }}"
|
|
region_name: "{{ app_env.region_name }}"
|
|
availability_zone: "{{ app_env.availability_zone }}"
|
|
validate_certs: "{{ app_env.validate_certs }}"
|
|
security_group: lampstack_sg
|
|
protocol: "{{ item.protocol }}"
|
|
direction: "{{ item.dir }}"
|
|
port_range_min: "{{ item.p_min }}"
|
|
port_range_max: "{{ item.p_max }}"
|
|
remote_ip_prefix: 0.0.0.0/0
|
|
with_items:
|
|
- { p_min: 22, p_max: 22, dir: ingress, protocol: tcp }
|
|
- { p_min: 80, p_max: 80, dir: ingress, protocol: tcp }
|
|
- { p_min: 2049, p_max: 2049, dir: ingress, protocol: tcp }
|
|
- { p_min: 2049, p_max: 2049, dir: egress, protocol: tcp }
|
|
- { p_min: 3306, p_max: 3306, dir: ingress, protocol: tcp }
|
|
- { p_min: -1, p_max: -1, dir: ingress, protocol: icmp }
|
|
- { p_min: -1, p_max: -1, dir: egress, protocol: icmp }
|
|
|
|
- name: Create database node
|
|
os_server:
|
|
state: "present"
|
|
auth: "{{ auth }}"
|
|
region_name: "{{ app_env.region_name }}"
|
|
availability_zone: "{{ app_env.availability_zone }}"
|
|
validate_certs: "{{ app_env.validate_certs }}"
|
|
name: database
|
|
image: "{{ app_env.image_name }}"
|
|
key_name: "lampstack"
|
|
timeout: 200
|
|
flavor: "{{ app_env.flavor_name }}"
|
|
network: "{{ app_env.private_net_name }}"
|
|
userdata: "{{ lookup('template', 'templates/userdata.j2') }}"
|
|
config_drive: "{{ app_env.config_drive | default('no') }}"
|
|
security_groups: lampstack_sg
|
|
floating_ip_pools: "{{ app_env.public_net_name | default(omit) }}"
|
|
meta:
|
|
hostname: database
|
|
register: database
|
|
|
|
- name: Add database node to the dbservers host group
|
|
add_host:
|
|
name: "{{ database.openstack.public_v4 }}"
|
|
groups: dbservers
|
|
when: database.openstack.public_v4 != ""
|
|
|
|
- name: Add database node to the dbservers host group
|
|
add_host:
|
|
name: "{{ database.openstack.private_v4 }}"
|
|
groups: dbservers
|
|
when: database.openstack.public_v4 == ""
|
|
|
|
- name: Create balancer node
|
|
os_server:
|
|
state: "present"
|
|
auth: "{{ auth }}"
|
|
region_name: "{{ app_env.region_name }}"
|
|
availability_zone: "{{ app_env.availability_zone }}"
|
|
validate_certs: "{{ app_env.validate_certs }}"
|
|
name: balancer
|
|
image: "{{ app_env.image_name }}"
|
|
key_name: "lampstack"
|
|
timeout: 200
|
|
flavor: "{{ app_env.flavor_name }}"
|
|
network: "{{ app_env.private_net_name }}"
|
|
userdata: "{{ lookup('template', 'templates/userdata.j2') }}"
|
|
config_drive: "{{ app_env.config_drive | default('no') }}"
|
|
security_groups: lampstack_sg
|
|
floating_ip_pools: "{{ app_env.public_net_name | default(omit) }}"
|
|
meta:
|
|
hostname: balancer
|
|
register: balancer
|
|
|
|
- name: Add balancer node to the balancers host group
|
|
add_host:
|
|
name: "{{ balancer.openstack.public_v4 }}"
|
|
groups: balancers
|
|
when: balancer.openstack.public_v4 != ""
|
|
|
|
- name: Add balancer node to the balancers host group
|
|
add_host:
|
|
name: "{{ balancer.openstack.private_v4 }}"
|
|
groups: balancers
|
|
when: balancer.openstack.public_v4 == ""
|
|
|
|
- name: Create a volume for database to save data
|
|
os_server_volume:
|
|
state: present
|
|
auth: "{{ auth }}"
|
|
region_name: "{{ app_env.region_name }}"
|
|
availability_zone: "{{ app_env.availability_zone }}"
|
|
validate_certs: "{{ app_env.validate_certs }}"
|
|
server: database
|
|
volume: db_volume
|
|
device: "{{ app_env.block_device_name }}"
|
|
|
|
- name: Create web server nodes to host application
|
|
os_server:
|
|
state: "present"
|
|
auth: "{{ auth }}"
|
|
region_name: "{{ app_env.region_name }}"
|
|
availability_zone: "{{ app_env.availability_zone }}"
|
|
validate_certs: "{{ app_env.validate_certs }}"
|
|
name: apache-{{ item }}
|
|
image: "{{ app_env.image_name }}"
|
|
key_name: "lampstack"
|
|
timeout: 200
|
|
flavor: "{{ app_env.flavor_name }}"
|
|
network: "{{ app_env.private_net_name }}"
|
|
floating_ip_pools: "{{ app_env.public_net_name | default(omit) }}"
|
|
userdata: "{{ lookup('template', 'templates/userdata.j2') }}"
|
|
config_drive: "{{ app_env.config_drive | default('no') }}"
|
|
security_groups: lampstack_sg
|
|
meta:
|
|
hostname: apache-{{ item }}
|
|
with_sequence: count={{ app_env.stack_size - 2 }}
|
|
register: webserver
|
|
|
|
- name: Add web servers to webservers host group
|
|
add_host:
|
|
name: "{{ item.openstack.public_v4 }}"
|
|
groups: webservers
|
|
when: item.openstack.public_v4 != ""
|
|
with_items: "{{ webserver.results }}"
|
|
no_log: True
|
|
|
|
- name: Add web servers to webservers host group
|
|
add_host:
|
|
name: "{{ item.openstack.private_v4 }}"
|
|
groups: webservers
|
|
when: item.openstack.public_v4 == ""
|
|
with_items: "{{ webserver.results }}"
|
|
no_log: True
|
|
|
|
- name: Add one web servers to wps host group
|
|
add_host:
|
|
name: "{{ webserver.results[0].openstack.public_v4 }}"
|
|
groups: wps
|
|
when: webserver.results[0].openstack.public_v4 != ""
|
|
no_log: True
|
|
|
|
- name: Add one web servers to wps host group
|
|
add_host:
|
|
name: "{{ webserver.results[0].openstack.private_v4 }}"
|
|
groups: wps
|
|
when: webserver.results[0].openstack.public_v4 == ""
|
|
no_log: True
|