diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c0d1b6b --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.terraform +.terraform.lock.hcl +*.tfstate +*.tfstate.* diff --git a/ansible.cfg b/ansible.cfg index 69ce460..372966a 100644 --- a/ansible.cfg +++ b/ansible.cfg @@ -1,7 +1,7 @@ [defaults] inventory = inventory.ini -remote_user = vagrant -private_key_file = ~/.ssh/id_rsa host_key_checking = False -remote_tmp = /tmp/.ansible-${USER}/tmp -roles_path= roles +roles_path = roles +remote_user = ubuntu +private_key_file = /home/emora/linux_files/workStuff/emi_openproject/tf_config/keys/openproject + diff --git a/host_vars/db1.yml b/host_vars/db1.yml index 15b1703..a96bcad 100644 --- a/host_vars/db1.yml +++ b/host_vars/db1.yml @@ -1 +1 @@ -ansible_host: 192.168.56.12 +ansible_host: 3.123.232.167 diff --git a/host_vars/web1.yml b/host_vars/web1.yml index 4eedc27..49a9a74 100644 --- a/host_vars/web1.yml +++ b/host_vars/web1.yml @@ -1,4 +1,4 @@ -ansible_host: 192.168.56.11 +ansible_host: 3.68.226.174 apache_config_path: /etc/apache2/sites-available/openproject.conf apache_service_name: apache2 ruby_version: "2.7" diff --git a/inventory.ini b/inventory.ini index e6c61d5..af9c06e 100644 --- a/inventory.ini +++ b/inventory.ini @@ -1,8 +1,8 @@ [dbservers] -db1 ansible_host=192.168.56.12 ansible_user=vagrant ansible_ssh_private_key_file=~/.ssh/vagrant_db_key +db1 ansible_host=3.123.232.167 ansible_user=ubuntu ansible_ssh_private_key_file=/home/emora/linux_files/workStuff/emi_openproject/tf_config/keys/openproject [webservers] -web1 ansible_host=192.168.56.11 ansible_user=vagrant ansible_ssh_private_key_file=~/.ssh/vagrant_web_key +web1 ansible_host=3.68.226.174 ansible_user=ubuntu ansible_ssh_private_key_file=/home/emora/linux_files/workStuff/emi_openproject/tf_config/keys/openproject [all:children] dbservers diff --git a/roles/webserver/handlers/main.yml b/roles/webserver/handlers/main.yml index 89305f0..b0c6680 100644 --- a/roles/webserver/handlers/main.yml +++ b/roles/webserver/handlers/main.yml @@ -3,3 +3,8 @@ service: name: "{{ apache_service_name }}" state: restarted + +- name: restart openproject + systemd: + name: openproject-web + state: restarted diff --git a/tf_config/ec2_config.tf b/tf_config/ec2_config.tf new file mode 100644 index 0000000..5fc355e --- /dev/null +++ b/tf_config/ec2_config.tf @@ -0,0 +1,72 @@ +data "aws_ssm_parameter" "ubuntu_2004" { + name = "/aws/service/canonical/ubuntu/server/focal/stable/current/amd64/hvm/ebs-gp2/ami-id" +} +data "aws_vpcs" "default" { + filter { + name = "isDefault" + values = ["true"] + } +} + +data "aws_subnets" "default_subnet" { + filter { + name = "vpc-id" + values = [data.aws_vpcs.default.ids[0]] + } +} + +resource "aws_security_group" "openproject_sg" { + name = "openproject-sg" + vpc_id = data.aws_vpcs.default.ids[0] + + ingress { + from_port = 22 + to_port = 22 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } + + ingress { + from_port = 80 + to_port = 80 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } + + ingress { + from_port = 5432 + to_port = 5432 + protocol = "tcp" + self = true + } + + egress { + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = ["0.0.0.0/0"] + } +} + +resource "aws_key_pair" "openproject" { + key_name = "openproject-key" + public_key = file("${path.module}/keys/openproject.pub") +} + +resource "aws_instance" "openproject" { + count = 2 + ami = data.aws_ssm_parameter.ubuntu_2004.value + instance_type = "t3.micro" + subnet_id = data.aws_subnets.default_subnet.ids[0] + vpc_security_group_ids = [aws_security_group.openproject_sg.id] + key_name = aws_key_pair.openproject.key_name + associate_public_ip_address = true + + tags = { + Name = "openproject-${count.index + 1}" + } +} + +output "openproject_public_ips" { + value = aws_instance.openproject[*].public_ip +} diff --git a/tf_config/terraform.tf b/tf_config/terraform.tf new file mode 100644 index 0000000..353d38f --- /dev/null +++ b/tf_config/terraform.tf @@ -0,0 +1,13 @@ +terraform { + required_providers { + aws = { + source = "hashicorp/aws" + version = "~> 5.92" + } + } + required_version = ">=1.2" +} + +provider "aws" { + region = "eu-central-1" +}