-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
467 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
box-example/roles | ||
*.retry | ||
tempfile | ||
local* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[submodule "roles/sa-box-bootstrap"] | ||
path = roles/sa-box-bootstrap | ||
url = https://github.com/softasap/sa-box-bootstrap.git | ||
[submodule "roles/sa-node-nvm"] | ||
path = roles/sa-node-nvm | ||
url = https://github.com/softasap/sa-node-nvm.git | ||
[submodule "roles/sa-nginx"] | ||
path = roles/sa-nginx | ||
url = https://github.com/softasap/sa-nginx.git | ||
[submodule "roles/sa-include"] | ||
path = roles/sa-include | ||
url = https://github.com/softasap/sa-include.git | ||
[submodule "roles/sa-monit"] | ||
path = roles/sa-monit | ||
url = https://github.com/softasap/sa-monit.git | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/bash | ||
|
||
sudo apt-get install python-pip | ||
sudo pip install -U pip | ||
sudo -H pip install ansible | ||
sudo -H pip install prudentia |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
|
||
|
||
brew install git | ||
brew install python | ||
pip install -U pip | ||
sudo -H pip install ansible | ||
sudo -H pip install prudentia |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
--- | ||
- hosts: newserver | ||
gather_facts: False | ||
|
||
vars: | ||
- root_dir: .. | ||
- user_authorized_keys: | ||
- "~/.ssh/id_rsa.pub" | ||
|
||
pre_tasks: | ||
- debug: msg="Pre tasks section" | ||
|
||
- name: ANSIBLE PYTHON | install python 2 | ||
raw: | | ||
if [ ! -e "/usr/bin/python" ] | ||
then | ||
apt -qqy update && apt install -qy python-minimal | ||
fi | ||
become: yes | ||
|
||
- name: gather facts | ||
setup: | ||
|
||
- debug: var="hostvars" | ||
|
||
- name: UNPRIVILEGED USERS | Get acl dependency (ansible unprivileged user operations magic) | ||
package: name="acl" | ||
become: yes | ||
|
||
|
||
roles: | ||
- { | ||
role: "sa-box-bootstrap", | ||
deploy_user: "appuser", | ||
deploy_user_authorized_keys: "{{user_authorized_keys}}", | ||
option_enforce_ssh_keys_login: yes, | ||
option_file2ban: false | ||
} | ||
- { | ||
role: "sa-monit", | ||
monit_presets: ["basic", "basic_nginx"], | ||
monit_gui_password: monit | ||
} | ||
- { | ||
role: "sa-nginx" | ||
} | ||
- { | ||
role: "sa-node-nvm", | ||
nvm_version: "0.31.2", | ||
nodejs_version: "0.12", | ||
deploy_user: "appuser", | ||
option_nodejs_install_with_nvm: true, | ||
tags: ["create"] | ||
} | ||
|
||
|
||
|
||
tasks: | ||
|
||
- debug: msg="Tasks section" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
- hosts: www | ||
vars: | ||
- root_dir: "{{playbook_dir}}" | ||
|
||
vars_files: | ||
- ./demoapp_vars.yml | ||
|
||
pre_tasks: | ||
- debug: msg="Pre tasks section" | ||
|
||
tasks: | ||
- debug: msg="Tasks section" | ||
- include: "{{root_dir}}/demosite.yml" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
env: staging | ||
deploy_user: "{{ansible_user_id}}" | ||
|
||
install_dir: /opt/yourapp | ||
install_dir_api: "{{install_dir}}/server" | ||
install_dir_client: "{{install_dir}}/client" | ||
|
||
extra_api_params: "" | ||
api_port: 3000 | ||
api_upstart_name: yourapp-api | ||
|
||
app_domain: yourapp.yourdomain.dev | ||
|
||
log_file_path: /opt/yourapp/log | ||
log_file_name: api.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
--- | ||
- include: use/__detect_node_path.yml | ||
tags: | ||
- update | ||
- create | ||
|
||
- name: DemoApp | Dump mounts | ||
command: /bin/mount | ||
register: machine_mounts | ||
tags: | ||
- create | ||
- update | ||
|
||
- name: DemoApp | Create directory | ||
action: file dest={{install_dir}} owner={{deploy_user}} group={{deploy_user}} mode=755 state=directory | ||
when: "'{{install_dir}}' not in machine_mounts.stdout" | ||
become: yes | ||
with_items: | ||
- "{{install_dir}}" | ||
- "{{install_dir_api}}" | ||
- "{{install_dir_client}}" | ||
tags: | ||
- create | ||
- update | ||
|
||
- name: DemoApp | Deploy application (checkout from repo, download tarball whatever) | ||
copy: src="{{item}}" dest="{{install_dir}}" owner="root" group="{{deploy_user}}" mode="u=rw,g=r,o=r" | ||
with_items: | ||
- "{{root_dir}}/files/yourapp/server" | ||
- "{{root_dir}}/files/yourapp/client" | ||
become: yes | ||
tags: | ||
- create | ||
- update | ||
|
||
|
||
- name: DemoApp | Create log dir | ||
file: dest={{log_file_path}} owner={{deploy_user}} group={{deploy_user}} mode=755 state=directory | ||
tags: | ||
- api | ||
|
||
- name: DemoApp | Install node modules | ||
shell: npm update | ||
args: | ||
chdir: "{{install_dir_api}}" | ||
environment: | ||
PATH: "{{npm_path_detected}}:{{ ansible_env.PATH }}" | ||
tags: | ||
- api | ||
- update | ||
|
||
- name: DemoApp |Copy upstart script | ||
template: src="{{root_dir}}/templates/api/upstart.conf.j2" dest=/etc/init/{{api_upstart_name}}.conf | ||
when: ansible_service_mgr == "upstart" | ||
become: yes | ||
tags: | ||
- api | ||
- update | ||
|
||
- name: DemoApp |Copy systemd script | ||
template: src="{{root_dir}}/templates/api/systemd.service.j2" dest=/etc/systemd/system/{{api_upstart_name}}.service | ||
when: ansible_service_mgr == "systemd" | ||
become: yes | ||
tags: | ||
- api | ||
- update | ||
|
||
- name: DemoApp |Create pid dir | ||
file: path="/var/run/yourapp" state="directory" owner="{{deploy_user}}" group="root" | ||
become: yes | ||
tags: | ||
- api | ||
- update | ||
|
||
- name: DemoApp |Restart | ||
service: name={{api_upstart_name}} state=restarted | ||
become: yes | ||
tags: | ||
- api | ||
- update | ||
|
||
- name: DemoApp |Configure monit api monitoring | ||
template: src={{root_dir}}/templates/monit/monit.conf.j2 dest=/etc/monit/conf.d/{{item.api_upstart_name}}.conf | ||
become: yes | ||
tags: | ||
- api | ||
- update | ||
with_items: | ||
- { | ||
api_upstart_name: "{{api_upstart_name}}", | ||
port_number: "{{api_port}}" | ||
} | ||
|
||
- name: DemoApp | Remove default website | ||
file: path="/etc/nginx/conf.d/default.conf" state="absent" | ||
become: yes | ||
tags: | ||
- create | ||
- update | ||
|
||
|
||
- name: DemoApp | configure web startup | ||
template: src="{{root_dir}}/templates/nginx/site.conf.j2" dest="/etc/nginx/sites-available/{{app_domain}}" | ||
become: yes | ||
tags: | ||
- create | ||
- update | ||
|
||
- name: DemoApp | Enable sites | ||
command: ln -fs /etc/nginx/sites-available/{{app_domain}} /etc/nginx/sites-enabled/{{app_domain}} creates=/etc/nginx/sites-enabled/{{app_domain}} | ||
become: yes | ||
tags: | ||
- create | ||
- update | ||
|
||
- name: DemoApp | Restart | ||
service: name="nginx" state=restarted | ||
become: yes | ||
tags: | ||
- create | ||
- update |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<p>This is client app. | ||
try <a href="api/"> api running </a> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Load the http module to create an http server. | ||
var http = require('http'); | ||
|
||
// Configure our HTTP server to respond with Hello World to all requests. | ||
var server = http.createServer(function (request, response) { | ||
response.writeHead(200, {"Content-Type": "text/plain"}); | ||
response.end("Hello World\n"); | ||
}); | ||
|
||
// Listen on port 8000, IP defaults to 127.0.0.1 | ||
server.listen(3000); | ||
|
||
// Put a friendly message on the terminal | ||
console.log("Server running at http://127.0.0.1:3000/"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/bin/bash | ||
|
||
git config -f .projmodules --get-regexp '^submodule\..*\.path$' > tempfile | ||
|
||
while read -u 3 path_key path | ||
do | ||
url_key=$(echo $path_key | sed 's/\.path/.url/') | ||
url=$(git config -f .projmodules --get "$url_key") | ||
|
||
read -p "Are you sure you want to delete $path and re-initialize as a separate repository? " yn | ||
case $yn in | ||
[Yy]* ) rm -rf $path; git clone $url $path; echo "$path has been initialized";; | ||
[Nn]* ) continue;; | ||
* ) echo "Please answer yes or no.";; | ||
esac | ||
|
||
done 3<tempfile | ||
|
||
rm tempfile | ||
|
||
echo Project was checked out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Static parameters | ||
WORKSPACE=./ | ||
BOX_PLAYBOOK=$WORKSPACE/box.yml | ||
BOX_NAME=sixteen | ||
BOX_ADDRESS=188.166.57.245 | ||
BOX_USER=appuser | ||
BOX_PWD= | ||
|
||
prudentia ssh <<EOF | ||
unregister $BOX_NAME | ||
register | ||
$BOX_PLAYBOOK | ||
$BOX_NAME | ||
$BOX_ADDRESS | ||
$BOX_USER | ||
$BOX_PWD | ||
verbose 4 | ||
set box_address $BOX_ADDRESS | ||
provision $BOX_NAME | ||
EOF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Static parameters | ||
WORKSPACE=./ | ||
BOX_PLAYBOOK=$WORKSPACE/bootstrap_server.yml | ||
BOX_NAME=newserverinstance | ||
BOX_ADDRESS=188.166.57.245 | ||
BOX_USER=root | ||
BOX_PWD= | ||
|
||
prudentia ssh <<EOF | ||
unregister $BOX_NAME | ||
register | ||
$BOX_PLAYBOOK | ||
$BOX_NAME | ||
$BOX_ADDRESS | ||
$BOX_USER | ||
$BOX_PWD | ||
verbose 4 | ||
set box_address $BOX_ADDRESS | ||
provision $BOX_NAME | ||
EOF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# CI/CD managed | ||
# Do NOT modify this file by hand! | ||
|
||
[Unit] | ||
Description=Your App | ||
After=network.target | ||
Requires=network.target | ||
|
||
[Service] | ||
Environment="HOME={{install_dir_api}}" | ||
ExecStart={{npm_path_detected}}/node -- server {{extra_api_params}} | ||
|
||
StandardOutput=syslog | ||
StandardError=syslog | ||
SyslogIdentifier={{api_upstart_name}} | ||
|
||
WorkingDirectory={{install_dir_api}} | ||
PIDFile=/var/run/yourapp/{{api_upstart_name}}.pid | ||
|
||
User={{ansible_user_id}} | ||
Group={{ansible_user_id}} | ||
|
||
Restart=always | ||
RestartSec=5 | ||
TimeoutSec=5 | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
description "Your App" | ||
|
||
start on runlevel [2345] | ||
stop on runlevel [016] | ||
|
||
respawn | ||
console log | ||
setuid {{ansible_user_id}} | ||
setgid {{ansible_user_id}} | ||
|
||
env HOME={{install_dir_api}} | ||
|
||
exec start-stop-daemon --chdir ${HOME} --start --make-pidfile --pid=/var/run/yourapp/{{api_upstart_name}}.pid --exec {{npm_path_detected}}/node -- server {{extra_api_params}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!monit | ||
|
||
check process {{item.api_upstart_name}} with pidfile "/var/run/yourapp/{{item.api_upstart_name}}.pid" | ||
start program = "{% if ansible_service_mgr == "systemd" %}/usr/bin/systemctl start{% else %}/sbin/start{% endif %} {{item.api_upstart_name}}" | ||
stop program = "{% if ansible_service_mgr == "systemd" %}/usr/bin/systemctl stop{% else %}/sbin/stop{% endif %} {{item.api_upstart_name}}" | ||
if failed port {{item.port_number}} protocol HTTP | ||
request /api | ||
with timeout 10 seconds | ||
then restart |
Oops, something went wrong.