Skip to content

Instantly share code, notes, and snippets.

@kareiva
Created November 8, 2019 08:09
Show Gist options
  • Save kareiva/27b0ffe23fcec0b0432134528710560f to your computer and use it in GitHub Desktop.
Save kareiva/27b0ffe23fcec0b0432134528710560f to your computer and use it in GitHub Desktop.
provider "openstack" {
user_name = "admin"
tenant_name = "containers"
}
data "openstack_networking_floatingip_v2" "fip_jump" {
address = "193.219.144.110"
}
data "openstack_networking_floatingip_v2" "fip_master1" {
address = "193.219.144.111"
}
data "openstack_networking_floatingip_v2" "fip_master2" {
address = "193.219.144.113"
}
data "openstack_networking_floatingip_v2" "fip_master3" {
address = "193.219.144.115"
}
resource "openstack_compute_instance_v2" "master" {
count = 3
name = "master-${count.index}.okd"
image_id = "a598e364-20e3-4ad9-82a0-247139e2fb17"
flavor_id = "48da4865-f5a4-4c16-a2ac-2596fd012a6e"
key_pair = "simonas"
security_groups = ["default","AllowAll"]
user_data = <<EOT
#!/bin/bash
sed -i "s/^.*requiretty/#Defaults requiretty/" /etc/sudoers
yum upgrade -y && reboot
EOT
network {
name = "PrivateForVlan10"
}
}
resource "openstack_compute_instance_v2" "node" {
count = 3
name = "node-${count.index}.okd"
image_id = "a598e364-20e3-4ad9-82a0-247139e2fb17"
flavor_id = "48da4865-f5a4-4c16-a2ac-2596fd012a6e"
key_pair = "simonas"
security_groups = ["default","AllowAll"]
user_data = <<EOT
#!/bin/bash
sed -i "s/^.*requiretty/#Defaults requiretty/" /etc/sudoers
yum upgrade -y && reboot
EOT
network {
name = "PrivateForVlan10"
}
}
resource "openstack_compute_instance_v2" "jump" {
name = "jump"
image_id = "a598e364-20e3-4ad9-82a0-247139e2fb17"
flavor_id = "48da4865-f5a4-4c16-a2ac-2596fd012a6e"
key_pair = "simonas"
security_groups = ["default","AllowAll"]
user_data = <<EOT
#!/bin/bash
sed -i "s/^.*requiretty/#Defaults requiretty/" /etc/sudoers
yum upgrade -y
yum install -y ansible git httpd-tools pyOpenSSL java
echo "ssh_args = -C -o ControlMaster=auto -o ControlPersist=600s -o
ConnectTimeout=60" >> /etc/ansible/ansible.cfg
echo "pipelining = True" >> /etc/ansible/ansible.cfg
echo "scp_if_ssh = smart" >> /etc/ansible/ansible.cfg
reboot
EOT
network {
name = "PrivateForVlan10"
}
}
resource "null_resource" "jump_setup" {
depends_on = ["openstack_compute_floatingip_associate_v2.fip_1"]
connection {
user = "centos"
agent = true
host = data.openstack_networking_floatingip_v2.fip_jump.address
}
provisioner "remote-exec" {
inline = [
"echo \"git clone -b 'release-3.11' [email protected]:openshift/openshift-ansible.git\" > init.sh",
"echo \"git clone [email protected]:vubtg/openshift.git\" >> init.sh"
]
}
}
resource "null_resource" "jump_etc_hosts" {
depends_on = ["openstack_compute_floatingip_associate_v2.fip_1"]
triggers = {
instance_ids = "${join(",", openstack_compute_instance_v2.master.*.id)},${join(",", openstack_compute_instance_v2.node.*.id )}"
}
connection {
user = "centos"
agent = true
host = data.openstack_networking_floatingip_v2.fip_jump.address
}
provisioner "remote-exec" {
inline = concat([
"echo '127.0.0.1 localhost localhost.localdomain' | sudo tee /etc/hosts"
], [
for i, m in openstack_compute_instance_v2.master:
"echo '${m.access_ip_v4} master-${i}.okd master-${i}.okd.novalocal' | sudo tee -a /etc/hosts"
], [
for i, n in openstack_compute_instance_v2.node:
"echo '${n.access_ip_v4} node-${i}.okd node-${i}.okd.novalocal' | sudo tee -a /etc/hosts"
], [
for i, m in openstack_compute_instance_v2.master:
"cat /etc/hosts | ssh -o \"StrictHostKeyChecking=no\" master-${i}.okd sudo tee /etc/hosts"
], [
for i, n in openstack_compute_instance_v2.node:
"cat /etc/hosts | ssh -o \"StrictHostKeyChecking=no\" node-${i}.okd sudo tee /etc/hosts"
])
}
}
resource "openstack_compute_floatingip_associate_v2" "fip_1" {
floating_ip = data.openstack_networking_floatingip_v2.fip_jump.address
instance_id = "${openstack_compute_instance_v2.jump.id}"
}
resource "openstack_compute_floatingip_associate_v2" "fip_m1" {
floating_ip = data.openstack_networking_floatingip_v2.fip_master1.address
instance_id = "${openstack_compute_instance_v2.master.*.id[0]}"
}
resource "openstack_compute_floatingip_associate_v2" "fip_m2" {
floating_ip = data.openstack_networking_floatingip_v2.fip_master2.address
instance_id = "${openstack_compute_instance_v2.master.*.id[1]}"
}
resource "openstack_compute_floatingip_associate_v2" "fip_m3" {
floating_ip = data.openstack_networking_floatingip_v2.fip_master3.address
instance_id = "${openstack_compute_instance_v2.master.*.id[2]}"
}
resource "openstack_blockstorage_volume_v2" "glusterfs" {
count = 3
name = "glusterfs-${count.index}"
size = 100
}
resource "openstack_compute_volume_attach_v2" "attachments" {
count = 3
instance_id = "${openstack_compute_instance_v2.node.*.id[count.index]}"
volume_id = "${openstack_blockstorage_volume_v2.glusterfs.*.id[count.index]}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment