Skip to content

Commit

Permalink
feat(ansible): add nginx template generator to ansible. (#97)
Browse files Browse the repository at this point in the history
* feat(nginx_ansible): recreate nginx ansible model

* fix(nginx_ansible): fix nginx validator

* refactor(ansible): refactor ansible function for more flexibility
  • Loading branch information
abolfazl8131 authored Nov 27, 2024
1 parent 6b07ce3 commit d182782
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 489 deletions.
17 changes: 0 additions & 17 deletions app/media/MyTerraform/main.tf

This file was deleted.

82 changes: 0 additions & 82 deletions app/media/MyTerraform/modules/efs/main.tf

This file was deleted.

28 changes: 0 additions & 28 deletions app/media/MyTerraform/modules/efs/terraform.tfvars

This file was deleted.

44 changes: 0 additions & 44 deletions app/media/MyTerraform/modules/efs/variables.tf

This file was deleted.

10 changes: 0 additions & 10 deletions app/media/MyTerraform/modules/efs/versions.tf

This file was deleted.

28 changes: 0 additions & 28 deletions app/media/MyTerraform/terraform.tfvars

This file was deleted.

44 changes: 0 additions & 44 deletions app/media/MyTerraform/variables.tf

This file was deleted.

10 changes: 0 additions & 10 deletions app/media/MyTerraform/versions.tf

This file was deleted.

14 changes: 12 additions & 2 deletions app/models/ansible_models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
from typing import List, Optional
from pydantic import BaseModel, validator, ValidationError

class AnsibleInstall(BaseModel):


class AnsibleInstallNginx(BaseModel):
os: str = 'ubuntu'
tool: str = 'nginx'
hosts:List[str] = ['www.example.com']
version:str = 'latest'

@validator("os")
def validator_os(cls, value):
valid_oss = ['ubuntu']
if value not in valid_oss:
raise ValueError(f"your selected OS must be in {valid_oss}")
return value
9 changes: 5 additions & 4 deletions app/routes/ansible.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
from app.app_instance import app
from app.gpt_services import gpt_service
from app.services import (write_installation,edit_directory_generator,execute_pythonfile)
from app.models import (AnsibleInstall,Output)
from app.models import (AnsibleInstallNginx,Output)
from app.template_generators.ansible.install.main import ansible_install_template
import os

@app.post("/ansible-install/")
async def ansible_install_generation(request:AnsibleInstall) -> Output:
@app.post("/ansible-install/nginx/")
async def ansible_install_generation_nginx(request:AnsibleInstallNginx) -> Output:

if os.environ.get("TEST"):
return Output(output='output')
generated_prompt = ansible_install_template(request)
generated_prompt = ansible_install_template(request,"nginx")
output = gpt_service(generated_prompt)
edit_directory_generator("ansible_generator",output)
execute_pythonfile("MyAnsible","ansible_generator")
Expand Down
5 changes: 3 additions & 2 deletions app/template_generators/ansible/install/main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from .docker import ansible_docker_install
from .nginx import ansible_nginx_install
from fastapi import HTTPException
def ansible_install_template(input_):
match input_.tool:

def ansible_install_template(input_, tool:str):
match tool:
case 'nginx':
return ansible_nginx_install(input_)
case 'docker':
Expand Down
Loading

0 comments on commit d182782

Please sign in to comment.