From 17bcb2684fbeb89cd6c07b8abde081af57eb7e70 Mon Sep 17 00:00:00 2001 From: arunodhayamsam <108027-arunodhayamsam@users.noreply.framagit.org> Date: Mar 31 2022 15:39:12 +0000 Subject: Applied ansible styling best practices and Terraform data sorces --- diff --git a/.provision/ansible-role-lufi/README.md b/.provision/ansible-role-lufi/README.md index ee540e0..e943dda 100644 --- a/.provision/ansible-role-lufi/README.md +++ b/.provision/ansible-role-lufi/README.md @@ -9,10 +9,10 @@ Role Variables | `app_dir` | /var/www/lufi | Set the application directory for the best practice | | `lufi_owner` | www-data | Set the application user for the best practice | | `lufi_group` | www-data | Set the application group for the best practice | -| `contact` | contact.example.com | Contact option (mandatory), where you have to put some way for the users to contact you. | -| `report` | report@example.com | report option (mandatory) Put an email address or an URL to let people report illegal files | -| `project_version` | master | We can chose the project version either Master branch, Dev branch or tag based | -| `servername` | IP address (or) CNAME/FQDN | Mention the Server Name for the Nginx configurations | +| `_contact` | contact.example.com | Contact option (mandatory), where you have to put some way for the users to contact you. | +| `_report` | report@example.com | report option (mandatory) Put an email address or an URL to let people report illegal files | +| `_project_version` | master | We can chose the project version either Master branch, Dev branch or tag based | +| `_server_name` | IP address (or) CNAME/FQDN | Mention the Server Name for the Nginx configurations | Sample example of use in a playbook -------------- diff --git a/.provision/ansible-role-lufi/tasks/apprun.yml b/.provision/ansible-role-lufi/tasks/apprun.yml index 6038d0e..4728886 100644 --- a/.provision/ansible-role-lufi/tasks/apprun.yml +++ b/.provision/ansible-role-lufi/tasks/apprun.yml @@ -6,7 +6,7 @@ chdir: "{{ app_dir }}" - name: Upload application file - template: + ansible.builtin.template: src: ../templates/lufi.conf.j2 dest: "{{ app_dir }}/lufi.conf" @@ -16,7 +16,7 @@ chdir: "{{ app_dir }}" - name: Nginx configuration file add - template: + ansible.builtin.template: src: ../templates/app.conf dest: /etc/nginx/conf.d/ mode: '0644' diff --git a/.provision/ansible-role-lufi/tasks/dependencies.yml b/.provision/ansible-role-lufi/tasks/dependencies.yml index 04272af..cc4ca9c 100644 --- a/.provision/ansible-role-lufi/tasks/dependencies.yml +++ b/.provision/ansible-role-lufi/tasks/dependencies.yml @@ -1,5 +1,7 @@ +#dependencies.yml +--- - name: Install Dependencies - apt: + ansible.builtin.apt: name: - nginx - build-essential @@ -12,6 +14,6 @@ state: present - name: Install Postgress Dev Packages - apt: + ansible.builtin.apt: name: - libpq-dev \ No newline at end of file diff --git a/.provision/ansible-role-lufi/templates/lufi.conf.j2 b/.provision/ansible-role-lufi/templates/lufi.conf.j2 index 45dfbe8..9b9ee5f 100644 --- a/.provision/ansible-role-lufi/templates/lufi.conf.j2 +++ b/.provision/ansible-role-lufi/templates/lufi.conf.j2 @@ -21,12 +21,12 @@ # Put a way to contact you here and uncomment it # You can put some HTML in it # MANDATORY - contact => 'Contact page', + contact => 'Contact page', # Put an URL or an email address to receive file reports and uncomment it # It's for make reporting illegal files easy for users # MANDATORY - report => '{{ report }}', + report => '{{ _report }}', # Array of random strings used to encrypt cookies # optional, default is ['fdjsofjoihrei'], PLEASE, CHANGE IT diff --git a/.provision/ansible-role-lufi/vars/main.yml b/.provision/ansible-role-lufi/vars/main.yml index dff6c35..04df23c 100644 --- a/.provision/ansible-role-lufi/vars/main.yml +++ b/.provision/ansible-role-lufi/vars/main.yml @@ -5,12 +5,12 @@ lufi_owner: "www-data" lufi_group: "www-data" -contact: "contact.example.com" +app_dir: "" -report: "report@example.com" +_contact: "contact.example.com" -app_dir: "" +_report: "report@example.com" -project_version: "" +_project_version: "" -servername: "" +_servername: "" diff --git a/.provision/terraform-aws-lufi/main.tf b/.provision/terraform-aws-lufi/main.tf index f4b7de5..de8fa8f 100644 --- a/.provision/terraform-aws-lufi/main.tf +++ b/.provision/terraform-aws-lufi/main.tf @@ -1,5 +1,5 @@ #Create the VPC -resource "aws_vpc" "MAIN" { +resource "aws_vpc" "vpc" { cidr_block = "${var.vpc_cidr}" enable_dns_hostnames = true enable_dns_support = true @@ -12,7 +12,7 @@ resource "aws_vpc" "MAIN" { # Create InternetGateWay and attach to VPC resource "aws_internet_gateway" "IGW" { - vpc_id = "${aws_vpc.MAIN.id}" + vpc_id = "${aws_vpc.vpc.id}" tags = { "Name" = "lufi-master-igw" } @@ -21,7 +21,7 @@ resource "aws_internet_gateway" "IGW" { # Create a public subnet resource "aws_subnet" "publicsubnet" { - vpc_id = "${aws_vpc.MAIN.id}" + vpc_id = "${aws_vpc.vpc.id}" cidr_block = "${var.public_subnet_cidr}" map_public_ip_on_launch = true tags = { @@ -30,8 +30,8 @@ resource "aws_subnet" "publicsubnet" { } # Create routeTable -resource "aws_route_table" "publicroute" { - vpc_id = "${aws_vpc.MAIN.id}" +resource "aws_route_table" "public" { + vpc_id = "${aws_vpc.vpc.id}" route { cidr_block = "0.0.0.0/0" gateway_id = "${aws_internet_gateway.IGW.id}" @@ -43,14 +43,14 @@ resource "aws_route_table" "publicroute" { } resource "aws_main_route_table_association" "mainRTB" { - vpc_id = "${aws_vpc.MAIN.id}" - route_table_id = "${aws_route_table.publicroute.id}" + vpc_id = "${aws_vpc.vpc.id}" + route_table_id = "${aws_route_table.public.id}" } ## Create security group resource "aws_security_group" "security" { name = "lufi-master-sg" description = "allow all traffic" - vpc_id = "${aws_vpc.MAIN.id}" + vpc_id = "${aws_vpc.vpc.id}" ingress { description = "allow all traffic" @@ -82,9 +82,20 @@ resource "aws_key_pair" "genkey" { public_key = "${file(var.public_key)}" } +# Add ubuntu AMI +data "aws_ami" "ubuntu" { + most_recent = true + owners = ["099720109477"] + + filter { + name = "name" + values = ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"] + } +} + # Craete ec2 instance resource "aws_instance" "ec2_instance" { - ami = "ami-04505e74c0741db8d" + ami = "${data.aws_ami.ubuntu.id}" instance_type = "t2.medium" associate_public_ip_address = "true" subnet_id = "${aws_subnet.publicsubnet.id}"