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

Added built-in roles #98

Open
wants to merge 1 commit 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
20 changes: 19 additions & 1 deletion lib/Generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
var fs = require('fs');
var Q = require('q');
var mkdirp = require('mkdirp');
var ncp = require('ncp').ncp;
// create promise versions of read and write files
var read = Q.denodeify(fs.readFile);
var write = Q.denodeify(fs.writeFile);
Expand All @@ -15,12 +16,23 @@
answers.tag_old_app = 'old' + answers.appName.charAt(0).toUpperCase() + answers.appName.slice(1);
answers.converted_environment = answers.environment.replace(/-/g, "_");

answers.roles = {};
answers.builtin_roles.forEach(function(role){
answers.roles[role] = true;
});

// create promise versions of chmod and mkdirp
var chmod = Q.denodeify(fs.chmod);
var mkdir = Q.denodeify(mkdirp);



function cpdir(dir, dest) {
ncp(__dirname+'/templates/'+dir, dest, function(err){
if(err) console.log(err);
return Promise.resolve();
});
}
//function that handles .gitignore
function gitignore(path) {
return function() {
Expand All @@ -33,6 +45,7 @@

// Kick off a promise chain
mkdir('ansible/inventory', '0755')
//anible folder
.then(process('ansible.cfg.mustache', 'ansible/ansible.cfg'))
.then(process('aws_keys.mustache', 'ansible/inventory/aws_keys'))
.then(gitignore('ansible/inventory/aws_keys'))
Expand All @@ -43,13 +56,18 @@
.then(process('provision.sh.mustache', 'ansible/provision.sh'))
.then(process('tag-old-nodes.yaml.mustache', 'ansible/tag-old-nodes.yaml'))
.then(mkdir('ansible/roles/' + answers.appName + '/tasks'))
.then(function(){if(answers.roles.Nginx) cpdir('roles/nginx/', 'ansible/roles/nginx');})
.then(function(){if(answers.roles["File Transfer"]) cpdir('roles/push-code/', 'ansible/roles/push-code');})
.then(process('roles/appName/tasks/main.yaml.mustache', 'ansible/roles/' + answers.appName + '/tasks/main.yaml'))
.then(process('myApp.pem.mustache', 'ansible/' + answers.appPem))
.then(gitignore('ansible/' + answers.appPem))
.finally(function() {
.then(function() {
fs.chmod('ansible/provision.sh', '0744');
fs.chmod('ansible/inventory/ec2.py', '0755');
})
.then(mkdir('HelloWorld/'))
.finally(process('HelloWorld.txt.mustache', "HelloWorld/HelloWorld.txt"))

.catch(handler);


Expand Down
12 changes: 12 additions & 0 deletions lib/questions.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,18 @@
'base-64 string with nothing before or after';
return validateInput(value, regex, errorMessage);
}
}, {
type: 'checkbox',
name: 'builtin_roles',
message: 'What roles would you like to include (health checks will fail without a webserver, such as NGINX, installed)',
choices: [
{
name: "File Transfer"
},
{
name: "Nginx"
}
]
}];

module.exports = questions;
Expand Down
5 changes: 5 additions & 0 deletions lib/templates/HelloWorld.txt.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
This file will be transfered over to all the new machines.
You can change the path of the transfered directory in ansible/roles/push-code/tasks/main.yaml


Hello world!
6 changes: 6 additions & 0 deletions lib/templates/immutable.yaml.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@
user: {{{ remote_user }}}
sudo: yes
roles:
{{#roles.Nginx}}
- nginx
{{/roles.Nginx}}
{{#roles['File Transfer']}}
- push-code
{{/roles['File Transfer']}}
- {{{ appName }}}

- hosts: ec2hosts
Expand Down
10 changes: 10 additions & 0 deletions lib/templates/roles/nginx/tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
- name: Ensure nginx stable PPA
apt_repository: repo='ppa:nginx/stable' update_cache="yes"

- name: Install nginx full
apt: name=nginx-full state=installed

- name: Update default site config
template: src=default.conf dest=/etc/nginx/sites-available/default
owner=root group=root mode=0440
27 changes: 27 additions & 0 deletions lib/templates/roles/nginx/templates/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
server {
listen 80 default_server;
listen [::]:80 default_server;

root /opt/dashboard;

# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;

server_name _;


# Reverse proxy to services
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://127.0.0.1:3000;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";

proxy_redirect off;
}
}
7 changes: 7 additions & 0 deletions lib/templates/roles/push-code/tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
- name: Push up code
synchronize: src=../../../../HelloWorld/
dest=/opt/HelloWorld
recursive=yes
rsync_opts="--verbose, --exclude ansible --exclude docs --exclude .git --exclude .idea --exclude .DS_Store --exclude .awscredentials --exclude .gitignore --exclude tests"
archive=no
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"inquirer": "^0.11.0",
"mkdirp": "^0.5.1",
"mustache": "^2.2.1",
"ncp": "^2.0.0",
"openurl": "^1.1.0",
"q": "^1.4.1"
},
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/questionsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ var questions = require('../../lib/questions.js');

describe('questions.js', function() {
describe('format', function() {
it('should be an array of 25 questions', function() {
expect(questions.length).toEqual(25);
it('should be an array of 26 questions', function() {
expect(questions.length).toEqual(26);
});
});
});