From bdae3f768aeebb6c105af2c5829eda89780a3437 Mon Sep 17 00:00:00 2001 From: arsengspeyan Date: Fri, 5 Jul 2024 15:37:12 +0400 Subject: [PATCH 01/34] packer and ansible for postgresdb --- ansible/setup_postgresql.yml | 31 +++++++++++++++++++++++++++++++ packer/PosgresawsTemplate.json | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 ansible/setup_postgresql.yml create mode 100644 packer/PosgresawsTemplate.json diff --git a/ansible/setup_postgresql.yml b/ansible/setup_postgresql.yml new file mode 100644 index 0000000..88dcfc0 --- /dev/null +++ b/ansible/setup_postgresql.yml @@ -0,0 +1,31 @@ +--- +- name: Set up PostgreSQL + hosts: all + become: yes + tasks: + - name: Update and install PostgreSQL + apt: + update_cache: yes + name: postgresql + state: present + + - name: Ensure PostgreSQL is running and enabled + systemd: + name: postgresql + state: started + enabled: yes + + - name: Create PostgreSQL user + become_user: postgres + postgresql_user: + name: "{{ postgres_user }}" + password: "{{ postgres_password }}" + state: present + + - name: Create PostgreSQL database + become_user: postgres + postgresql_db: + name: "{{ postgres_db }}" + owner: "{{ postgres_user }}" + state: present + diff --git a/packer/PosgresawsTemplate.json b/packer/PosgresawsTemplate.json new file mode 100644 index 0000000..a4d53be --- /dev/null +++ b/packer/PosgresawsTemplate.json @@ -0,0 +1,33 @@ +{ + "variables": { + "aws_access_key": "{{env `AWS_ACCESS_KEY_ID`}}", + "aws_secret_key": "{{env `AWS_SECRET_ACCESS_KEY`}}", + "region": "us-east-1", + "source_ami": "ami-0a0e5d9c7acc336f1", + "instance_type": "t2.micro", + "ssh_username": "ubuntu" + "postgres_user": "{{ env `POSTGRES_USER` }}", + "postgres_password": "{{ env `POSTGRES_PASSWORD` }}", + "postgres_db": "{{ env `POSTGRES_DB` }}" + }, + "builders": [ + { + "type": "amazon-ebs", + "region": "{{user `region`}}", + "source_ami": "{{user `source_ami`}}", + "instance_type": "{{user `instance_type`}}", + "ssh_username": "{{user `ssh_username`}}", + "ami_name": "packer-postgresql-{{timestamp}}" + } + ], + "provisioners": [ + { + "type": "ansible", + "playbook_file": "../ansible/setup_postgresql.yml" + "extra_arguments": [ + "--extra-vars", "postgres_user={{ user `postgres_user` }} postgres_password={{ user `postgres_password` }} postgres_db={{ user `postgres_db` }}" + ] + } + ] +} + From 2af70a5fc1d1b50f83c16f7016316d80af08ec76 Mon Sep 17 00:00:00 2001 From: arsengspeyan <109848618+arsengspeyan@users.noreply.github.com> Date: Fri, 5 Jul 2024 17:01:34 +0400 Subject: [PATCH 02/34] Update PosgresawsTemplate.json --- packer/PosgresawsTemplate.json | 62 +++++++++++++++++----------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/packer/PosgresawsTemplate.json b/packer/PosgresawsTemplate.json index a4d53be..3edeadb 100644 --- a/packer/PosgresawsTemplate.json +++ b/packer/PosgresawsTemplate.json @@ -1,33 +1,33 @@ { - "variables": { - "aws_access_key": "{{env `AWS_ACCESS_KEY_ID`}}", - "aws_secret_key": "{{env `AWS_SECRET_ACCESS_KEY`}}", - "region": "us-east-1", - "source_ami": "ami-0a0e5d9c7acc336f1", - "instance_type": "t2.micro", - "ssh_username": "ubuntu" - "postgres_user": "{{ env `POSTGRES_USER` }}", - "postgres_password": "{{ env `POSTGRES_PASSWORD` }}", - "postgres_db": "{{ env `POSTGRES_DB` }}" - }, - "builders": [ - { - "type": "amazon-ebs", - "region": "{{user `region`}}", - "source_ami": "{{user `source_ami`}}", - "instance_type": "{{user `instance_type`}}", - "ssh_username": "{{user `ssh_username`}}", - "ami_name": "packer-postgresql-{{timestamp}}" - } - ], - "provisioners": [ - { - "type": "ansible", - "playbook_file": "../ansible/setup_postgresql.yml" - "extra_arguments": [ - "--extra-vars", "postgres_user={{ user `postgres_user` }} postgres_password={{ user `postgres_password` }} postgres_db={{ user `postgres_db` }}" - ] - } - ] + "variables":{ + "aws_access_key":"{{env `AWS_ACCESS_KEY_ID`}}", + "aws_secret_key":"{{env `AWS_SECRET_ACCESS_KEY`}}", + "region":"us-east-1", + "source_ami":"ami-0a0e5d9c7acc336f1", + "instance_type":"t2.micro", + "ssh_username":"ubuntu", // Added comma to separate key-value pairs + "postgres_user":"{{ env `POSTGRES_USER` }}", + "postgres_password":"{{ env `POSTGRES_PASSWORD` }}", + "postgres_db":"{{ env `POSTGRES_DB` }}" + }, + "builders":[ + { + "type":"amazon-ebs", + "region":"{{user `region`}}", + "source_ami":"{{user `source_ami`}}", + "instance_type":"{{user `instance_type`}}", + "ssh_username":"{{user `ssh_username`}}", + "ami_name":"packer-postgresql-{{timestamp}}" + } + ], + "provisioners":[ + { + "type":"ansible", + "playbook_file":"../ansible/setup_postgresql.yml", // Added comma to separate key-value pairs + "extra_arguments":[ + "--extra-vars", + "postgres_user={{ user `postgres_user` }} postgres_password={{ user `postgres_password` }} postgres_db={{ user `postgres_db` }}" + ] + } + ] } - From 76f3f51394c9dd92e15ce1224725ad6c97b5c59f Mon Sep 17 00:00:00 2001 From: arsengspeyan <109848618+arsengspeyan@users.noreply.github.com> Date: Fri, 5 Jul 2024 17:02:16 +0400 Subject: [PATCH 03/34] Update PosgresawsTemplate.json --- packer/PosgresawsTemplate.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packer/PosgresawsTemplate.json b/packer/PosgresawsTemplate.json index 3edeadb..1afa356 100644 --- a/packer/PosgresawsTemplate.json +++ b/packer/PosgresawsTemplate.json @@ -5,7 +5,7 @@ "region":"us-east-1", "source_ami":"ami-0a0e5d9c7acc336f1", "instance_type":"t2.micro", - "ssh_username":"ubuntu", // Added comma to separate key-value pairs + "ssh_username":"ubuntu", "postgres_user":"{{ env `POSTGRES_USER` }}", "postgres_password":"{{ env `POSTGRES_PASSWORD` }}", "postgres_db":"{{ env `POSTGRES_DB` }}" @@ -23,7 +23,7 @@ "provisioners":[ { "type":"ansible", - "playbook_file":"../ansible/setup_postgresql.yml", // Added comma to separate key-value pairs + "playbook_file":"../ansible/setup_postgresql.yml", "extra_arguments":[ "--extra-vars", "postgres_user={{ user `postgres_user` }} postgres_password={{ user `postgres_password` }} postgres_db={{ user `postgres_db` }}" From ab54d28fd3303ce6ccf026947a47d918d1f06719 Mon Sep 17 00:00:00 2001 From: arsengspeyan <109848618+arsengspeyan@users.noreply.github.com> Date: Fri, 5 Jul 2024 17:11:20 +0400 Subject: [PATCH 04/34] Update PosgresawsTemplate.json --- packer/PosgresawsTemplate.json | 61 +++++++++++++++++----------------- 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/packer/PosgresawsTemplate.json b/packer/PosgresawsTemplate.json index 1afa356..c733b16 100644 --- a/packer/PosgresawsTemplate.json +++ b/packer/PosgresawsTemplate.json @@ -1,33 +1,32 @@ { - "variables":{ - "aws_access_key":"{{env `AWS_ACCESS_KEY_ID`}}", - "aws_secret_key":"{{env `AWS_SECRET_ACCESS_KEY`}}", - "region":"us-east-1", - "source_ami":"ami-0a0e5d9c7acc336f1", - "instance_type":"t2.micro", - "ssh_username":"ubuntu", - "postgres_user":"{{ env `POSTGRES_USER` }}", - "postgres_password":"{{ env `POSTGRES_PASSWORD` }}", - "postgres_db":"{{ env `POSTGRES_DB` }}" - }, - "builders":[ - { - "type":"amazon-ebs", - "region":"{{user `region`}}", - "source_ami":"{{user `source_ami`}}", - "instance_type":"{{user `instance_type`}}", - "ssh_username":"{{user `ssh_username`}}", - "ami_name":"packer-postgresql-{{timestamp}}" - } - ], - "provisioners":[ - { - "type":"ansible", - "playbook_file":"../ansible/setup_postgresql.yml", - "extra_arguments":[ - "--extra-vars", - "postgres_user={{ user `postgres_user` }} postgres_password={{ user `postgres_password` }} postgres_db={{ user `postgres_db` }}" - ] - } - ] + "variables": { + "aws_access_key": "{{env `AWS_ACCESS_KEY_ID`}}", + "aws_secret_key": "{{env `AWS_SECRET_ACCESS_KEY`}}", + "region": "us-east-1", + "source_ami": "ami-0a0e5d9c7acc336f1", + "instance_type": "t2.micro", + "ssh_username": "ubuntu", // Note the comma here + "postgres_user": "{{ env `POSTGRES_USER` }}", + "postgres_password": "{{ env `POSTGRES_PASSWORD` }}", + "postgres_db": "{{ env `POSTGRES_DB` }}" + }, + "builders": [ + { + "type": "amazon-ebs", + "region": "{{user `region`}}", + "source_ami": "{{user `source_ami`}}", + "instance_type": "{{user `instance_type`}}", + "ssh_username": "{{user `ssh_username`}}", + "ami_name": "packer-postgresql-{{timestamp}}" + } + ], + "provisioners": [ + { + "type": "ansible", + "playbook_file": "../ansible/setup_postgresql.yml", // Note the comma here + "extra_arguments": [ + "--extra-vars", "postgres_user={{ user `postgres_user` }} postgres_password={{ user `postgres_password` }} postgres_db={{ user `postgres_db` }}" + ] + } + ] } From 5516eb2b0305cb74e6a3ab146dea2d0e74aad4f2 Mon Sep 17 00:00:00 2001 From: arsengspeyan <109848618+arsengspeyan@users.noreply.github.com> Date: Fri, 5 Jul 2024 17:11:37 +0400 Subject: [PATCH 05/34] Update PosgresawsTemplate.json --- packer/PosgresawsTemplate.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packer/PosgresawsTemplate.json b/packer/PosgresawsTemplate.json index c733b16..f570eec 100644 --- a/packer/PosgresawsTemplate.json +++ b/packer/PosgresawsTemplate.json @@ -5,7 +5,7 @@ "region": "us-east-1", "source_ami": "ami-0a0e5d9c7acc336f1", "instance_type": "t2.micro", - "ssh_username": "ubuntu", // Note the comma here + "ssh_username": "ubuntu", "postgres_user": "{{ env `POSTGRES_USER` }}", "postgres_password": "{{ env `POSTGRES_PASSWORD` }}", "postgres_db": "{{ env `POSTGRES_DB` }}" @@ -23,7 +23,7 @@ "provisioners": [ { "type": "ansible", - "playbook_file": "../ansible/setup_postgresql.yml", // Note the comma here + "playbook_file": "../ansible/setup_postgresql.yml", "extra_arguments": [ "--extra-vars", "postgres_user={{ user `postgres_user` }} postgres_password={{ user `postgres_password` }} postgres_db={{ user `postgres_db` }}" ] From a290bce10d287555ec1f6f1a98ddfbf37e90b9fa Mon Sep 17 00:00:00 2001 From: arsengspeyan <109848618+arsengspeyan@users.noreply.github.com> Date: Fri, 5 Jul 2024 17:39:50 +0400 Subject: [PATCH 06/34] Update and rename PosgresawsTemplate.json to PosgresawsTemplate.hcl --- packer/PosgresawsTemplate.hcl | 42 ++++++++++++++++++++++++++++++++++ packer/PosgresawsTemplate.json | 32 -------------------------- 2 files changed, 42 insertions(+), 32 deletions(-) create mode 100644 packer/PosgresawsTemplate.hcl delete mode 100644 packer/PosgresawsTemplate.json diff --git a/packer/PosgresawsTemplate.hcl b/packer/PosgresawsTemplate.hcl new file mode 100644 index 0000000..3c45374 --- /dev/null +++ b/packer/PosgresawsTemplate.hcl @@ -0,0 +1,42 @@ +packer { + required_plugins { + amazon = { + version = ">= 0.0.1" + source = "github.com/hashicorp/amazon" + } + } +} + +variable "aws_access_key" {} +variable "aws_secret_key" {} +variable "region" { + default = "us-east-1" +} +variable "source_ami" { + default = "ami-0a0e5d9c7acc336f1" +} +variable "instance_type" { + default = "t2.micro" +} +variable "ssh_username" { + default = "ubuntu" +} +variable "postgres_user" {} +variable "postgres_password" {} +variable "postgres_db" {} + +builder { + type = "amazon-ebs" + region = var.region + source_ami = var.source_ami + instance_type = var.instance_type + ssh_username = var.ssh_username + ami_name = "packer-postgresql-{{timestamp}}" +} + +provisioner "ansible" { + playbook_file = "../ansible/setup_postgresql.yml" + extra_arguments = [ + "--extra-vars", "postgres_user=${var.postgres_user} postgres_password=${var.postgres_password} postgres_db=${var.postgres_db}" + ] +} diff --git a/packer/PosgresawsTemplate.json b/packer/PosgresawsTemplate.json deleted file mode 100644 index f570eec..0000000 --- a/packer/PosgresawsTemplate.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "variables": { - "aws_access_key": "{{env `AWS_ACCESS_KEY_ID`}}", - "aws_secret_key": "{{env `AWS_SECRET_ACCESS_KEY`}}", - "region": "us-east-1", - "source_ami": "ami-0a0e5d9c7acc336f1", - "instance_type": "t2.micro", - "ssh_username": "ubuntu", - "postgres_user": "{{ env `POSTGRES_USER` }}", - "postgres_password": "{{ env `POSTGRES_PASSWORD` }}", - "postgres_db": "{{ env `POSTGRES_DB` }}" - }, - "builders": [ - { - "type": "amazon-ebs", - "region": "{{user `region`}}", - "source_ami": "{{user `source_ami`}}", - "instance_type": "{{user `instance_type`}}", - "ssh_username": "{{user `ssh_username`}}", - "ami_name": "packer-postgresql-{{timestamp}}" - } - ], - "provisioners": [ - { - "type": "ansible", - "playbook_file": "../ansible/setup_postgresql.yml", - "extra_arguments": [ - "--extra-vars", "postgres_user={{ user `postgres_user` }} postgres_password={{ user `postgres_password` }} postgres_db={{ user `postgres_db` }}" - ] - } - ] -} From 9d2b8187e4cb41e6025e3d472003e4cb0dd4c2cd Mon Sep 17 00:00:00 2001 From: arsengspeyan <109848618+arsengspeyan@users.noreply.github.com> Date: Fri, 5 Jul 2024 17:45:04 +0400 Subject: [PATCH 07/34] Update and rename PosgresawsTemplate.hcl to PosgresawsTemplate.pkr.hcl --- packer/{PosgresawsTemplate.hcl => PosgresawsTemplate.pkr.hcl} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename packer/{PosgresawsTemplate.hcl => PosgresawsTemplate.pkr.hcl} (100%) diff --git a/packer/PosgresawsTemplate.hcl b/packer/PosgresawsTemplate.pkr.hcl similarity index 100% rename from packer/PosgresawsTemplate.hcl rename to packer/PosgresawsTemplate.pkr.hcl From 8bb842f333ddb0b6ee3ebbe08f9b17b8de7ddfcd Mon Sep 17 00:00:00 2001 From: arsengspeyan <109848618+arsengspeyan@users.noreply.github.com> Date: Fri, 5 Jul 2024 17:48:37 +0400 Subject: [PATCH 08/34] Update PosgresawsTemplate.pkr.hcl --- packer/PosgresawsTemplate.pkr.hcl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packer/PosgresawsTemplate.pkr.hcl b/packer/PosgresawsTemplate.pkr.hcl index 3c45374..f0c7c93 100644 --- a/packer/PosgresawsTemplate.pkr.hcl +++ b/packer/PosgresawsTemplate.pkr.hcl @@ -1,6 +1,6 @@ packer { required_plugins { - amazon = { + amazon { version = ">= 0.0.1" source = "github.com/hashicorp/amazon" } From 96b10696b19df461a7405b2dfc3d9b434a50e75b Mon Sep 17 00:00:00 2001 From: arsengspeyan <109848618+arsengspeyan@users.noreply.github.com> Date: Fri, 5 Jul 2024 17:56:23 +0400 Subject: [PATCH 09/34] Update PosgresawsTemplate.pkr.hcl --- packer/PosgresawsTemplate.pkr.hcl | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/packer/PosgresawsTemplate.pkr.hcl b/packer/PosgresawsTemplate.pkr.hcl index f0c7c93..be56f10 100644 --- a/packer/PosgresawsTemplate.pkr.hcl +++ b/packer/PosgresawsTemplate.pkr.hcl @@ -1,12 +1,3 @@ -packer { - required_plugins { - amazon { - version = ">= 0.0.1" - source = "github.com/hashicorp/amazon" - } - } -} - variable "aws_access_key" {} variable "aws_secret_key" {} variable "region" { @@ -25,7 +16,7 @@ variable "postgres_user" {} variable "postgres_password" {} variable "postgres_db" {} -builder { +build { type = "amazon-ebs" region = var.region source_ami = var.source_ami From 9e47e1453d4d7ae7114563179d4dc022ab6842e2 Mon Sep 17 00:00:00 2001 From: arsengspeyan <109848618+arsengspeyan@users.noreply.github.com> Date: Fri, 5 Jul 2024 18:09:49 +0400 Subject: [PATCH 10/34] Update PosgresawsTemplate.pkr.hcl --- packer/PosgresawsTemplate.pkr.hcl | 62 ++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 17 deletions(-) diff --git a/packer/PosgresawsTemplate.pkr.hcl b/packer/PosgresawsTemplate.pkr.hcl index be56f10..d022bca 100644 --- a/packer/PosgresawsTemplate.pkr.hcl +++ b/packer/PosgresawsTemplate.pkr.hcl @@ -1,5 +1,21 @@ -variable "aws_access_key" {} -variable "aws_secret_key" {} +packer { + required_plugins { + amazon { + version = ">= 0.0.1" + source = "github.com/hashicorp/amazon" + } + } +} + +# Retrieve AWS credentials from GitHub Secrets +variable "aws_access_key" { + default = "" +} + +variable "aws_secret_key" { + default = "" +} + variable "region" { default = "us-east-1" } @@ -12,22 +28,34 @@ variable "instance_type" { variable "ssh_username" { default = "ubuntu" } -variable "postgres_user" {} -variable "postgres_password" {} -variable "postgres_db" {} +variable "postgres_user" { + default = "" +} + +variable "postgres_password" { + default = "" +} + +variable "postgres_db" { + default = "" +} + +# Define the build block for creating the AMI build { - type = "amazon-ebs" - region = var.region - source_ami = var.source_ami - instance_type = var.instance_type - ssh_username = var.ssh_username - ami_name = "packer-postgresql-{{timestamp}}" -} - -provisioner "ansible" { - playbook_file = "../ansible/setup_postgresql.yml" - extra_arguments = [ - "--extra-vars", "postgres_user=${var.postgres_user} postgres_password=${var.postgres_password} postgres_db=${var.postgres_db}" + sources = [ + "amazon-ebs.source_ami" ] + + communicator = "ssh" + ssh_username = var.ssh_username + ami_name = "packer-postgresql-{{timestamp}}" + + # Define provisioners within the build block + provisioner "ansible" { + playbook_file = "../ansible/setup_postgresql.yml" + extra_arguments = [ + "--extra-vars", "postgres_user=${var.postgres_user} postgres_password=${var.postgres_password} postgres_db=${var.postgres_db}" + ] + } } From f49afecba9c4585656a0b48dcaf43128978422a9 Mon Sep 17 00:00:00 2001 From: arsengspeyan <109848618+arsengspeyan@users.noreply.github.com> Date: Fri, 5 Jul 2024 18:21:07 +0400 Subject: [PATCH 11/34] Update PosgresawsTemplate.pkr.hcl --- packer/PosgresawsTemplate.pkr.hcl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packer/PosgresawsTemplate.pkr.hcl b/packer/PosgresawsTemplate.pkr.hcl index d022bca..bbf016f 100644 --- a/packer/PosgresawsTemplate.pkr.hcl +++ b/packer/PosgresawsTemplate.pkr.hcl @@ -1,6 +1,6 @@ packer { required_plugins { - amazon { + amazon = { version = ">= 0.0.1" source = "github.com/hashicorp/amazon" } From 2722dd0196da1cf6d08013d9d75153e4439db967 Mon Sep 17 00:00:00 2001 From: arsengspeyan <109848618+arsengspeyan@users.noreply.github.com> Date: Fri, 5 Jul 2024 18:33:54 +0400 Subject: [PATCH 12/34] Update PosgresawsTemplate.pkr.hcl --- packer/PosgresawsTemplate.pkr.hcl | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/packer/PosgresawsTemplate.pkr.hcl b/packer/PosgresawsTemplate.pkr.hcl index bbf016f..4b04a94 100644 --- a/packer/PosgresawsTemplate.pkr.hcl +++ b/packer/PosgresawsTemplate.pkr.hcl @@ -19,12 +19,15 @@ variable "aws_secret_key" { variable "region" { default = "us-east-1" } + variable "source_ami" { default = "ami-0a0e5d9c7acc336f1" } + variable "instance_type" { default = "t2.micro" } + variable "ssh_username" { default = "ubuntu" } @@ -47,15 +50,20 @@ build { "amazon-ebs.source_ami" ] - communicator = "ssh" - ssh_username = var.ssh_username - ami_name = "packer-postgresql-{{timestamp}}" - - # Define provisioners within the build block provisioner "ansible" { playbook_file = "../ansible/setup_postgresql.yml" extra_arguments = [ "--extra-vars", "postgres_user=${var.postgres_user} postgres_password=${var.postgres_password} postgres_db=${var.postgres_db}" ] } + + # This section defines the template for building the AMI + builder { + type = "amazon-ebs" + region = var.region + source_ami = var.source_ami + instance_type = var.instance_type + ssh_username = var.ssh_username + ami_name = "packer-postgresql-{{timestamp}}" + } } From 230eeb43598eacf1949b39b9b37bb6a121deebe1 Mon Sep 17 00:00:00 2001 From: arsengspeyan <109848618+arsengspeyan@users.noreply.github.com> Date: Fri, 5 Jul 2024 18:36:19 +0400 Subject: [PATCH 13/34] Update PosgresawsTemplate.pkr.hcl From 4705fbdb0a68062c2e18bf7607a078e1ce124314 Mon Sep 17 00:00:00 2001 From: arsengspeyan <109848618+arsengspeyan@users.noreply.github.com> Date: Fri, 5 Jul 2024 18:38:31 +0400 Subject: [PATCH 14/34] Update PosgresawsTemplate.pkr.hcl From 0a481a6cbba2c6604dae76f9c401c9c085747d1b Mon Sep 17 00:00:00 2001 From: arsengspeyan <109848618+arsengspeyan@users.noreply.github.com> Date: Fri, 5 Jul 2024 18:44:56 +0400 Subject: [PATCH 15/34] Update and rename PosgresawsTemplate.pkr.hcl to PosgresawsTemplate.json --- packer/PosgresawsTemplate.json | 35 ++++++++++++++++ packer/PosgresawsTemplate.pkr.hcl | 69 ------------------------------- 2 files changed, 35 insertions(+), 69 deletions(-) create mode 100644 packer/PosgresawsTemplate.json delete mode 100644 packer/PosgresawsTemplate.pkr.hcl diff --git a/packer/PosgresawsTemplate.json b/packer/PosgresawsTemplate.json new file mode 100644 index 0000000..6dfe7a6 --- /dev/null +++ b/packer/PosgresawsTemplate.json @@ -0,0 +1,35 @@ +{ + "builders": [ + { + "type": "amazon-ebs", + "region": "{{user `region`}}", + "source_ami": "{{user `source_ami`}}", + "instance_type": "{{user `instance_type`}}", + "ssh_username": "{{user `ssh_username`}}", + "ami_name": "packer-postgresql-{{timestamp}}", + "access_key": "{{env `AWS_ACCESS_KEY_ID`}}", + "secret_key": "{{env `AWS_SECRET_ACCESS_KEY`}}" + } + ], + "provisioners": [ + { + "type": "ansible", + "playbook_file": "../ansible/setup_postgresql.yml", + "extra_arguments": [ + "--extra-vars", "postgres_user={{env `POSTGRES_USER`}} postgres_password={{env `POSTGRES_PASSWORD`}} postgres_db={{env `POSTGRES_DB`}}" + ] + } + ], + "variables": { + "region": "us-east-1", + "source_ami": "ami-0a0e5d9c7acc336f1", + "instance_type": "t2.micro", + "ssh_username": "ubuntu" + }, + "required_plugins": { + "amazon": { + "version": ">= 0.0.1", + "source": "github.com/hashicorp/amazon" + } + } +} diff --git a/packer/PosgresawsTemplate.pkr.hcl b/packer/PosgresawsTemplate.pkr.hcl deleted file mode 100644 index 4b04a94..0000000 --- a/packer/PosgresawsTemplate.pkr.hcl +++ /dev/null @@ -1,69 +0,0 @@ -packer { - required_plugins { - amazon = { - version = ">= 0.0.1" - source = "github.com/hashicorp/amazon" - } - } -} - -# Retrieve AWS credentials from GitHub Secrets -variable "aws_access_key" { - default = "" -} - -variable "aws_secret_key" { - default = "" -} - -variable "region" { - default = "us-east-1" -} - -variable "source_ami" { - default = "ami-0a0e5d9c7acc336f1" -} - -variable "instance_type" { - default = "t2.micro" -} - -variable "ssh_username" { - default = "ubuntu" -} - -variable "postgres_user" { - default = "" -} - -variable "postgres_password" { - default = "" -} - -variable "postgres_db" { - default = "" -} - -# Define the build block for creating the AMI -build { - sources = [ - "amazon-ebs.source_ami" - ] - - provisioner "ansible" { - playbook_file = "../ansible/setup_postgresql.yml" - extra_arguments = [ - "--extra-vars", "postgres_user=${var.postgres_user} postgres_password=${var.postgres_password} postgres_db=${var.postgres_db}" - ] - } - - # This section defines the template for building the AMI - builder { - type = "amazon-ebs" - region = var.region - source_ami = var.source_ami - instance_type = var.instance_type - ssh_username = var.ssh_username - ami_name = "packer-postgresql-{{timestamp}}" - } -} From 1f3c3eab6a1f1b89fe74f330a543c15845efc381 Mon Sep 17 00:00:00 2001 From: arsengspeyan <109848618+arsengspeyan@users.noreply.github.com> Date: Fri, 5 Jul 2024 18:48:45 +0400 Subject: [PATCH 16/34] Rename PosgresawsTemplate.json to PosgresawsTemplate.pkr.json --- packer/{PosgresawsTemplate.json => PosgresawsTemplate.pkr.json} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename packer/{PosgresawsTemplate.json => PosgresawsTemplate.pkr.json} (100%) diff --git a/packer/PosgresawsTemplate.json b/packer/PosgresawsTemplate.pkr.json similarity index 100% rename from packer/PosgresawsTemplate.json rename to packer/PosgresawsTemplate.pkr.json From cb225a5ab0c65146688780e9558bbed230215bdb Mon Sep 17 00:00:00 2001 From: arsengspeyan <109848618+arsengspeyan@users.noreply.github.com> Date: Fri, 5 Jul 2024 18:56:20 +0400 Subject: [PATCH 17/34] Update PosgresawsTemplate.pkr.json --- packer/PosgresawsTemplate.pkr.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packer/PosgresawsTemplate.pkr.json b/packer/PosgresawsTemplate.pkr.json index 6dfe7a6..de880e6 100644 --- a/packer/PosgresawsTemplate.pkr.json +++ b/packer/PosgresawsTemplate.pkr.json @@ -16,7 +16,7 @@ "type": "ansible", "playbook_file": "../ansible/setup_postgresql.yml", "extra_arguments": [ - "--extra-vars", "postgres_user={{env `POSTGRES_USER`}} postgres_password={{env `POSTGRES_PASSWORD`}} postgres_db={{env `POSTGRES_DB`}}" + "--extra-vars", "postgres_user={{ env `POSTGRES_USER` }} postgres_password={{ env `POSTGRES_PASSWORD` }} postgres_db={{ env `POSTGRES_DB` }}" ] } ], From 9f38f199204fd4aab11aaabee600c0248049f76f Mon Sep 17 00:00:00 2001 From: arsengspeyan <109848618+arsengspeyan@users.noreply.github.com> Date: Fri, 5 Jul 2024 18:58:36 +0400 Subject: [PATCH 18/34] Update PosgresawsTemplate.pkr.json From 1b7bf564e143a453cee4bafade967fbe31d5c8a5 Mon Sep 17 00:00:00 2001 From: arsengspeyan <109848618+arsengspeyan@users.noreply.github.com> Date: Tue, 9 Jul 2024 22:06:37 +0400 Subject: [PATCH 19/34] Update setup_postgresql.yml --- ansible/setup_postgresql.yml | 86 +++++++++++++++++++++++++++++------- 1 file changed, 71 insertions(+), 15 deletions(-) diff --git a/ansible/setup_postgresql.yml b/ansible/setup_postgresql.yml index 88dcfc0..ab0314a 100644 --- a/ansible/setup_postgresql.yml +++ b/ansible/setup_postgresql.yml @@ -1,31 +1,87 @@ --- -- name: Set up PostgreSQL - hosts: all +- name: Set up PostgreSQL 14 locally + hosts: localhost + connection: local become: yes + vars: + db_name: "mydatabase" + postgres_password: "smartes" tasks: - - name: Update and install PostgreSQL + + - name: Install psycopg2 Python library + package: + name: python3-psycopg2 # This might vary based on your system, adjust as needed + state: present + become: yes + become_user: root + + + + - name: Add PostgreSQL APT repository key + apt_key: + url: https://www.postgresql.org/media/keys/ACCC4CF8.asc + state: present + + - name: Add PostgreSQL APT repository + apt_repository: + repo: deb http://apt.postgresql.org/pub/repos/apt/ {{ ansible_distribution_release }}-pgdg main + state: present + + - name: Update APT cache apt: update_cache: yes - name: postgresql + + - name: Install PostgreSQL 14 and related packages + apt: + name: + - postgresql-14 + - postgresql-client-14 + - postgresql-contrib-14 state: present - - name: Ensure PostgreSQL is running and enabled + - name: Ensure PostgreSQL service is running and enabled systemd: - name: postgresql + name: postgresql@14-main state: started enabled: yes - - name: Create PostgreSQL user + - name: Set PostgreSQL password become_user: postgres postgresql_user: - name: "{{ postgres_user }}" - password: "{{ postgres_password }}" - state: present + name: postgres + password: "{ postgres_password }" - - name: Create PostgreSQL database - become_user: postgres - postgresql_db: - name: "{{ postgres_db }}" - owner: "{{ postgres_user }}" + - name: Update pg_hba.conf to use md5 authentication for all users + community.postgresql.postgresql_pg_hba: + dest: /etc/postgresql/14/main/pg_hba.conf + contype: host + users: all + databases: all + method: md5 + address: 0.0.0.0/0 state: present + + - name: Update pg_hba.conf to use md5 authentication for local connections + community.postgresql.postgresql_pg_hba: + dest: /etc/postgresql/14/main/pg_hba.conf + contype: local + users: all + databases: all + method: md5 + state: present + + - name: Reload PostgreSQL to apply changes + systemd: + name: postgresql + state: reloaded + + + + + - name: Create a database + community.postgresql.postgresql_db: + name: "{{ db_name }}" + state: present + become: true + become_user: postgres From 913c6a8dd1c8a9bd09bb8a4a927f32c6110c1a0a Mon Sep 17 00:00:00 2001 From: arsengspeyan <109848618+arsengspeyan@users.noreply.github.com> Date: Tue, 9 Jul 2024 22:13:40 +0400 Subject: [PATCH 20/34] Update PosgresawsTemplate.pkr.json --- packer/PosgresawsTemplate.pkr.json | 88 +++++++++++++++++++----------- 1 file changed, 57 insertions(+), 31 deletions(-) diff --git a/packer/PosgresawsTemplate.pkr.json b/packer/PosgresawsTemplate.pkr.json index de880e6..af1785c 100644 --- a/packer/PosgresawsTemplate.pkr.json +++ b/packer/PosgresawsTemplate.pkr.json @@ -1,35 +1,61 @@ -{ - "builders": [ - { - "type": "amazon-ebs", - "region": "{{user `region`}}", - "source_ami": "{{user `source_ami`}}", - "instance_type": "{{user `instance_type`}}", - "ssh_username": "{{user `ssh_username`}}", - "ami_name": "packer-postgresql-{{timestamp}}", - "access_key": "{{env `AWS_ACCESS_KEY_ID`}}", - "secret_key": "{{env `AWS_SECRET_ACCESS_KEY`}}" +packer { + required_plugins { + amazon = { + version = ">= 1.3.1" + source = "github.com/hashicorp/amazon" } - ], - "provisioners": [ - { - "type": "ansible", - "playbook_file": "../ansible/setup_postgresql.yml", - "extra_arguments": [ - "--extra-vars", "postgres_user={{ env `POSTGRES_USER` }} postgres_password={{ env `POSTGRES_PASSWORD` }} postgres_db={{ env `POSTGRES_DB` }}" - ] - } - ], - "variables": { - "region": "us-east-1", - "source_ami": "ami-0a0e5d9c7acc336f1", - "instance_type": "t2.micro", - "ssh_username": "ubuntu" - }, - "required_plugins": { - "amazon": { - "version": ">= 0.0.1", - "source": "github.com/hashicorp/amazon" + ansible = { + version = "~> 1" + source = "github.com/hashicorp/ansible" } + } } + +source "amazon-ebs" "example" { + region = var.region + source_ami = var.source_ami + instance_type = var.instance_type + ssh_username = var.ssh_username + ami_name = "packer-postgresql" + access_key = var.aws_access_key_id + secret_key = var.aws_secret_access_key +} + +build { + sources = ["source.amazon-ebs.example"] + + provisioner "ansible" { + playbook_file = "../ansible/setup_postgresql.yml" + } +} + +variable "region" { + type = string + default = "us-west-1" +} + +variable "source_ami" { + type = string + default = "ami-0ecaad63ed3668fca" +} + +variable "instance_type" { + type = string + default = "t2.micro" +} + +variable "ssh_username" { + type = string + default = "ubuntu" +} + +variable "aws_access_key_id" { + type = string + sensitive = true +} + +variable "aws_secret_access_key" { + type = string + sensitive = true +} From aa86c72cda2ec2342b1b7f54d9d0302c1d4a1e7b Mon Sep 17 00:00:00 2001 From: arsengspeyan <109848618+arsengspeyan@users.noreply.github.com> Date: Tue, 9 Jul 2024 22:14:28 +0400 Subject: [PATCH 21/34] Rename PosgresawsTemplate.pkr.json to PosgresawsTemplate.pkr.hcl --- .../{PosgresawsTemplate.pkr.json => PosgresawsTemplate.pkr.hcl} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename packer/{PosgresawsTemplate.pkr.json => PosgresawsTemplate.pkr.hcl} (100%) diff --git a/packer/PosgresawsTemplate.pkr.json b/packer/PosgresawsTemplate.pkr.hcl similarity index 100% rename from packer/PosgresawsTemplate.pkr.json rename to packer/PosgresawsTemplate.pkr.hcl From 5caa21ffcd5b33090e5080d84d5a58dffb3ec75b Mon Sep 17 00:00:00 2001 From: arsengspeyan <109848618+arsengspeyan@users.noreply.github.com> Date: Tue, 9 Jul 2024 22:20:49 +0400 Subject: [PATCH 22/34] Update PosgresawsTemplate.pkr.hcl --- packer/PosgresawsTemplate.pkr.hcl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packer/PosgresawsTemplate.pkr.hcl b/packer/PosgresawsTemplate.pkr.hcl index af1785c..4d4337e 100644 --- a/packer/PosgresawsTemplate.pkr.hcl +++ b/packer/PosgresawsTemplate.pkr.hcl @@ -50,12 +50,12 @@ variable "ssh_username" { default = "ubuntu" } -variable "aws_access_key_id" { +variable "aws_access_key" { type = string sensitive = true } -variable "aws_secret_access_key" { +variable "aws_secret_key" { type = string sensitive = true } From 394750f37ee5dada778a89d7aef68494487dfd67 Mon Sep 17 00:00:00 2001 From: arsengspeyan <109848618+arsengspeyan@users.noreply.github.com> Date: Tue, 9 Jul 2024 22:23:31 +0400 Subject: [PATCH 23/34] Update PosgresawsTemplate.pkr.hcl --- packer/PosgresawsTemplate.pkr.hcl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packer/PosgresawsTemplate.pkr.hcl b/packer/PosgresawsTemplate.pkr.hcl index 4d4337e..7268dc2 100644 --- a/packer/PosgresawsTemplate.pkr.hcl +++ b/packer/PosgresawsTemplate.pkr.hcl @@ -18,8 +18,8 @@ source "amazon-ebs" "example" { instance_type = var.instance_type ssh_username = var.ssh_username ami_name = "packer-postgresql" - access_key = var.aws_access_key_id - secret_key = var.aws_secret_access_key + access_key = var.aws_access_key + secret_key = var.aws_secret_key } build { From c570e8145af4d05f43f068250783570e4dc970d1 Mon Sep 17 00:00:00 2001 From: arsengspeyan <109848618+arsengspeyan@users.noreply.github.com> Date: Tue, 9 Jul 2024 22:30:39 +0400 Subject: [PATCH 24/34] Update PosgresawsTemplate.pkr.hcl --- packer/PosgresawsTemplate.pkr.hcl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packer/PosgresawsTemplate.pkr.hcl b/packer/PosgresawsTemplate.pkr.hcl index 7268dc2..35dbb8b 100644 --- a/packer/PosgresawsTemplate.pkr.hcl +++ b/packer/PosgresawsTemplate.pkr.hcl @@ -53,9 +53,11 @@ variable "ssh_username" { variable "aws_access_key" { type = string sensitive = true + default = "" } variable "aws_secret_key" { type = string - sensitive = true + sensitive = true + default = "" } From 59a76868d60147c24a4deb6b23d22105a996c93f Mon Sep 17 00:00:00 2001 From: arsengspeyan <109848618+arsengspeyan@users.noreply.github.com> Date: Tue, 9 Jul 2024 22:36:14 +0400 Subject: [PATCH 25/34] Update PosgresawsTemplate.pkr.hcl --- packer/PosgresawsTemplate.pkr.hcl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packer/PosgresawsTemplate.pkr.hcl b/packer/PosgresawsTemplate.pkr.hcl index 35dbb8b..358570c 100644 --- a/packer/PosgresawsTemplate.pkr.hcl +++ b/packer/PosgresawsTemplate.pkr.hcl @@ -25,8 +25,8 @@ source "amazon-ebs" "example" { build { sources = ["source.amazon-ebs.example"] - provisioner "ansible" { - playbook_file = "../ansible/setup_postgresql.yml" +provisioner "ansible" { + playbook_file = "../ansible/setup_postgresql.yml" } } From 665b4c83cce366bb2742d422dbef0dcfd73644f3 Mon Sep 17 00:00:00 2001 From: arsengspeyan Date: Tue, 9 Jul 2024 22:59:01 +0400 Subject: [PATCH 26/34] Add new files: --- .github/workflows/build-ami.yml | 58 +++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 .github/workflows/build-ami.yml diff --git a/.github/workflows/build-ami.yml b/.github/workflows/build-ami.yml new file mode 100644 index 0000000..dbb248e --- /dev/null +++ b/.github/workflows/build-ami.yml @@ -0,0 +1,58 @@ +name: Build AMI with Packer and Ansible + +on: + push: + branches: + - ansible-packer + +jobs: + build-ami: + runs-on: ubuntu-latest + env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + #POSTGRES_USER: ${{ secrets.POSTGRES_USER }} + #POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }} + #POSTGRES_DB: ${{ secrets.POSTGRES_DB }} + + steps: + - name: Checkout ansible-packer branch + uses: actions/checkout@v2 + with: + ref: ansible-packer + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.11' + + - name: Install Ansible + run: | + sudo apt update + sudo apt install -y ansible + + - name: Install Latest Packer and Initialize + run: | + wget -O packer.zip https://releases.hashicorp.com/packer/1.11.1/packer_1.11.1_linux_amd64.zip + unzip -o packer.zip -d packer_install + sudo mv packer_install/packer /usr/local/bin/ + rm -rf packer.zip packer_install # Clean up extracted files and zip + packer --version # Verify Packer installation + packer init packer/PosgresawsTemplate.pkr.hcl + + - name: Validate Packer Template + run: packer validate packer/PosgresawsTemplate.pkr.hcl + + - name: Run Packer build and print AMI ID + run: | + packer build -machine-readable -var aws_access_key=${{ secrets.AWS_ACCESS_KEY_ID }} -var aws_secret_key=${{ secrets.AWS_SECRET_ACCESS_KEY }} packer/PosgresawsTemplate.pkr.hcl | tee packer_output.txt + ami_id=$(awk -F, '$0 ~/artifact,0,id/ {print $6}' packer_output.txt) + echo "AMI_ID=$ami_id" >> $GITHUB_ENV + echo "AMI_ID=$ami_id" # Print AMI ID to console + + - name: Save AMI_ID as artifact + uses: actions/upload-artifact@v2 + with: + name: packer-output + path: packer_output.txt + From e1c3d75e79bd7cb83501b663e01f4b37cc471085 Mon Sep 17 00:00:00 2001 From: arsengspeyan <109848618+arsengspeyan@users.noreply.github.com> Date: Tue, 9 Jul 2024 23:09:23 +0400 Subject: [PATCH 27/34] Rename build-ami.yml to build-amii.yml --- .github/workflows/{build-ami.yml => build-amii.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{build-ami.yml => build-amii.yml} (100%) diff --git a/.github/workflows/build-ami.yml b/.github/workflows/build-amii.yml similarity index 100% rename from .github/workflows/build-ami.yml rename to .github/workflows/build-amii.yml From 8140b744d1405f78a50a74982b818c44cf18adc6 Mon Sep 17 00:00:00 2001 From: arsengspeyan <109848618+arsengspeyan@users.noreply.github.com> Date: Tue, 9 Jul 2024 23:23:29 +0400 Subject: [PATCH 28/34] Update build-amii.yml --- .github/workflows/build-amii.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/build-amii.yml b/.github/workflows/build-amii.yml index dbb248e..224b1e7 100644 --- a/.github/workflows/build-amii.yml +++ b/.github/workflows/build-amii.yml @@ -1,9 +1,7 @@ name: Build AMI with Packer and Ansible on: - push: - branches: - - ansible-packer + workflow_dispatch: jobs: build-ami: From 7f383e27f9f94aea3fec6b5e55e9f7ce685fd452 Mon Sep 17 00:00:00 2001 From: arsengspeyan <109848618+arsengspeyan@users.noreply.github.com> Date: Tue, 9 Jul 2024 23:59:28 +0400 Subject: [PATCH 29/34] Update PosgresawsTemplate.pkr.hcl --- packer/PosgresawsTemplate.pkr.hcl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packer/PosgresawsTemplate.pkr.hcl b/packer/PosgresawsTemplate.pkr.hcl index 358570c..afd3d9b 100644 --- a/packer/PosgresawsTemplate.pkr.hcl +++ b/packer/PosgresawsTemplate.pkr.hcl @@ -26,7 +26,7 @@ build { sources = ["source.amazon-ebs.example"] provisioner "ansible" { - playbook_file = "../ansible/setup_postgresql.yml" + playbook_file = "/ansible/setup_postgresql.yml" } } From e961c468a47f9ef0f28acdeda9493b960b69030f Mon Sep 17 00:00:00 2001 From: arsengspeyan <109848618+arsengspeyan@users.noreply.github.com> Date: Wed, 10 Jul 2024 00:24:22 +0400 Subject: [PATCH 30/34] Update PosgresawsTemplate.pkr.hcl --- packer/PosgresawsTemplate.pkr.hcl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packer/PosgresawsTemplate.pkr.hcl b/packer/PosgresawsTemplate.pkr.hcl index afd3d9b..358570c 100644 --- a/packer/PosgresawsTemplate.pkr.hcl +++ b/packer/PosgresawsTemplate.pkr.hcl @@ -26,7 +26,7 @@ build { sources = ["source.amazon-ebs.example"] provisioner "ansible" { - playbook_file = "/ansible/setup_postgresql.yml" + playbook_file = "../ansible/setup_postgresql.yml" } } From d70fb3def2c02572434f1bb2f19763dbdeeaca61 Mon Sep 17 00:00:00 2001 From: arsengspeyan <109848618+arsengspeyan@users.noreply.github.com> Date: Wed, 10 Jul 2024 01:00:15 +0400 Subject: [PATCH 31/34] Update PosgresawsTemplate.pkr.hcl --- packer/PosgresawsTemplate.pkr.hcl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packer/PosgresawsTemplate.pkr.hcl b/packer/PosgresawsTemplate.pkr.hcl index 358570c..d19071f 100644 --- a/packer/PosgresawsTemplate.pkr.hcl +++ b/packer/PosgresawsTemplate.pkr.hcl @@ -26,7 +26,7 @@ build { sources = ["source.amazon-ebs.example"] provisioner "ansible" { - playbook_file = "../ansible/setup_postgresql.yml" + playbook_file = "/home/runner/work/Team1-react-rust-postgres/Team1-react-rust-postgres/packer_ansible/ansible/setup_postgresql.yml" } } From c59f005321276e95cf00ada043f5e6d29f665ae4 Mon Sep 17 00:00:00 2001 From: arsengspeyan <109848618+arsengspeyan@users.noreply.github.com> Date: Wed, 10 Jul 2024 01:35:28 +0400 Subject: [PATCH 32/34] Update setup_postgresql.yml --- ansible/setup_postgresql.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ansible/setup_postgresql.yml b/ansible/setup_postgresql.yml index ab0314a..1f570ac 100644 --- a/ansible/setup_postgresql.yml +++ b/ansible/setup_postgresql.yml @@ -6,8 +6,20 @@ vars: db_name: "mydatabase" postgres_password: "smartes" + + tasks: + + - name: Install psycopg2 Python library + pip: + name: psycopg2-binary + executable: /opt/pipx/venvs/ansible-core/bin/python + state: present + become: yes + become_user: root + + - name: Install psycopg2 Python library package: name: python3-psycopg2 # This might vary based on your system, adjust as needed From e32b3aa8a0f274f0c5dd7fe98f702de7ce9721d7 Mon Sep 17 00:00:00 2001 From: arsengspeyan <109848618+arsengspeyan@users.noreply.github.com> Date: Wed, 10 Jul 2024 01:41:14 +0400 Subject: [PATCH 33/34] Update setup_postgresql.yml --- ansible/setup_postgresql.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ansible/setup_postgresql.yml b/ansible/setup_postgresql.yml index 1f570ac..336f44b 100644 --- a/ansible/setup_postgresql.yml +++ b/ansible/setup_postgresql.yml @@ -11,7 +11,7 @@ tasks: - - name: Install psycopg2 Python library + - name: Install psycopg2-binary Python library pip: name: psycopg2-binary executable: /opt/pipx/venvs/ansible-core/bin/python From 7f675cd65ccc325b57ae412d6ca9745593bfbafb Mon Sep 17 00:00:00 2001 From: arsengspeyan <109848618+arsengspeyan@users.noreply.github.com> Date: Wed, 10 Jul 2024 16:45:24 +0400 Subject: [PATCH 34/34] Update setup_postgresql.yml --- ansible/setup_postgresql.yml | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/ansible/setup_postgresql.yml b/ansible/setup_postgresql.yml index 336f44b..4881a43 100644 --- a/ansible/setup_postgresql.yml +++ b/ansible/setup_postgresql.yml @@ -11,23 +11,6 @@ tasks: - - name: Install psycopg2-binary Python library - pip: - name: psycopg2-binary - executable: /opt/pipx/venvs/ansible-core/bin/python - state: present - become: yes - become_user: root - - - - name: Install psycopg2 Python library - package: - name: python3-psycopg2 # This might vary based on your system, adjust as needed - state: present - become: yes - become_user: root - - - name: Add PostgreSQL APT repository key apt_key: