Skip to content

Commit 1d3f31a

Browse files
committed
Support attaching a floating IP to the Ansible control host
This may be used for SSH access to the Ansible control host when no direct access to the multinode network is available.
1 parent f922a98 commit 1d3f31a

File tree

4 files changed

+42
-3
lines changed

4 files changed

+42
-3
lines changed

README.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ Generate Terraform variables:
129129
infra_vm_flavor = "general.v1.small"
130130
infra_vm_disk_size = 100
131131
132+
add_ansible_control_fip = false
133+
ansible_control_fip_pool = ""
132134
EOF
133135
134136
You will need to set the `multinode_keypair`, `prefix`, and `ssh_public_key`.
@@ -147,6 +149,12 @@ If `deploy_wazuh` is set to true, an infrastructure VM will be created that
147149
hosts the Wazuh manager. The Wazuh deployment playbooks will also be triggered
148150
automatically to deploy Wazuh agents to the overcloud hosts.
149151

152+
If `add_ansible_control_fip` is set to `true`, a floating IP will be created
153+
and attached to the Ansible control host. In that case
154+
`ansible_control_fip_pool` should be set to the name of the pool (network) from
155+
which to allocate the floating IP, and the floating IP will be used for SSH
156+
access to the control host.
157+
150158
Generate a plan:
151159

152160
.. code-block:: console

compute_instances.tf

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,30 @@
1+
data "openstack_networking_network_v2" "multinode_network" {
2+
name = var.multinode_vm_network
3+
}
4+
5+
resource "openstack_networking_port_v2" "ansible_control_port" {
6+
network_id = data.openstack_networking_network_v2.multinode_network.id
7+
}
8+
9+
resource "openstack_networking_floatingip_v2" "ansible_control_fip" {
10+
count = var.add_ansible_control_fip ? 1 : 0
11+
pool = var.ansible_control_fip_pool
12+
}
13+
14+
resource "openstack_networking_floatingip_associate_v2" "ansible_control_fip_association" {
15+
count = var.add_ansible_control_fip ? 1 : 0
16+
floating_ip = resource.openstack_networking_floatingip_v2.ansible_control_fip.0.address
17+
port_id = resource.openstack_networking_port_v2.ansible_control_port.id
18+
}
19+
120
resource "openstack_compute_instance_v2" "ansible_control" {
221
name = format("%s-%s", var.prefix, var.ansible_control_vm_name)
322
flavor_name = var.ansible_control_vm_flavor
423
key_pair = resource.openstack_compute_keypair_v2.keypair.name
524
config_drive = true
625
user_data = file("templates/userdata.cfg.tpl")
726
network {
8-
name = var.multinode_vm_network
27+
port = resource.openstack_networking_port_v2.ansible_control_port.id
928
}
1029

1130
dynamic "block_device" {

outputs.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
output "ansible_control_access_ip_v4" {
2-
value = openstack_compute_instance_v2.ansible_control.access_ip_v4
2+
value = var.add_ansible_control_fip ? openstack_networking_floatingip_v2.ansible_control_fip[0].address : openstack_compute_instance_v2.ansible_control.access_ip_v4
33
}
44

55
output "seed_access_ip_v4" {
@@ -76,7 +76,7 @@ resource "local_file" "deploy_openstack" {
7676
}
7777

7878
resource "ansible_host" "control_host" {
79-
name = openstack_compute_instance_v2.ansible_control.access_ip_v4
79+
name = var.add_ansible_control_fip ? openstack_networking_floatingip_v2.ansible_control_fip[0].address : openstack_compute_instance_v2.ansible_control.access_ip_v4
8080
groups = ["ansible_control"]
8181
variables = {
8282
ansible_user = var.ssh_user

variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,15 @@ variable "deploy_wazuh" {
102102
type = bool
103103
default = false
104104
}
105+
106+
variable "add_ansible_control_fip" {
107+
description = "Bool, whether to add a floating IP address to the Ansible control host."
108+
type = bool
109+
default = false
110+
}
111+
112+
variable "ansible_control_fip_pool" {
113+
description = "Pool/network from which to allocate a floating IP for the Ansible control host."
114+
type = string
115+
default = ""
116+
}

0 commit comments

Comments
 (0)