2018-03-02 12:55:54 +00:00
---
2018-08-27 14:05:45 +00:00
- fail :
msg : "OpenStack credentials are not set. Download it from the OpenStack dashboard->Compute->API Access and source it in the shell (eg: source /tmp/dhc-openrc.sh)"
2019-04-26 15:48:28 +00:00
when : lookup('env', 'OS_AUTH_URL')|length <= 0
2018-08-27 14:05:45 +00:00
2019-04-08 20:20:34 +00:00
- name : Build python virtual environment
import_tasks : venv.yml
2018-03-02 12:55:54 +00:00
2019-09-28 00:10:20 +00:00
- name : Security group created
2021-10-31 09:58:35 +00:00
openstack.cloud.security_group :
2019-09-28 00:10:20 +00:00
state : "{{ state|default('present') }}"
name : "{{ algo_server_name }}-security_group"
description : AlgoVPN security group
register : os_security_group
2018-03-02 12:55:54 +00:00
2019-09-28 00:10:20 +00:00
- name : Security rules created
2021-10-31 09:58:35 +00:00
openstack.cloud.security_group_rule :
2019-09-28 00:10:20 +00:00
state : "{{ state|default('present') }}"
security_group : "{{ os_security_group.id }}"
protocol : "{{ item.proto }}"
port_range_min : "{{ item.port_min }}"
port_range_max : "{{ item.port_max }}"
remote_ip_prefix : "{{ item.range }}"
with_items :
2022-07-30 12:01:24 +00:00
- { proto: tcp, port_min : "{{ ssh_port }}" , port_max : "{{ ssh_port }}" , range : 0.0 .0 .0 /0 }
2019-09-28 00:10:20 +00:00
- { proto: icmp, port_min: -1, port_max: -1, range : 0.0 .0 .0 /0 }
- { proto: udp, port_min: 4500, port_max: 4500, range : 0.0 .0 .0 /0 }
- { proto: udp, port_min: 500, port_max: 500, range : 0.0 .0 .0 /0 }
- { proto: udp, port_min : "{{ wireguard_port }}" , port_max : "{{ wireguard_port }}" , range : 0.0 .0 .0 /0 }
2018-03-02 12:55:54 +00:00
2019-09-28 00:10:20 +00:00
- name : Gather facts about flavors
2021-10-31 09:58:35 +00:00
openstack.cloud.compute_flavor_info :
2019-09-28 00:10:20 +00:00
ram : "{{ cloud_providers.openstack.flavor_ram }}"
2021-10-31 09:58:35 +00:00
register : os_flavor
2018-03-02 12:55:54 +00:00
2019-09-28 00:10:20 +00:00
- name : Gather facts about images
2021-10-31 09:58:35 +00:00
openstack.cloud.image_info :
register : os_image
2020-01-07 13:28:19 +00:00
- name : Set image as a fact
set_fact :
image_id : "{{ item.id }}"
2021-10-31 09:58:35 +00:00
loop : "{{ os_image.openstack_image }}"
2020-01-07 13:28:19 +00:00
when :
- item.name == cloud_providers.openstack.image
- item.status == "active"
2018-03-02 12:55:54 +00:00
2019-09-28 00:10:20 +00:00
- name : Gather facts about public networks
2021-10-31 09:58:35 +00:00
openstack.cloud.networks_info :
register : os_network
2018-03-02 12:55:54 +00:00
2019-09-28 00:10:20 +00:00
- name : Set the network as a fact
set_fact :
public_network_id : "{{ item.id }}"
when :
- item['router:external']|default(omit)
- item['admin_state_up']|default(omit)
- item['status'] == 'ACTIVE'
2021-10-31 09:58:35 +00:00
with_items : "{{ os_network.openstack_networks }}"
2018-03-02 12:55:54 +00:00
2019-09-28 00:10:20 +00:00
- name : Set facts
set_fact :
2021-10-31 09:58:35 +00:00
flavor_id : "{{ (os_flavor.openstack_flavors | sort(attribute='ram'))[0]['id'] }}"
2019-09-28 00:10:20 +00:00
security_group_name : "{{ os_security_group['secgroup']['name'] }}"
2018-11-22 18:04:58 +00:00
2019-09-28 00:10:20 +00:00
- name : Server created
2021-10-31 09:58:35 +00:00
openstack.cloud.server :
2019-09-28 00:10:20 +00:00
state : "{{ state|default('present') }}"
name : "{{ algo_server_name }}"
image : "{{ image_id }}"
flavor : "{{ flavor_id }}"
security_groups : "{{ security_group_name }}"
2020-01-07 13:28:19 +00:00
userdata : "{{ lookup('template', 'files/cloud-init/base.yml') }}"
2019-09-28 00:10:20 +00:00
nics :
- net-id : "{{ public_network_id }}"
register : os_server
2018-03-02 12:55:54 +00:00
2019-09-28 00:10:20 +00:00
- set_fact :
cloud_instance_ip : "{{ os_server['openstack']['public_v4'] }}"
2020-01-07 13:28:19 +00:00
ansible_ssh_user : algo
ansible_ssh_port : "{{ ssh_port }}"
cloudinit : true