From 3d6d9a20ea7df06ba6bdf6fcf8c3db8f0ee5578f Mon Sep 17 00:00:00 2001 From: Timur Mustafin Date: Fri, 6 Aug 2021 21:12:27 +0300 Subject: [PATCH 1/3] ansible task --- .sys/ansible/playbook.yml | 8 +++++--- .sys/ansible/roles/install-apps/tasks/main.yml | 7 +++++++ .sys/ansible/roles/nginx/templates/main.conf.j2 | 13 ++++++++++--- .sys/ansible/roles/nginx/templates/proxy.conf.j2 | 5 +++++ .../roles/node-app/templates/node-app.service.j2 | 2 +- node-app/index.js | 2 +- 6 files changed, 29 insertions(+), 8 deletions(-) create mode 100644 .sys/ansible/roles/install-apps/tasks/main.yml diff --git a/.sys/ansible/playbook.yml b/.sys/ansible/playbook.yml index d18eea9..61686a6 100644 --- a/.sys/ansible/playbook.yml +++ b/.sys/ansible/playbook.yml @@ -2,11 +2,13 @@ hosts: localhost gather_facts: no vars: - main_domain: funtov.loc + main_domain: mustafin.local + main_dir: /home/MustafinTF/devops_lessons main_port: 80 - node_port: 3000 - php_fpm_socket: /run/php/my-app-php-fpm.sock + node_port: 4000 + php_fpm_socket: 127.0.0.1:9234 roles: - nginx - node-app - php-app + - install-apps diff --git a/.sys/ansible/roles/install-apps/tasks/main.yml b/.sys/ansible/roles/install-apps/tasks/main.yml new file mode 100644 index 0000000..ece2256 --- /dev/null +++ b/.sys/ansible/roles/install-apps/tasks/main.yml @@ -0,0 +1,7 @@ +- name: Install tilde + apt: + name: tilde + +- name: Install mc + apt: + name: mc \ No newline at end of file diff --git a/.sys/ansible/roles/nginx/templates/main.conf.j2 b/.sys/ansible/roles/nginx/templates/main.conf.j2 index 7c76bf3..e9fdd98 100644 --- a/.sys/ansible/roles/nginx/templates/main.conf.j2 +++ b/.sys/ansible/roles/nginx/templates/main.conf.j2 @@ -6,17 +6,22 @@ server { server_name {{main_domain}}; listen {{main_port}}; - root /home/kfuntov/devops_lessons; + root {{main_dir}}; location / { - root /home/kfuntov/devops_lessons/static-files; + root {{main_dir}}/static-files; try_files $uri $uri/index.html =404; } + + location ~ \.jpg$ { + try_files $uri $uri/index.html =404; + } + location ^~ /new-php/ { include /etc/nginx/fastcgi_params; fastcgi_index index.php; - fastcgi_param SCRIPT_FILENAME /home/kfuntov/devops_lessons/php-app/index.php; + fastcgi_param SCRIPT_FILENAME {{main_dir}}/php-app/index.php; fastcgi_pass unix:{{php_fpm_socket}}; } @@ -28,6 +33,8 @@ server { } location /node/ { + proxy_set_header From-who 'my-app'; + proxy_set_header Host 'testx'; proxy_pass http://node_app; } } \ No newline at end of file diff --git a/.sys/ansible/roles/nginx/templates/proxy.conf.j2 b/.sys/ansible/roles/nginx/templates/proxy.conf.j2 index b873a56..31adb1d 100644 --- a/.sys/ansible/roles/nginx/templates/proxy.conf.j2 +++ b/.sys/ansible/roles/nginx/templates/proxy.conf.j2 @@ -13,12 +13,17 @@ upstream tech-dash { server tech-dash.x340.org; } +upstream rep { + server repetitors.info.master.stend.x340.org; +} + map $http_host $proxy_host { hostnames; default kibana.x340.org; kibana.* kibana.x340.org; tech-dash.* tech-dash.x340.org; + rep.* repetitors.info.master.stend.x340.org; } diff --git a/.sys/ansible/roles/node-app/templates/node-app.service.j2 b/.sys/ansible/roles/node-app/templates/node-app.service.j2 index 8ddc6fb..36f12fe 100644 --- a/.sys/ansible/roles/node-app/templates/node-app.service.j2 +++ b/.sys/ansible/roles/node-app/templates/node-app.service.j2 @@ -3,7 +3,7 @@ Description=NodeJs app for devops lessons [Service] User=www-data -WorkingDirectory=/home/kfuntov/devops_lessons/node-app +WorkingDirectory={{main_dir}}/node-app Environment=PORT={{node_port}} ExecStart=/usr/bin/node index.js Restart=always diff --git a/node-app/index.js b/node-app/index.js index 40ace55..23ae76c 100644 --- a/node-app/index.js +++ b/node-app/index.js @@ -6,7 +6,7 @@ const port = process.env.PORT; const server = http.createServer((req, res) => { if (req.url === "/node/hello") { res.statusCode = 200; - res.end('Hello from node.js'); + res.end('Hello from node.js ' + req.headers['from-who'] + ' ' + req.headers['host']); return; } res.statusCode = 404; From 767580a15d88f5f52e79bcb8fb7f0b67a33f5f0e Mon Sep 17 00:00:00 2001 From: Timur Mustafin Date: Fri, 6 Aug 2021 23:05:17 +0300 Subject: [PATCH 2/3] ansible task --- .sys/ansible/roles/nginx/templates/main.conf.j2 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.sys/ansible/roles/nginx/templates/main.conf.j2 b/.sys/ansible/roles/nginx/templates/main.conf.j2 index e9fdd98..c10faf8 100644 --- a/.sys/ansible/roles/nginx/templates/main.conf.j2 +++ b/.sys/ansible/roles/nginx/templates/main.conf.j2 @@ -22,14 +22,14 @@ server { include /etc/nginx/fastcgi_params; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME {{main_dir}}/php-app/index.php; - fastcgi_pass unix:{{php_fpm_socket}}; + fastcgi_pass {{php_fpm_socket}}; } location ~ \.php$ { include /etc/nginx/fastcgi_params; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; - fastcgi_pass unix:{{php_fpm_socket}}; + fastcgi_pass {{php_fpm_socket}}; } location /node/ { From edb026084565f39c9c3da670bbe3f5b8239e6935 Mon Sep 17 00:00:00 2001 From: Timur Mustafin Date: Fri, 6 Aug 2021 23:10:58 +0300 Subject: [PATCH 3/3] ansible task proxy --- .sys/ansible/roles/nginx/templates/proxy.conf.j2 | 1 + 1 file changed, 1 insertion(+) diff --git a/.sys/ansible/roles/nginx/templates/proxy.conf.j2 b/.sys/ansible/roles/nginx/templates/proxy.conf.j2 index 31adb1d..bed0918 100644 --- a/.sys/ansible/roles/nginx/templates/proxy.conf.j2 +++ b/.sys/ansible/roles/nginx/templates/proxy.conf.j2 @@ -4,6 +4,7 @@ map $http_host $proxy_upstream { default kibana; kibana.* kibana; tech-dash.* tech-dash; + rep.* rep; } upstream kibana {