Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ansible task #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .sys/ansible/playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions .sys/ansible/roles/install-apps/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- name: Install tilde
apt:
name: tilde

- name: Install mc
apt:
name: mc
17 changes: 12 additions & 5 deletions .sys/ansible/roles/nginx/templates/main.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,35 @@ 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_pass unix:{{php_fpm_socket}};
fastcgi_param SCRIPT_FILENAME {{main_dir}}/php-app/index.php;
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/ {
proxy_set_header From-who 'my-app';
proxy_set_header Host 'testx';
proxy_pass http://node_app;
}
}
6 changes: 6 additions & 0 deletions .sys/ansible/roles/nginx/templates/proxy.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ map $http_host $proxy_upstream {
default kibana;
kibana.* kibana;
tech-dash.* tech-dash;
rep.* rep;
}

upstream kibana {
Expand All @@ -13,12 +14,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;
}


Expand Down
2 changes: 1 addition & 1 deletion .sys/ansible/roles/node-app/templates/node-app.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion node-app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down