Applied ansible styling best practices and Terraform data sorces
This commit is contained in:
parent
3f1d8d822b
commit
17bcb2684f
|
@ -9,10 +9,10 @@ Role Variables
|
||||||
| `app_dir` | /var/www/lufi | Set the application directory for the best practice |
|
| `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_owner` | www-data | Set the application user for the best practice |
|
||||||
| `lufi_group` | www-data | Set the application group 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. |
|
| `_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 |
|
| `_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 |
|
| `_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 |
|
| `_server_name` | IP address (or) CNAME/FQDN | Mention the Server Name for the Nginx configurations |
|
||||||
|
|
||||||
Sample example of use in a playbook
|
Sample example of use in a playbook
|
||||||
--------------
|
--------------
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
chdir: "{{ app_dir }}"
|
chdir: "{{ app_dir }}"
|
||||||
|
|
||||||
- name: Upload application file
|
- name: Upload application file
|
||||||
template:
|
ansible.builtin.template:
|
||||||
src: ../templates/lufi.conf.j2
|
src: ../templates/lufi.conf.j2
|
||||||
dest: "{{ app_dir }}/lufi.conf"
|
dest: "{{ app_dir }}/lufi.conf"
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@
|
||||||
chdir: "{{ app_dir }}"
|
chdir: "{{ app_dir }}"
|
||||||
|
|
||||||
- name: Nginx configuration file add
|
- name: Nginx configuration file add
|
||||||
template:
|
ansible.builtin.template:
|
||||||
src: ../templates/app.conf
|
src: ../templates/app.conf
|
||||||
dest: /etc/nginx/conf.d/
|
dest: /etc/nginx/conf.d/
|
||||||
mode: '0644'
|
mode: '0644'
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
|
#dependencies.yml
|
||||||
|
---
|
||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
apt:
|
ansible.builtin.apt:
|
||||||
name:
|
name:
|
||||||
- nginx
|
- nginx
|
||||||
- build-essential
|
- build-essential
|
||||||
|
@ -12,6 +14,6 @@
|
||||||
state: present
|
state: present
|
||||||
|
|
||||||
- name: Install Postgress Dev Packages
|
- name: Install Postgress Dev Packages
|
||||||
apt:
|
ansible.builtin.apt:
|
||||||
name:
|
name:
|
||||||
- libpq-dev
|
- libpq-dev
|
|
@ -21,12 +21,12 @@
|
||||||
# Put a way to contact you here and uncomment it
|
# Put a way to contact you here and uncomment it
|
||||||
# You can put some HTML in it
|
# You can put some HTML in it
|
||||||
# MANDATORY
|
# MANDATORY
|
||||||
contact => '<a href="https://{{ contact }}">Contact page</a>',
|
contact => '<a href="https://{{ _contact }}">Contact page</a>',
|
||||||
|
|
||||||
# Put an URL or an email address to receive file reports and uncomment it
|
# Put an URL or an email address to receive file reports and uncomment it
|
||||||
# It's for make reporting illegal files easy for users
|
# It's for make reporting illegal files easy for users
|
||||||
# MANDATORY
|
# MANDATORY
|
||||||
report => '{{ report }}',
|
report => '{{ _report }}',
|
||||||
|
|
||||||
# Array of random strings used to encrypt cookies
|
# Array of random strings used to encrypt cookies
|
||||||
# optional, default is ['fdjsofjoihrei'], PLEASE, CHANGE IT
|
# optional, default is ['fdjsofjoihrei'], PLEASE, CHANGE IT
|
||||||
|
|
|
@ -5,12 +5,12 @@ lufi_owner: "www-data"
|
||||||
|
|
||||||
lufi_group: "www-data"
|
lufi_group: "www-data"
|
||||||
|
|
||||||
contact: "contact.example.com"
|
|
||||||
|
|
||||||
report: "report@example.com"
|
|
||||||
|
|
||||||
app_dir: ""
|
app_dir: ""
|
||||||
|
|
||||||
project_version: ""
|
_contact: "contact.example.com"
|
||||||
|
|
||||||
servername: ""
|
_report: "report@example.com"
|
||||||
|
|
||||||
|
_project_version: ""
|
||||||
|
|
||||||
|
_servername: ""
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#Create the VPC
|
#Create the VPC
|
||||||
resource "aws_vpc" "MAIN" {
|
resource "aws_vpc" "vpc" {
|
||||||
cidr_block = "${var.vpc_cidr}"
|
cidr_block = "${var.vpc_cidr}"
|
||||||
enable_dns_hostnames = true
|
enable_dns_hostnames = true
|
||||||
enable_dns_support = true
|
enable_dns_support = true
|
||||||
|
@ -12,7 +12,7 @@ resource "aws_vpc" "MAIN" {
|
||||||
# Create InternetGateWay and attach to VPC
|
# Create InternetGateWay and attach to VPC
|
||||||
|
|
||||||
resource "aws_internet_gateway" "IGW" {
|
resource "aws_internet_gateway" "IGW" {
|
||||||
vpc_id = "${aws_vpc.MAIN.id}"
|
vpc_id = "${aws_vpc.vpc.id}"
|
||||||
tags = {
|
tags = {
|
||||||
"Name" = "lufi-master-igw"
|
"Name" = "lufi-master-igw"
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ resource "aws_internet_gateway" "IGW" {
|
||||||
# Create a public subnet
|
# Create a public subnet
|
||||||
|
|
||||||
resource "aws_subnet" "publicsubnet" {
|
resource "aws_subnet" "publicsubnet" {
|
||||||
vpc_id = "${aws_vpc.MAIN.id}"
|
vpc_id = "${aws_vpc.vpc.id}"
|
||||||
cidr_block = "${var.public_subnet_cidr}"
|
cidr_block = "${var.public_subnet_cidr}"
|
||||||
map_public_ip_on_launch = true
|
map_public_ip_on_launch = true
|
||||||
tags = {
|
tags = {
|
||||||
|
@ -30,8 +30,8 @@ resource "aws_subnet" "publicsubnet" {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Create routeTable
|
# Create routeTable
|
||||||
resource "aws_route_table" "publicroute" {
|
resource "aws_route_table" "public" {
|
||||||
vpc_id = "${aws_vpc.MAIN.id}"
|
vpc_id = "${aws_vpc.vpc.id}"
|
||||||
route {
|
route {
|
||||||
cidr_block = "0.0.0.0/0"
|
cidr_block = "0.0.0.0/0"
|
||||||
gateway_id = "${aws_internet_gateway.IGW.id}"
|
gateway_id = "${aws_internet_gateway.IGW.id}"
|
||||||
|
@ -43,14 +43,14 @@ resource "aws_route_table" "publicroute" {
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_main_route_table_association" "mainRTB" {
|
resource "aws_main_route_table_association" "mainRTB" {
|
||||||
vpc_id = "${aws_vpc.MAIN.id}"
|
vpc_id = "${aws_vpc.vpc.id}"
|
||||||
route_table_id = "${aws_route_table.publicroute.id}"
|
route_table_id = "${aws_route_table.public.id}"
|
||||||
}
|
}
|
||||||
## Create security group
|
## Create security group
|
||||||
resource "aws_security_group" "security" {
|
resource "aws_security_group" "security" {
|
||||||
name = "lufi-master-sg"
|
name = "lufi-master-sg"
|
||||||
description = "allow all traffic"
|
description = "allow all traffic"
|
||||||
vpc_id = "${aws_vpc.MAIN.id}"
|
vpc_id = "${aws_vpc.vpc.id}"
|
||||||
|
|
||||||
ingress {
|
ingress {
|
||||||
description = "allow all traffic"
|
description = "allow all traffic"
|
||||||
|
@ -82,9 +82,20 @@ resource "aws_key_pair" "genkey" {
|
||||||
public_key = "${file(var.public_key)}"
|
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
|
# Craete ec2 instance
|
||||||
resource "aws_instance" "ec2_instance" {
|
resource "aws_instance" "ec2_instance" {
|
||||||
ami = "ami-04505e74c0741db8d"
|
ami = "${data.aws_ami.ubuntu.id}"
|
||||||
instance_type = "t2.medium"
|
instance_type = "t2.medium"
|
||||||
associate_public_ip_address = "true"
|
associate_public_ip_address = "true"
|
||||||
subnet_id = "${aws_subnet.publicsubnet.id}"
|
subnet_id = "${aws_subnet.publicsubnet.id}"
|
||||||
|
|
Loading…
Reference in New Issue