1-
21def ansible_nginx_install_ubuntu (input ):
2+
33 nginx_hosts = input .hosts
4- inventory = (f"[nginx_nodes]\n " + "\n " .join (nginx_hosts ))
5- nginx_version = input .version
4+ nginx_inventory = (f"[nginx_nodes]\n " + "\n " .join (nginx_hosts ))
5+ nginx_version = '*' if input .version == 'latest' else input .version
6+ nginx_ansible_port = input .ansible_port
7+ nginx_ansible_user = input .ansible_user
8+ nginx_repo_key_in_task = "{{ nginx_repo_key_url }}"
9+ nginx_repo_in_task = "deb {{ nginx_repo_url }} {{ ansible_distribution_release }} nginx"
10+ nginx_version_in_task = "nginx={{ nginx_version }}~{{ ansible_distribution_release }}"
11+
612
713 prompt = f"""
814 Generate a Python code to generate an Ansible project (project name is app/media/MyAnsible)
915 that dynamically provisions Ansible resources ensuring a modular, flexible structure. Only provide
10- Python code, no explanations or markdown formatting. The project should be organized as follows:
16+ Python code, no explanations or markdown formatting, without ```python entry.
17+ The project should be organized as follows:
1118
1219 The structure of this project must be as follows:
1320 ```
@@ -38,12 +45,12 @@ def ansible_nginx_install_ubuntu(input):
3845 ```
3946 - group_vars directory includes a single file called "nginx_nodes" and the content of this file must be as follows:
4047 ```
41- ansible_port: 22
42- ansible_user: root
48+ ansible_port: { nginx_ansible_port }
49+ ansible_user: { nginx_ansible_user }
4350 ```
4451 - there is file called "hosts" which its content must be as follows:
4552 ```
46- { inventory }
53+ { nginx_inventory }
4754 ```
4855 - There is an empty directory called "host_vars" with no files included
4956 - There is a file called "nginx_playbook.yml" which its content must be as follows:
@@ -64,12 +71,12 @@ def ansible_nginx_install_ubuntu(input):
6471
6572 - name: Add Nginx signing key
6673 apt_key:
67- url: "{{ nginx_repo_key_url } }"
74+ url: "{ nginx_repo_key_in_task } "
6875 state: present
6976
7077 - name: Add Nginx repository
7178 apt_repository:
72- repo: "deb {{ nginx_repo_url }} {{ ansible_distribution_release }} nginx "
79+ repo: "{ nginx_repo_in_task } "
7380 state: present
7481 filename: nginx
7582
@@ -79,7 +86,7 @@ def ansible_nginx_install_ubuntu(input):
7986
8087 - name: Install specific version of Nginx
8188 apt:
82- name: "nginx={{ nginx_version }}~{{ ansible_distribution_release } }"
89+ name: "{ nginx_version_in_task } "
8390 state: present
8491
8592 - name: Ensure Nginx service is running and enabled
@@ -92,12 +99,12 @@ def ansible_nginx_install_ubuntu(input):
9299 ```
93100 nginx_repo_key_url: "https://nginx.org/keys/nginx_signing.key"
94101 nginx_repo_url: "http://nginx.org/packages/mainline/ubuntu/"
95- nginx_version: "1.23.4-1 "
102+ nginx_version: "{ nginx_version } "
96103 ```
97104
98- finally just give me a python code without any note that can generate a project folder with the given
99- schema without ```python entry. and we dont need any base directory in the python code. the final
100- terraform template must work very well without any error!
105+ finally just give me a python code without any note that can generate a project folder with the
106+ given schema without ```python entry. and we dont need any base directory in the python code.
107+ the final ansible template must work very well without any error!
101108
102109 the python code you give me, must have structure like that:
103110
@@ -114,12 +121,9 @@ def ansible_nginx_install_ubuntu(input):
114121 # any thing you need
115122 """
116123 return prompt
117-
118-
124+
119125
120126def ansible_nginx_install (input ):
121127
122128 if input .os == 'ubuntu' :
123129 return ansible_nginx_install_ubuntu (input )
124-
125-
0 commit comments