Skip to content

Commit

Permalink
Merge pull request #100 from abolfazl8131/jcasc
Browse files Browse the repository at this point in the history
add Jcasc
  • Loading branch information
mohammadll authored Nov 27, 2024
2 parents 20a9453 + da7aa07 commit bda80c4
Show file tree
Hide file tree
Showing 22 changed files with 634 additions and 4 deletions.
161 changes: 160 additions & 1 deletion app/directory_generators/ansible_generator.py
Original file line number Diff line number Diff line change
@@ -1 +1,160 @@
Hello! How can I assist you today?
import os

project_name = "app/media/MyAnsible"
roles_dir = os.path.join(project_name, "roles")
nginx_dir = os.path.join(roles_dir, "nginx")
tasks_dir = os.path.join(nginx_dir, "tasks")
handlers_dir = os.path.join(nginx_dir, "handlers")
var_dir = os.path.join(nginx_dir, "var")
meta_dir = os.path.join(nginx_dir, "meta")

# Create project directories
os.makedirs(nginx_dir, exist_ok=True)
os.makedirs(tasks_dir, exist_ok=True)
os.makedirs(handlers_dir, exist_ok=True)
os.makedirs(var_dir, exist_ok=True)
os.makedirs(meta_dir, exist_ok=True)

# Create install_nginx.yaml
with open(os.path.join(project_name, "install_nginx.yaml"), "w") as main_file:
main_file.write('''---
- name: install nginx service
hosts:
- dest
roles:
- nginx
''')

# Create handlers/main.yaml
with open(os.path.join(handlers_dir, "main.yaml"), "w") as handlers_file:
handlers_file.write('''---
- name: restart nginx
service:
name: "{ service }"
state: restarted
- name: restart firewall
service:
name: firewalld
state: restarted
''')

# Create tasks/main.yaml
with open(os.path.join(tasks_dir, "main.yaml"), "w") as tasks_file:
tasks_file.write('''---
# tasks file for nginx
- name: download page
include: download_webpage.yml
- name: unzip
include: unzip.yml
- name: install service
include: install_service.yml
- name: open website port https
firewalld:
service: https
permanent: yes
state: enabled
notify:
- restart firewall
- name: open website port http
firewalld:
zone: public
service: http
permanent: yes
state: enabled
notify:
- restart firewall
- name: webpage
include: copy_files.yml
''')

# Create tasks/unzip.yaml
with open(os.path.join(tasks_dir, "unzip.yaml"), "w") as unzip_file:
unzip_file.write('''---
- name: unarchive zip file
ansible.builtin.unarchive:
src: /home/ansible/ninom.zip
dest: /home/ansible
remote_src: yes
register: unzip
- debug:
var: unzip
''')

# Create tasks/download_webpage.yaml
with open(os.path.join(tasks_dir, "download_webpage.yaml"), "w") as download_file:
download_file.write('''---
- name: download webpage
ansible.builtin.get_url:
url: "{ url_path }"
dest: /home/ansible
timeout: 20
validate_certs: no
register: download
ignore_errors: True
- debug:
var: download
''')

# Create tasks/install_service.yaml
with open(os.path.join(tasks_dir, "install_service.yaml"), "w") as install_file:
install_file.write('''---
- name: install { service }
register: install
ansible.builtin.package:
name: "{ item }"
state: latest
loop:
- "{ service }"
- debug:
var: install
''')

# Create tasks/copy_files.yaml
with open(os.path.join(tasks_dir, "copy_files.yaml"), "w") as copy_file:
copy_file.write('''---
- name: delete before context
shell: "rm -rf /usr/share/nginx/html/*"
register: delete
- debug:
var: delete
- name: copy html file on the html main dir
register: copy_file
copy:
src: /home/ansible/ninom-html/
dest: /usr/share/nginx/html/
remote_src: yes
directory_mode: yes
notify:
- restart nginx
- debug:
var: copy_file
''')

# Create var/main.yaml
with open(os.path.join(var_dir, "main.yaml"), "w") as var_file:
var_file.write('''---
# vars file for nginx
#url_path : https://www.free-css.com/assets/files/free-css-templates/download/page261/avalon.zip
url_path : https://www.free-css.com/assets/files/free-css-templates/download/page283/ninom.zip
service: nginx
''')

# Create meta/main.yaml
with open(os.path.join(meta_dir, "main.yaml"), "w") as meta_file:
meta_file.write('''---
allow_duplicates: yes
dependencies:
- { role: pre-install }
''')
3 changes: 2 additions & 1 deletion app/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from app.routes.utils import *
from app.routes.terraform import *
from app.routes.helm import *
from app.routes.ansible import *
from app.routes.ansible import *
from app.routes.jcasc import *
6 changes: 6 additions & 0 deletions app/media/MyAnsible/install_nginx.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- name: install nginx service
hosts:
- dest
roles:
- nginx
10 changes: 10 additions & 0 deletions app/media/MyAnsible/roles/nginx/handlers/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
- name: restart nginx
service:
name: "{ service }"
state: restarted

- name: restart firewall
service:
name: firewalld
state: restarted
4 changes: 4 additions & 0 deletions app/media/MyAnsible/roles/nginx/meta/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
allow_duplicates: yes
dependencies:
- { role: pre-install }
20 changes: 20 additions & 0 deletions app/media/MyAnsible/roles/nginx/tasks/copy_files.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
- name: delete before context
shell: "rm -rf /usr/share/nginx/html/*"
register: delete

- debug:
var: delete

- name: copy html file on the html main dir
register: copy_file
copy:
src: /home/ansible/ninom-html/
dest: /usr/share/nginx/html/
remote_src: yes
directory_mode: yes
notify:
- restart nginx

- debug:
var: copy_file
12 changes: 12 additions & 0 deletions app/media/MyAnsible/roles/nginx/tasks/download_webpage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
- name: download webpage
ansible.builtin.get_url:
url: "{ url_path }"
dest: /home/ansible
timeout: 20
validate_certs: no
register: download
ignore_errors: True

- debug:
var: download
11 changes: 11 additions & 0 deletions app/media/MyAnsible/roles/nginx/tasks/install_service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
- name: install { service }
register: install
ansible.builtin.package:
name: "{ item }"
state: latest
loop:
- "{ service }"

- debug:
var: install
30 changes: 30 additions & 0 deletions app/media/MyAnsible/roles/nginx/tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
# tasks file for nginx
- name: download page
include: download_webpage.yml

- name: unzip
include: unzip.yml

- name: install service
include: install_service.yml

- name: open website port https
firewalld:
service: https
permanent: yes
state: enabled
notify:
- restart firewall

- name: open website port http
firewalld:
zone: public
service: http
permanent: yes
state: enabled
notify:
- restart firewall

- name: webpage
include: copy_files.yml
10 changes: 10 additions & 0 deletions app/media/MyAnsible/roles/nginx/tasks/unzip.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
- name: unarchive zip file
ansible.builtin.unarchive:
src: /home/ansible/ninom.zip
dest: /home/ansible
remote_src: yes
register: unzip

- debug:
var: unzip
5 changes: 5 additions & 0 deletions app/media/MyAnsible/roles/nginx/var/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
# vars file for nginx
#url_path : https://www.free-css.com/assets/files/free-css-templates/download/page261/avalon.zip
url_path : https://www.free-css.com/assets/files/free-css-templates/download/page283/ninom.zip
service: nginx
6 changes: 6 additions & 0 deletions app/media/MyHelm/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{{/*
Common template helpers
*/}}
{{- define "my-helm.fullname" -}}
{{- printf "%s-%s" .Release.Name .Chart.Name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
17 changes: 17 additions & 0 deletions app/media/MyHelm/templates/web/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: web-ingress
spec:
rules:
- host: 123.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: web
port:
number: 80
41 changes: 41 additions & 0 deletions app/media/MyTerraform/modules/argocd/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
resource "argocd_repository" "repository" {
count = var.repository_create ? 1 : 0
repo = var.argocd_repository_info["repo"]
username = var.argocd_repository_info["username"]
password = var.argocd_repository_info["password"]
}

resource "argocd_application" "application" {
count = var.application_create ? 1 : 0

depends_on = []

metadata {
name = var.argocd_application["name"]
namespace = "argocd"
labels = {
using_sync_policy_options = "true"
}
}

spec {
destination {
server = var.argocd_application["destination_server"]
namespace = var.argocd_application["destination_namespace"]
}

source {
repo_url = var.argocd_application["source_repo_url"]
path = var.argocd_application["source_path"]
target_revision = var.argocd_application["source_target_revision"]
}

sync_policy {
automated {
prune = false
self_heal = true
}
sync_options = var.argocd_sync_options
}
}
}
18 changes: 18 additions & 0 deletions app/media/MyTerraform/modules/argocd/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
repository_create = false
argocd_repository_info = {
repo = "https://YOUR_REPO.git"
username = "USERNAME"
password = "CHANGE_ME_WITH_TOKEN"
}

application_create = true
argocd_application = {
name = "APPLICATION_NAME"
destination_server = "https://kubernetes.default.svc"
destination_namespace = "DESTINATION_NAMESPACE"
source_repo_url = "https://YOUR_REPO.git"
source_path = "SOURCE_PATH"
source_target_revision = "SOURCE_TARGET_REVISION"
}

argocd_sync_options = ["CreateNamespace=true", "ApplyOutOfSyncOnly=true", "FailOnSharedResource=true"]
19 changes: 19 additions & 0 deletions app/media/MyTerraform/modules/argocd/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
variable "repository_create" {
type = bool
}

variable "argocd_repository_info" {
type = map(string)
}

variable "application_create" {
type = bool
}

variable "argocd_application" {
type = map(string)
}

variable "argocd_sync_options" {
type = list(string)
}
Loading

0 comments on commit bda80c4

Please sign in to comment.