Skip to content

Commit

Permalink
Adds ansible playbooks (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hirotaka Wakabayashi authored Nov 14, 2019
1 parent 12f77c9 commit 86c98d4
Show file tree
Hide file tree
Showing 30 changed files with 1,935 additions and 283 deletions.
61 changes: 61 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# next.js build output
.next
2 changes: 1 addition & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

Develops and wrote from scratch the initial version.

2. Takeshi Nakatani <[email protected]>
2. Takeshi Nakatani <[email protected]>

Develops and other improvements.
7 changes: 7 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
k2hr3-utils (0.10.0) unstable; urgency=low

* [devcluster] Changes installation path of node apps.
* [ansible] New release on GitHub.

-- Hirotaka Wakabayashi <[email protected]> Thu, 14 Nov 2019 14:10:56 +0900

k2hr3-utils (0.9.1) unstable; urgency=low

* [devcluster] Added a command line option, -r, which devcluster runs in dry
Expand Down
28 changes: 28 additions & 0 deletions ansible/ansible.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# K2HR3 Utilities
#
# Copyright 2018 Yahoo! Japan Corporation.
#
# K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers
# common management information for the cloud.
# K2HR3 can dynamically manage information as "who", "what", "operate".
# These are stored as roles, resources, policies in K2hdkc, and the
# client system can dynamically read and modify these information.
#
# For the full copyright and license information, please view
# the licenses file that was distributed with this source code.
#
# AUTHOR: Hirotaka Wakabayashi
# CREATE: Tue Nov 12 2019
# REVISION:
#
[defaults]
fact_caching = jsonfile
fact_caching_connection = /tmp/ansible_fact_cache
forks = 8
gathering = smart
host_key_checking = False
pipelining = True
vault_password_file = .vault_password

[ssh_connection]
ssh_args = -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o HostKeyAlgorithms=+ssh-dss
42 changes: 42 additions & 0 deletions ansible/bootstrap-api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# K2HR3 Utilities
#
# Copyright 2018 Yahoo! Japan Corporation.
#
# K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers
# common management information for the cloud.
# K2HR3 can dynamically manage information as "who", "what", "operate".
# These are stored as roles, resources, policies in K2hdkc, and the
# client system can dynamically read and modify these information.
#
# For the full copyright and license information, please view
# the licenses file that was distributed with this source code.
#
# AUTHOR: Hirotaka Wakabayashi
# CREATE: Tue Nov 12 2019
# REVISION:
#
- name: bootstrap api hosts
hosts: api
tasks:
- name: scp devcluster to /tmp on the target hosts
copy:
src: ../devcluster
dest: /tmp
- name: chmod setup_api.sh
copy:
src: ../devcluster/api/setup_api.sh
dest: /tmp/devcluster/api/setup_api.sh
mode: 0755
- name: chmod setup_api_node_module.sh
copy:
src: ../devcluster/api/setup_api_node_module.sh
dest: /tmp/devcluster/api/setup_api_node_module.sh
mode: 0755
- name: Exec the /tmp/devcluster/api/setup_api.sh
shell:
./api/setup_api.sh -d
args:
chdir: /tmp/devcluster
register: setup_api
- debug:
msg: "{{ setup_api.stdout }}"
42 changes: 42 additions & 0 deletions ansible/bootstrap-app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# K2HR3 Utilities
#
# Copyright 2018 Yahoo! Japan Corporation.
#
# K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers
# common management information for the cloud.
# K2HR3 can dynamically manage information as "who", "what", "operate".
# These are stored as roles, resources, policies in K2hdkc, and the
# client system can dynamically read and modify these information.
#
# For the full copyright and license information, please view
# the licenses file that was distributed with this source code.
#
# AUTHOR: Hirotaka Wakabayashi
# CREATE: Tue Nov 12 2019
# REVISION:
#
- name: bootstrap app hosts
hosts: app
tasks:
- name: scp devcluster to /tmp on the target hosts
copy:
src: ../devcluster
dest: /tmp
- name: chmod setup_app.sh
copy:
src: ../devcluster/app/setup_app.sh
dest: /tmp/devcluster/app/setup_app.sh
mode: 0755
- name: chmod setup_app_node_module.sh
copy:
src: ../devcluster/app/setup_app_node_module.sh
dest: /tmp/devcluster/app/setup_app_node_module.sh
mode: 0755
- name: Exec the /tmp/devcluster/app/setup_app.sh
shell:
./app/setup_app.sh -d
args:
chdir: /tmp/devcluster
register: setup_app
- debug:
msg: "{{ setup_app.stdout }}"
37 changes: 37 additions & 0 deletions ansible/bootstrap-dkc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# K2HR3 Utilities
#
# Copyright 2018 Yahoo! Japan Corporation.
#
# K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers
# common management information for the cloud.
# K2HR3 can dynamically manage information as "who", "what", "operate".
# These are stored as roles, resources, policies in K2hdkc, and the
# client system can dynamically read and modify these information.
#
# For the full copyright and license information, please view
# the licenses file that was distributed with this source code.
#
# AUTHOR: Hirotaka Wakabayashi
# CREATE: Tue Nov 12 2019
# REVISION:
#
- name: bootstrap dkc hosts
hosts: dkc
tasks:
- name: scp devcluster dir to /tmp
copy:
src: ../devcluster
dest: /tmp
- name: chmod /tmp/devcluster/dkc/setup_dkc.sh
copy:
src: ../devcluster/dkc/setup_dkc.sh
dest: /tmp/devcluster/dkc/setup_dkc.sh
mode: 0755
- name: Exec the /tmp/devcluster/dkc/setup_dkc.sh
shell:
./dkc/setup_dkc.sh -d
args:
chdir: /tmp/devcluster
register: setup_dkc
- debug:
msg: "{{ setup_dkc.stdout }}"
80 changes: 80 additions & 0 deletions ansible/init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/bin/sh
#
# K2HR3 Utilities
#
# Copyright 2018 Yahoo! Japan Corporation.
#
# K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers
# common management information for the cloud.
# K2HR3 can dynamically manage information as "who", "what", "operate".
# These are stored as roles, resources, policies in K2hdkc, and the
# client system can dynamically read and modify these information.
#
# For the full copyright and license information, please view
# the licenses file that was distributed with this source code.
#
# AUTHOR: Hirotaka Wakabayashi
# CREATE: Tue Nov 12 2019
# REVISION:
#

# This program puts ansible vault password as a file in the working directory
# This program decode base64 encoded data and decrypts it and puts it as a file in the working directory

# Sets the default locale. LC_ALL has precedence over other LC* variables.
unset LANG
unset LANGUAGE
LC_ALL=en_US.utf8
export LC_ALL

# Sets PATH. setup_*.sh uses useradd command
PATH=${PATH}:/usr/sbin:/sbin

# an unset parameter expansion will fail
set -u

# umask 022 is enough
umask 022

# defines environments
TAG=$(basename $0 -s)
VAULT_PASSWORD=${1-}
SSLKEY=${2-}
SSLKEY_FILE=${3-}

if test -z "${VAULT_PASSWORD}"; then
logger -t ${TAG} -p user.err "Usage: init.sh password [encrypted-sslkey] [decrypted-sslkey]"
exit 1
fi

cat <<EOF>.vault_password
${VAULT_PASSWORD}
EOF
if ! test -f ".vault_password" ; then
logger -t ${TAG} -p user.err "[ERROR] .vault_password file does not exist"
exit 1
fi
# defined SSLKEY should be base64 decoded.
if test -n "${SSLKEY}" -a -n "${SSLKEY_FILE}"; then
cat <<EOF>${SSLKEY_FILE}.base64
${SSLKEY}
EOF
base64 -d ${SSLKEY_FILE}.base64 | tee ${SSLKEY_FILE}
# ensures SSLKEY file exists
if ! test -f "${SSLKEY_FILE}" ; then
logger -t ${TAG} -p user.err "[ERROR] ${SSLKEY_FILE} file does not exist"
exit 1
fi
# decrypts SSLKEY file
if ! test -z "${SSLKEY}"; then
ansible-vault decrypt --vault-password-file=.vault_password ${SSLKEY_FILE}
if test "${?}" != 0; then
logger -t ${TAG} -p user.err "[ERROR] ansible-vault decryption error"
exit 1
fi
fi
fi
exit 0
47 changes: 47 additions & 0 deletions devcluster/api/local-json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// -*-Javascript-*-
/*
* K2HR3 Utils
*
* Copyright 2019 Yahoo! Japan Corporation.
*
* K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers
* common management information for the cloud.
* K2HR3 can dynamically manage information as "who", "what", "operate".
* These are stored as roles, resources, policies in K2hdkc, and the
* client system can dynamically read and modify these information.
*
* For the full copyright and license information, please view
* the license file that was distributed with this source code.
*
* AUTHOR: Hirotaka Wakabayashi
* CREATE: Tue Nov 12 2019
* REVISION:
*/
//
// This program generates a local.json of k2hr3-api from a k2hr3-utils setup.ini
//
'use strict';

const path = require('path');
const srcdir = path.resolve(__dirname);
const process = require('process');

if ( process.argv.length != 4) {
let err = "Usage: node " + process.argv[1] + " <path to setup.ini> <path to local.json>";
console.error(err);
throw new Error(err);
}
const input = process.argv[2];
const output = process.argv[3];
try {
let rci = require(path.join(srcdir, 'r3clusterini.js'));
let raj = require(path.join(srcdir, 'r3apijson.js'));
let cluster = new rci.R3clusterIni(input, 'k2hr3_api');
let r3api= new raj.R3apiJson();
for (const val of cluster) {
r3api.configure(val[0], val[1]); // key, value
}
r3api.dumpTo(output);
} catch (err) {
console.error(err.name + ' ' + err.message);
}
Loading

0 comments on commit 86c98d4

Please sign in to comment.