@ -0,0 +1,8 @@ | |||
--- | |||
#variable "service" is required | |||
- hosts: "{{ lookup('env','TF_VAR_TESTNET_NAME') }}:tag_Environment_{{ lookup('env','TF_VAR_TESTNET_NAME') | regex_replace('-','_') }}" | |||
roles: | |||
- getconfigtoml | |||
@ -0,0 +1,8 @@ | |||
--- | |||
#variable "source" is required | |||
- hosts: "{{ lookup('env','TF_VAR_TESTNET_NAME') }}:tag_Environment_{{ lookup('env','TF_VAR_TESTNET_NAME') | regex_replace('-','_') }}" | |||
roles: | |||
- getfile | |||
@ -0,0 +1,8 @@ | |||
--- | |||
#variable "service" is required | |||
- hosts: "{{ lookup('env','TF_VAR_TESTNET_NAME') }}:tag_Environment_{{ lookup('env','TF_VAR_TESTNET_NAME') | regex_replace('-','_') }}" | |||
roles: | |||
- jsonconfig | |||
@ -1,7 +1,6 @@ | |||
--- | |||
#tendermint_genesis_file: "<undefined>" | |||
#service_genesis_file: "<undefined>" | |||
app_options_file: "app_options_files/dev_money" | |||
#genesis_file: "<undefined>" | |||
app_options_file: "app_options_files/public_testnet" | |||
seeds: "" | |||
testnet_name: testnet1 | |||
validators: true | |||
@ -0,0 +1,46 @@ | |||
{ | |||
"genesis_time":"{{ansible_date_time.iso8601}}", | |||
"chain_id":"{{testnet_name}}", | |||
"validators": | |||
[ | |||
{% if (validators == true) or (validators == 'true') %} | |||
{% set comma = joiner(",") %} | |||
{% for host in (groups[testnet_name]|default([]))+(groups['tag_Environment_'~(testnet_name|regex_replace('-','_'))]|default([])) %} | |||
{{ comma() }} | |||
{ | |||
"pub_key": { | |||
"data": "{{hostvars[host]["pubkey"]["data"]}}", | |||
"type": "{{hostvars[host]["pubkey"]["type"]}}" | |||
}, | |||
"power":10, | |||
"name":"{{hostvars[host]["inventory_hostname"]}}" | |||
} | |||
{% endfor %} | |||
{% endif %} | |||
], | |||
"app_hash":"", | |||
"app_options": { | |||
{% if app_options_file is defined %} | |||
{% include app_options_file %} | |||
{% endif %} | |||
} | |||
{% if service == 'ethermint' %} | |||
, | |||
"config": { | |||
"chainId": 15, | |||
"homesteadBlock": 0, | |||
"eip155Block": 0, | |||
"eip158Block": 0 | |||
}, | |||
"nonce": "0xdeadbeefdeadbeef", | |||
"timestamp": "0x00", | |||
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", | |||
"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000", | |||
"difficulty": "0x40", | |||
"gasLimit": "0x8000000", | |||
"alloc": { | |||
"0x7eff122b94897ea5b0e2a9abf47b86337fafebdc": { "balance": "10000000000000000000000000000000000" }, | |||
"0xc6713982649D9284ff56c32655a9ECcCDA78422A": { "balance": "10000000000000000000000000000000000" } | |||
} | |||
{% endif %} | |||
} |
@ -0,0 +1,6 @@ | |||
--- | |||
- name: Get config.toml from node | |||
fetch: "dest={{ destination | default('.') }}/config.toml flat=yes src=/etc/{{service}}/config.toml" | |||
run_once: yes | |||
@ -0,0 +1,6 @@ | |||
--- | |||
- name: Get file from node | |||
fetch: "dest={{ destination | default('.') }}/{{ source | basename }} flat=yes src='{{source}}'" | |||
run_once: yes | |||
@ -1,4 +1,5 @@ | |||
--- | |||
release_install: true | |||
binary: "{{ lookup('env','GOPATH') | default('') }}/bin/{{service}}" | |||
devops_path: false | |||
@ -0,0 +1,360 @@ | |||
#!/usr/bin/python | |||
ANSIBLE_METADATA = { | |||
'metadata_version': '1.1', | |||
'status': ['preview'], | |||
'supported_by': 'community' | |||
} | |||
DOCUMENTATION = ''' | |||
--- | |||
module: jsonconfig | |||
short_description: Ensure a particular configuration is added to a json-formatted configuration file | |||
version_added: "2.4" | |||
description: | |||
- This module will add configuration to a json-formatted configuration file. | |||
options: | |||
dest: | |||
description: | |||
- The file to modify. | |||
required: true | |||
aliases: [ name, destfile ] | |||
json: | |||
description: | |||
- The configuration in json format to apply. | |||
required: false | |||
default: '{}' | |||
merge: | |||
description: | |||
- Used with C(state=present). If specified, it will merge the configuration. Othwerwise | |||
the configuration will be overwritten. | |||
required: false | |||
choices: [ "yes", "no" ] | |||
default: "yes" | |||
state: | |||
description: | |||
- Whether the configuration should be there or not. | |||
required: false | |||
choices: [ present, absent ] | |||
default: "present" | |||
create: | |||
description: | |||
- Used with C(state=present). If specified, the file will be created | |||
if it does not already exist. By default it will fail if the file | |||
is missing. | |||
required: false | |||
choices: [ "yes", "no" ] | |||
default: "no" | |||
backup: | |||
description: | |||
- Create a backup file including the timestamp information so you can | |||
get the original file back if you somehow clobbered it incorrectly. | |||
required: false | |||
choices: [ "yes", "no" ] | |||
default: "no" | |||
others: | |||
description: | |||
- All arguments accepted by the M(file) module also work here. | |||
required: false | |||
extends_documentation_fragment: | |||
- files | |||
- validate | |||
author: | |||
- "Greg Szabo (@greg-szabo)" | |||
''' | |||
EXAMPLES = ''' | |||
# Add a new section to a json file | |||
- name: Add comment section | |||
jsonconfig: | |||
dest: /etc/something.json | |||
json: '{ "comment": { "comment1": "mycomment" } }' | |||
# Rewrite a json file with the configuration | |||
- name: Create or overwrite config.json | |||
jsonconfig: | |||
dest: /etc/config.json | |||
json: '{ "regedit": { "freshfile": true } }' | |||
merge: no | |||
create: yes | |||
''' | |||
RETURN = ''' | |||
changed: | |||
description: True if the configuration changed. | |||
type: bool | |||
msg: | |||
description: Description of the change | |||
type: str | |||
''' | |||
from ansible.module_utils.basic import AnsibleModule | |||
from ansible.module_utils.six import b | |||
from ansible.module_utils._text import to_bytes, to_native | |||
import tempfile | |||
import json | |||
import copy | |||
import os | |||
def write_changes(module, b_lines, dest): | |||
tmpfd, tmpfile = tempfile.mkstemp() | |||
f = os.fdopen(tmpfd, 'wb') | |||
f.writelines(b_lines) | |||
f.close() | |||
validate = module.params.get('validate', None) | |||
valid = not validate | |||
if validate: | |||
if "%s" not in validate: | |||
module.fail_json(msg="validate must contain %%s: %s" % (validate)) | |||
(rc, out, err) = module.run_command(to_bytes(validate % tmpfile, errors='surrogate_or_strict')) | |||
valid = rc == 0 | |||
if rc != 0: | |||
module.fail_json(msg='failed to validate: ' | |||
'rc:%s error:%s' % (rc, err)) | |||
if valid: | |||
module.atomic_move(tmpfile, | |||
to_native(os.path.realpath(to_bytes(dest, errors='surrogate_or_strict')), errors='surrogate_or_strict'), | |||
unsafe_writes=module.params['unsafe_writes']) | |||
def check_file_attrs(module, changed, message, diff): | |||
file_args = module.load_file_common_arguments(module.params) | |||
if module.set_fs_attributes_if_different(file_args, False, diff=diff): | |||
if changed: | |||
message += " and " | |||
changed = True | |||
message += "ownership, perms or SE linux context changed" | |||
return message, changed | |||
#Merge dict d2 into dict d1 and return a new object | |||
def deepmerge(d1, d2): | |||
if d1 is None: | |||
return copy.deepcopy(d2) | |||
if d2 is None: | |||
return copy.deepcopy(d1) | |||
if d1 == d2: | |||
return copy.deepcopy(d1) | |||
if isinstance(d1, dict) and isinstance(d2, dict): | |||
result={} | |||
for key in set(d1.keys()+d2.keys()): | |||
da = db = None | |||
if key in d1: | |||
da = d1[key] | |||
if key in d2: | |||
db = d2[key] | |||
result[key] = deepmerge(da, db) | |||
return result | |||
else: | |||
return copy.deepcopy(d2) | |||
#Remove dict d2 from dict d1 and return a new object | |||
def deepdiff(d1, d2): | |||
if d1 is None or d2 is None: | |||
return None | |||
if d1 == d2: | |||
return None | |||
if isinstance(d1, dict) and isinstance(d2, dict): | |||
result = {} | |||
for key in d1.keys(): | |||
if key in d2: | |||
dd = deepdiff(d1[key],d2[key]) | |||
if dd is not None: | |||
result[key] = dd | |||
else: | |||
result[key] = d1[key] | |||
return result | |||
else: | |||
return None | |||
def present(module, dest, conf, merge, create, backup): | |||
diff = {'before': '', | |||
'after': '', | |||
'before_header': '%s (content)' % dest, | |||
'after_header': '%s (content)' % dest} | |||
b_dest = to_bytes(dest, errors='surrogate_or_strict') | |||
if not os.path.exists(b_dest): | |||
if not create: | |||
module.fail_json(rc=257, msg='Destination %s does not exist !' % dest) | |||
b_destpath = os.path.dirname(b_dest) | |||
if not os.path.exists(b_destpath) and not module.check_mode: | |||
os.makedirs(b_destpath) | |||
b_lines = [] | |||
else: | |||
f = open(b_dest, 'rb') | |||
b_lines = f.readlines() | |||
f.close() | |||
lines = to_native(b('').join(b_lines)) | |||
if module._diff: | |||
diff['before'] = lines | |||
b_conf = to_bytes(conf, errors='surrogate_or_strict') | |||
jsonconfig = json.loads(lines) | |||
config = eval(b_conf) | |||
if not isinstance(config, dict): | |||
module.fail_json(msg="Invalid value in json parameter: {0}".format(config)) | |||
b_lines_new = b_lines | |||
msg = '' | |||
changed = False | |||
if not merge: | |||
if jsonconfig != config: | |||
b_lines_new = to_bytes(json.dumps(config, sort_keys=True, indent=4, separators=(',', ': '))) | |||
msg = 'config overwritten' | |||
changed = True | |||
else: | |||
mergedconfig = deepmerge(jsonconfig,config) | |||
if jsonconfig != mergedconfig: | |||
b_lines_new = to_bytes(json.dumps(mergedconfig, sort_keys=True, indent=4, separators=(',', ': '))) | |||
msg = 'config merged' | |||
changed = True | |||
if module._diff: | |||
diff['after'] = to_native(b('').join(b_lines_new)) | |||
backupdest = "" | |||
if changed and not module.check_mode: | |||
if backup and os.path.exists(b_dest): | |||
backupdest = module.backup_local(dest) | |||
write_changes(module, b_lines_new, dest) | |||
if module.check_mode and not os.path.exists(b_dest): | |||
module.exit_json(changed=changed, msg=msg, backup=backupdest, diff=diff) | |||
attr_diff = {} | |||
msg, changed = check_file_attrs(module, changed, msg, attr_diff) | |||
attr_diff['before_header'] = '%s (file attributes)' % dest | |||
attr_diff['after_header'] = '%s (file attributes)' % dest | |||
difflist = [diff, attr_diff] | |||
module.exit_json(changed=changed, msg=msg, backup=backupdest, diff=difflist) | |||
def absent(module, dest, conf, backup): | |||
b_dest = to_bytes(dest, errors='surrogate_or_strict') | |||
if not os.path.exists(b_dest): | |||
module.exit_json(changed=False, msg="file not present") | |||
msg = '' | |||
diff = {'before': '', | |||
'after': '', | |||
'before_header': '%s (content)' % dest, | |||
'after_header': '%s (content)' % dest} | |||
f = open(b_dest, 'rb') | |||
b_lines = f.readlines() | |||
f.close() | |||
lines = to_native(b('').join(b_lines)) | |||
b_conf = to_bytes(conf, errors='surrogate_or_strict') | |||
lines = to_native(b('').join(b_lines)) | |||
jsonconfig = json.loads(lines) | |||
config = eval(b_conf) | |||
if not isinstance(config, dict): | |||
module.fail_json(msg="Invalid value in json parameter: {0}".format(config)) | |||
if module._diff: | |||
diff['before'] = to_native(b('').join(b_lines)) | |||
b_lines_new = b_lines | |||
msg = '' | |||
changed = False | |||
diffconfig = deepdiff(jsonconfig,config) | |||
if diffconfig is None: | |||
diffconfig = {} | |||
if jsonconfig != diffconfig: | |||
b_lines_new = to_bytes(json.dumps(diffconfig, sort_keys=True, indent=4, separators=(',', ': '))) | |||
msg = 'config removed' | |||
changed = True | |||
if module._diff: | |||
diff['after'] = to_native(b('').join(b_lines_new)) | |||
backupdest = "" | |||
if changed and not module.check_mode: | |||
if backup: | |||
backupdest = module.backup_local(dest) | |||
write_changes(module, b_lines_new, dest) | |||
attr_diff = {} | |||
msg, changed = check_file_attrs(module, changed, msg, attr_diff) | |||
attr_diff['before_header'] = '%s (file attributes)' % dest | |||
attr_diff['after_header'] = '%s (file attributes)' % dest | |||
difflist = [diff, attr_diff] | |||
module.exit_json(changed=changed, msg=msg, backup=backupdest, diff=difflist) | |||
def main(): | |||
# define the available arguments/parameters that a user can pass to | |||
# the module | |||
module_args = dict( | |||
dest=dict(type='str', required=True), | |||
json=dict(default=None, required=True), | |||
merge=dict(type='bool', default=True), | |||
state=dict(default='present', choices=['absent', 'present']), | |||
create=dict(type='bool', default=False), | |||
backup=dict(type='bool', default=False), | |||
validate=dict(default=None, type='str') | |||
) | |||
# the AnsibleModule object will be our abstraction working with Ansible | |||
# this includes instantiation, a couple of common attr would be the | |||
# args/params passed to the execution, as well as if the module | |||
# supports check mode | |||
module = AnsibleModule( | |||
argument_spec=module_args, | |||
add_file_common_args=True, | |||
supports_check_mode=True | |||
) | |||
params = module.params | |||
create = params['create'] | |||
merge = params['merge'] | |||
backup = params['backup'] | |||
dest = params['dest'] | |||
b_dest = to_bytes(dest, errors='surrogate_or_strict') | |||
if os.path.isdir(b_dest): | |||
module.fail_json(rc=256, msg='Destination %s is a directory !' % dest) | |||
conf = params['json'] | |||
if params['state'] == 'present': | |||
present(module, dest, conf, merge, create, backup) | |||
else: | |||
absent(module, dest, conf, backup) | |||
if __name__ == '__main__': | |||
main() | |||
@ -0,0 +1,5 @@ | |||
--- | |||
- name: Update | |||
jsonconfig: "dest='{{destination}}' json='{{jsonconfig}}' state={{(remove | default(false) | bool) | ternary('absent','present')}}" | |||
@ -0,0 +1,27 @@ | |||
--- | |||
- name: Download file if necessary | |||
when: source | regex_search('^https?://') | |||
get_url: "url={{source}} dest={{localdir}}/{{source | basename | regex_replace('\\?.*$','')}}" | |||
register: downloaded | |||
connection: local | |||
run_once: yes | |||
become: no | |||
- name: Figure out file source | |||
set_fact: | |||
compiledsource: "{{ (downloaded.skipped is defined) | ternary(source, downloaded.dest) }}" | |||
connection: local | |||
become: no | |||
- name: Extract file to destination | |||
when: compiledsource | regex_search('\\.(zip|tar|tar\\.gz|tgz|tb2|tbz|tbz2|tar\\.bz2|txz|tar\\.xz)$') | |||
register: extractcopy | |||
unarchive: | |||
src: "{{compiledsource}}" | |||
dest: "{{destination}}" | |||
- name: Copy non-zipped file to destination | |||
when: extractcopy.skipped is defined | |||
copy: "src='{{compiledsource}}' dest='{{destination}}'" | |||
@ -0,0 +1,3 @@ | |||
--- | |||
destination: /etc/{{service}}/config.toml | |||
@ -0,0 +1,386 @@ | |||
#!/usr/bin/python | |||
ANSIBLE_METADATA = { | |||
'metadata_version': '1.1', | |||
'status': ['preview'], | |||
'supported_by': 'community' | |||
} | |||
DOCUMENTATION = ''' | |||
--- | |||
module: tomlconfig | |||
short_description: Ensure a particular configuration is added to a toml-formatted configuration file | |||
version_added: "2.4" | |||
description: | |||
- This module will add configuration to a toml-formatted configuration file. | |||
options: | |||
dest: | |||
description: | |||
- The file to modify. | |||
required: true | |||
aliases: [ name, destfile ] | |||
json: | |||
description: | |||
- The configuration in json format to apply. Either C(json) or C(toml) has to be present. | |||
required: false | |||
default: '{}' | |||
toml: | |||
description: | |||
- The configuration in toml format to apply. Either C(json) or C(toml) has to be present. | |||
default: '' | |||
merge: | |||
description: | |||
- Used with C(state=present). If specified, it will merge the configuration. Othwerwise | |||
the configuration will be overwritten. | |||
required: false | |||
choices: [ "yes", "no" ] | |||
default: "yes" | |||
state: | |||
description: | |||
- Whether the configuration should be there or not. | |||
required: false | |||
choices: [ present, absent ] | |||
default: "present" | |||
create: | |||
description: | |||
- Used with C(state=present). If specified, the file will be created | |||
if it does not already exist. By default it will fail if the file | |||
is missing. | |||
required: false | |||
choices: [ "yes", "no" ] | |||
default: "no" | |||
backup: | |||
description: | |||
- Create a backup file including the timestamp information so you can | |||
get the original file back if you somehow clobbered it incorrectly. | |||
required: false | |||
choices: [ "yes", "no" ] | |||
default: "no" | |||
others: | |||
description: | |||
- All arguments accepted by the M(file) module also work here. | |||
required: false | |||
extends_documentation_fragment: | |||
- files | |||
- validate | |||
author: | |||
- "Greg Szabo (@greg-szabo)" | |||
''' | |||
EXAMPLES = ''' | |||
# Add a new section to a toml file | |||
- name: Add comment section | |||
tomlconfig: | |||
dest: /etc/config.toml | |||
json: '{ "comment": { "comment1": "mycomment" } }' | |||
# Rewrite a toml file with the configuration | |||
- name: Create or overwrite config.toml | |||
tomlconfig: | |||
dest: /etc/config.toml | |||
json: '{ "regedit": { "freshfile": true } }' | |||
merge: no | |||
create: yes | |||
''' | |||
RETURN = ''' | |||
changed: | |||
description: True if the configuration changed. | |||
type: bool | |||
msg: | |||
description: Description of the change | |||
type: str | |||
''' | |||
from ansible.module_utils.basic import AnsibleModule | |||
from ansible.module_utils.six import b | |||
from ansible.module_utils._text import to_bytes, to_native | |||
import tempfile | |||
import toml as pytoml | |||
import json | |||
import copy | |||
import os | |||
def write_changes(module, b_lines, dest): | |||
tmpfd, tmpfile = tempfile.mkstemp() | |||
f = os.fdopen(tmpfd, 'wb') | |||
f.writelines(b_lines) | |||
f.close() | |||
validate = module.params.get('validate', None) | |||
valid = not validate | |||
if validate: | |||
if "%s" not in validate: | |||
module.fail_json(msg="validate must contain %%s: %s" % (validate)) | |||
(rc, out, err) = module.run_command(to_bytes(validate % tmpfile, errors='surrogate_or_strict')) | |||
valid = rc == 0 | |||
if rc != 0: | |||
module.fail_json(msg='failed to validate: ' | |||
'rc:%s error:%s' % (rc, err)) | |||
if valid: | |||
module.atomic_move(tmpfile, | |||
to_native(os.path.realpath(to_bytes(dest, errors='surrogate_or_strict')), errors='surrogate_or_strict'), | |||
unsafe_writes=module.params['unsafe_writes']) | |||
def check_file_attrs(module, changed, message, diff): | |||
file_args = module.load_file_common_arguments(module.params) | |||
if module.set_fs_attributes_if_different(file_args, False, diff=diff): | |||
if changed: | |||
message += " and " | |||
changed = True | |||
message += "ownership, perms or SE linux context changed" | |||
return message, changed | |||
#Merge dict d2 into dict d1 and return a new object | |||
def deepmerge(d1, d2): | |||
if d1 is None: | |||
return copy.deepcopy(d2) | |||
if d2 is None: | |||
return copy.deepcopy(d1) | |||
if d1 == d2: | |||
return copy.deepcopy(d1) | |||
if isinstance(d1, dict) and isinstance(d2, dict): | |||
result={} | |||
for key in set(d1.keys()+d2.keys()): | |||
da = db = None | |||
if key in d1: | |||
da = d1[key] | |||
if key in d2: | |||
db = d2[key] | |||
result[key] = deepmerge(da, db) | |||
return result | |||
else: | |||
return copy.deepcopy(d2) | |||
#Remove dict d2 from dict d1 and return a new object | |||
def deepdiff(d1, d2): | |||
if d1 is None or d2 is None: | |||
return None | |||
if d1 == d2: | |||
return None | |||
if isinstance(d1, dict) and isinstance(d2, dict): | |||
result = {} | |||
for key in d1.keys(): | |||
if key in d2: | |||
dd = deepdiff(d1[key],d2[key]) | |||
if dd is not None: | |||
result[key] = dd | |||
else: | |||
result[key] = d1[key] | |||
return result | |||
else: | |||
return None | |||
def present(module, dest, conf, jsonbool, merge, create, backup): | |||
diff = {'before': '', | |||
'after': '', | |||
'before_header': '%s (content)' % dest, | |||
'after_header': '%s (content)' % dest} | |||
b_dest = to_bytes(dest, errors='surrogate_or_strict') | |||
if not os.path.exists(b_dest): | |||
if not create: | |||
module.fail_json(rc=257, msg='Destination %s does not exist !' % dest) | |||
b_destpath = os.path.dirname(b_dest) | |||
if not os.path.exists(b_destpath) and not module.check_mode: | |||
os.makedirs(b_destpath) | |||
b_lines = [] | |||
else: | |||
f = open(b_dest, 'rb') | |||
b_lines = f.readlines() | |||
f.close() | |||
lines = to_native(b('').join(b_lines)) | |||
if module._diff: | |||
diff['before'] = lines | |||
b_conf = to_bytes(conf, errors='surrogate_or_strict') | |||
tomlconfig = pytoml.loads(lines) | |||
config = {} | |||
if jsonbool: | |||
config = eval(b_conf) | |||
else: | |||
config = pytoml.loads(b_conf) | |||
if not isinstance(config, dict): | |||
if jsonbool: | |||
module.fail_json(msg="Invalid value in json parameter: {0}".format(config)) | |||
else: | |||
module.fail_json(msg="Invalid value in toml parameter: {0}".format(config)) | |||
b_lines_new = b_lines | |||
msg = '' | |||
changed = False | |||
if not merge: | |||
if tomlconfig != config: | |||
b_lines_new = to_bytes(pytoml.dumps(config)) | |||
msg = 'config overwritten' | |||
changed = True | |||
else: | |||
mergedconfig = deepmerge(tomlconfig,config) | |||
if tomlconfig != mergedconfig: | |||
b_lines_new = to_bytes(pytoml.dumps(mergedconfig)) | |||
msg = 'config merged' | |||
changed = True | |||
if module._diff: | |||
diff['after'] = to_native(b('').join(b_lines_new)) | |||
backupdest = "" | |||
if changed and not module.check_mode: | |||
if backup and os.path.exists(b_dest): | |||
backupdest = module.backup_local(dest) | |||
write_changes(module, b_lines_new, dest) | |||
if module.check_mode and not os.path.exists(b_dest): | |||
module.exit_json(changed=changed, msg=msg, backup=backupdest, diff=diff) | |||
attr_diff = {} | |||
msg, changed = check_file_attrs(module, changed, msg, attr_diff) | |||
attr_diff['before_header'] = '%s (file attributes)' % dest | |||
attr_diff['after_header'] = '%s (file attributes)' % dest | |||
difflist = [diff, attr_diff] | |||
module.exit_json(changed=changed, msg=msg, backup=backupdest, diff=difflist) | |||
def absent(module, dest, conf, jsonbool, backup): | |||
b_dest = to_bytes(dest, errors='surrogate_or_strict') | |||
if not os.path.exists(b_dest): | |||
module.exit_json(changed=False, msg="file not present") | |||
msg = '' | |||
diff = {'before': '', | |||
'after': '', | |||
'before_header': '%s (content)' % dest, | |||
'after_header': '%s (content)' % dest} | |||
f = open(b_dest, 'rb') | |||
b_lines = f.readlines() | |||
f.close() | |||
lines = to_native(b('').join(b_lines)) | |||
b_conf = to_bytes(conf, errors='surrogate_or_strict') | |||
lines = to_native(b('').join(b_lines)) | |||
tomlconfig = pytoml.loads(lines) | |||
config = {} | |||
if jsonbool: | |||
config = eval(b_conf) | |||
else: | |||
config = pytoml.loads(b_conf) | |||
if not isinstance(config, dict): | |||
if jsonbool: | |||
module.fail_json(msg="Invalid value in json parameter: {0}".format(config)) | |||
else: | |||
module.fail_json(msg="Invalid value in toml parameter: {0}".format(config)) | |||
if module._diff: | |||
diff['before'] = to_native(b('').join(b_lines)) | |||
b_lines_new = b_lines | |||
msg = '' | |||
changed = False | |||
diffconfig = deepdiff(tomlconfig,config) | |||
if diffconfig is None: | |||
diffconfig = {} | |||
if tomlconfig != diffconfig: | |||
b_lines_new = to_bytes(pytoml.dumps(diffconfig)) | |||
msg = 'config removed' | |||
changed = True | |||
if module._diff: | |||
diff['after'] = to_native(b('').join(b_lines_new)) | |||
backupdest = "" | |||
if changed and not module.check_mode: | |||
if backup: | |||
backupdest = module.backup_local(dest) | |||
write_changes(module, b_lines_new, dest) | |||
attr_diff = {} | |||
msg, changed = check_file_attrs(module, changed, msg, attr_diff) | |||
attr_diff['before_header'] = '%s (file attributes)' % dest | |||
attr_diff['after_header'] = '%s (file attributes)' % dest | |||
difflist = [diff, attr_diff] | |||
module.exit_json(changed=changed, msg=msg, backup=backupdest, diff=difflist) | |||
def main(): | |||
# define the available arguments/parameters that a user can pass to | |||
# the module | |||
module_args = dict( | |||
dest=dict(type='str', required=True), | |||
json=dict(default=None), | |||
toml=dict(default=None), | |||
merge=dict(type='bool', default=True), | |||
state=dict(default='present', choices=['absent', 'present']), | |||
create=dict(type='bool', default=False), | |||
backup=dict(type='bool', default=False), | |||
validate=dict(default=None, type='str') | |||
) | |||
# the AnsibleModule object will be our abstraction working with Ansible | |||
# this includes instantiation, a couple of common attr would be the | |||
# args/params passed to the execution, as well as if the module | |||
# supports check mode | |||
module = AnsibleModule( | |||
argument_spec=module_args, | |||
mutually_exclusive=[['json', 'toml']], | |||
add_file_common_args=True, | |||
supports_check_mode=True | |||
) | |||
params = module.params | |||
create = params['create'] | |||
merge = params['merge'] | |||
backup = params['backup'] | |||
dest = params['dest'] | |||
b_dest = to_bytes(dest, errors='surrogate_or_strict') | |||
if os.path.isdir(b_dest): | |||
module.fail_json(rc=256, msg='Destination %s is a directory !' % dest) | |||
par_json, par_toml, jsonbool = params['json'], params['toml'], False | |||
if par_json is None: | |||
conf = par_toml | |||
else: | |||
conf = par_json | |||
jsonbool = True | |||
if params['state'] == 'present': | |||
present(module, dest, conf, jsonbool, merge, create, backup) | |||
else: | |||
absent(module, dest, conf, jsonbool, backup) | |||
if __name__ == '__main__': | |||
main() | |||
@ -0,0 +1,10 @@ | |||
--- | |||
- name: Update config.toml with json | |||
when: jsonconfig is defined | |||
tomlconfig: "dest='{{destination}}' json='{{jsonconfig}}' state={{(remove | default(false) | bool) | ternary('absent','present')}}" | |||
- name: Update config.toml with toml | |||
when: tomlconfig is defined | |||
tomlconfig: "dest='{{destination}}' toml='{{tomlconfig}}' state={{(remove | default(false) | bool) | ternary('absent','present')}}" | |||
@ -0,0 +1,10 @@ | |||
--- | |||
#variable "source" is required | |||
#variable "destination" is required | |||
- hosts: "{{ lookup('env','TF_VAR_TESTNET_NAME') }}:tag_Environment_{{ lookup('env','TF_VAR_TESTNET_NAME') | regex_replace('-','_') }}" | |||
gather_facts: no | |||
roles: | |||
- setfile | |||
@ -0,0 +1,8 @@ | |||
--- | |||
#variable "service" is required | |||
- hosts: "{{ lookup('env','TF_VAR_TESTNET_NAME') }}:tag_Environment_{{ lookup('env','TF_VAR_TESTNET_NAME') | regex_replace('-','_') }}" | |||
roles: | |||
- tomlconfig | |||
@ -0,0 +1,6 @@ | |||
cosmos-sdk (@VERSION@) @STABILITY@; urgency=medium | |||
* Automatic build. See https://github.com/cosmos/cosmos-sdk for more information. | |||
-- Greg Szabo <greg@philosobear.com> @DATETIMESTAMP@ | |||
@ -0,0 +1 @@ | |||
9 |
@ -0,0 +1,15 @@ | |||
Source: cosmos-sdk | |||
Section: net | |||
Priority: optional | |||
Maintainer: Greg Szabo <greg@philosobear.com> | |||
Build-Depends: debhelper (>=9) | |||
Depends: tendermint (>=0.11.0) | |||
Standards-Version: 3.9.6 | |||
Homepage: https://tendermint.com | |||
Package: cosmos-sdk | |||
Architecture: amd64 | |||
Version: @VERSION@ | |||
Installed-Size: @INSTALLEDSIZE@ | |||
Description: cosmos-sdk is a Proof-of-Stake framework | |||
Cosmos-SDK is a general purpose framework for the Tendermint consensus engine to form a Proof-of-Stake cryptocurrency. | |||
@ -0,0 +1,21 @@ | |||
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ | |||
Upstream-Name: cosmos-sdk | |||
Source: https://github.com/cosmos/cosmos-sdk | |||
Files: * | |||
Copyright: 2017 All In Bits, Inc. | |||
License: Apache-2.0 | |||
Licensed under the Apache License, Version 2.0 (the "License"); | |||
you may not use this file except in compliance with the License. | |||
You may obtain a copy of the License at | |||
. | |||
http://www.apache.org/licenses/LICENSE-2.0 | |||
. | |||
Unless required by applicable law or agreed to in writing, software | |||
distributed under the License is distributed on an "AS IS" BASIS, | |||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
See the License for the specific language governing permissions and | |||
limitations under the License. | |||
. | |||
On Debian systems, the full text of the Apache License 2.0 can be found | |||
in the file `/usr/share/common-licenses/Apache-2.0'. |
@ -0,0 +1,46 @@ | |||
#!/bin/sh | |||
# postinst script for cosmos-sdk | |||
# | |||
set -e | |||
# summary of how this script can be called: | |||
# * <postinst> `configure' <most-recently-configured-version> | |||
# * <old-postinst> `abort-upgrade' <new version> | |||
# * <conflictor's-postinst> `abort-remove' `in-favour' <package> | |||
# <new-version> | |||
# * <postinst> `abort-remove' | |||
# * <deconfigured's-postinst> `abort-deconfigure' `in-favour' | |||
# <failed-install-package> <version> `removing' | |||
# <conflicting-package> <version> | |||
# for details, see https://www.debian.org/doc/debian-policy/ or | |||
# the debian-policy package | |||
case "$1" in | |||
configure) | |||
chown cosmos-sdk.cosmos-sdk /etc/cosmos-sdk | |||
sudo -Hu cosmos-sdk basecoin init --home /etc/cosmos-sdk 2B24DEE2364762300168DF19B6C18BCE2D399EA2 | |||
#The above command generates a genesis.json file that contains validators. This is wrong, the validator part should be empty. https://github.com/tendermint/basecoin/issues/124 | |||
sudo -Hu cosmos-sdk tendermint init --home /etc/cosmos-sdk/tendermint | |||
#The above command might need some kind of additional option in the future. https://github.com/tendermint/tendermint/issues/542 | |||
chmod 755 /etc/cosmos-sdk/tendermint | |||
chown cosmos-sdk.cosmos-sdk /etc/cosmos-sdk/tendermint | |||
systemctl daemon-reload | |||
;; | |||
abort-upgrade|abort-remove|abort-deconfigure) | |||
;; | |||
*) | |||
echo "postinst called with unknown argument \`$1'" >&2 | |||
exit 1 | |||
;; | |||
esac | |||
# dh_installdeb will replace this with shell code automatically | |||
# generated by other debhelper scripts. | |||
#DEBHELPER# | |||
exit 0 |
@ -0,0 +1,41 @@ | |||
#!/bin/sh | |||
# postrm script for cosmos-sdk | |||
# | |||
set -e | |||
# summary of how this script can be called: | |||
# * <postrm> `remove' | |||
# * <postrm> `purge' | |||
# * <old-postrm> `upgrade' <new-version> | |||
# * <new-postrm> `failed-upgrade' <old-version> | |||
# * <new-postrm> `abort-install' | |||
# * <new-postrm> `abort-install' <old-version> | |||
# * <new-postrm> `abort-upgrade' <old-version> | |||
# * <disappearer's-postrm> `disappear' <overwriter> | |||
# <overwriter-version> | |||
# for details, see https://www.debian.org/doc/debian-policy/ or | |||
# the debian-policy package | |||
case "$1" in | |||
upgrade|failed-upgrade|abort-upgrade) | |||
systemctl daemon-reload | |||
;; | |||
purge|remove|abort-install|disappear) | |||
systemctl daemon-reload | |||
;; | |||
*) | |||
echo "postrm called with unknown argument \`$1'" >&2 | |||
exit 1 | |||
;; | |||
esac | |||
# dh_installdeb will replace this with shell code automatically | |||
# generated by other debhelper scripts. | |||
#DEBHELPER# | |||
exit 0 |
@ -0,0 +1,38 @@ | |||
#!/bin/sh | |||
# preinst script for cosmos-sdk | |||
# | |||
set -e | |||
# summary of how this script can be called: | |||
# * <new-preinst> `install' | |||
# * <new-preinst> `install' <old-version> | |||
# * <new-preinst> `upgrade' <old-version> | |||
# * <old-preinst> `abort-upgrade' <new-version> | |||
# for details, see https://www.debian.org/doc/debian-policy/ or | |||
# the debian-policy package | |||
case "$1" in | |||
install|upgrade) | |||
if ! grep -q '^cosmos-sdk:' /etc/passwd ; then | |||
useradd -k /dev/null -r -m -b /etc cosmos-sdk | |||
chmod 755 /etc/cosmos-sdk | |||
fi | |||
;; | |||
abort-upgrade) | |||
;; | |||
*) | |||
echo "preinst called with unknown argument \`$1'" >&2 | |||
exit 1 | |||
;; | |||
esac | |||
# dh_installdeb will replace this with shell code automatically | |||
# generated by other debhelper scripts. | |||
#DEBHELPER# | |||
exit 0 |
@ -0,0 +1,39 @@ | |||
#!/bin/sh | |||
# prerm script for cosmos-sdk | |||
# | |||
set -e | |||
# summary of how this script can be called: | |||
# * <prerm> `remove' | |||
# * <old-prerm> `upgrade' <new-version> | |||
# * <new-prerm> `failed-upgrade' <old-version> | |||
# * <conflictor's-prerm> `remove' `in-favour' <package> <new-version> | |||
# * <deconfigured's-prerm> `deconfigure' `in-favour' | |||
# <package-being-installed> <version> `removing' | |||
# <conflicting-package> <version> | |||
# for details, see https://www.debian.org/doc/debian-policy/ or | |||
# the debian-policy package | |||
case "$1" in | |||
remove|upgrade|deconfigure) | |||
systemctl stop cosmos-sdk 2> /dev/null || : | |||
systemctl stop cosmos-sdk-service 2> /dev/null || : | |||
;; | |||
failed-upgrade) | |||
;; | |||
*) | |||
echo "prerm called with unknown argument \`$1'" >&2 | |||
exit 1 | |||
;; | |||
esac | |||
# dh_installdeb will replace this with shell code automatically | |||
# generated by other debhelper scripts. | |||
#DEBHELPER# | |||
exit 0 |
@ -0,0 +1,3 @@ | |||
disable cosmos-sdk.service | |||
disable cosmos-sdk-server.service | |||
@ -0,0 +1,23 @@ | |||
[Unit] | |||
Description=Cosmos SDK Basecoin Tendermint server | |||
Requires=network-online.target | |||
BindTo=cosmos-sdk.service | |||
PartOf=cosmos-sdk.service | |||
After=network-online.target cosmos-sdk.service | |||
PropagatesReloadTo=cosmos-sdk.service | |||
ReloadPropagatedFrom=cosmos-sdk.service | |||
[Service] | |||
Environment="TMHOME=/etc/cosmos-sdk" | |||
Restart=on-failure | |||
User=cosmos-sdk | |||
Group=cosmos-sdk | |||
PermissionsStartOnly=true | |||
ExecStart=/usr/bin/tendermint node | |||
ExecReload=/bin/kill -HUP $MAINPID | |||
KillSignal=SIGTERM | |||
[Install] | |||
WantedBy=multi-user.target | |||
Also=cosmos-sdk.service | |||
@ -0,0 +1,29 @@ | |||
[Unit] | |||
Description=Cosmos-SDK Basecoin | |||
#propagates activation, deactivation and activation fails. | |||
Requires=network-online.target | |||
#propagates activation, deactivation, activation fails and stops | |||
BindTo=cosmos-sdk-server.service | |||
#propagates stop and restart (one-way) | |||
PartOf=cosmos-sdk-server.service | |||
#order | |||
Before=cosmos-sdk-server.service | |||
After=network-online.target | |||
#propagates reload | |||
PropagatesReloadTo=cosmos-sdk-server.service | |||
ReloadPropagatedFrom=cosmos-sdk-server.service | |||
[Service] | |||
Environment="BCHOME=/etc/cosmos-sdk" | |||
Restart=on-failure | |||
User=cosmos-sdk | |||
Group=cosmos-sdk | |||
PermissionsStartOnly=true | |||
ExecStart=/usr/bin/basecoin start --without-tendermint | |||
ExecReload=/bin/kill -HUP $MAINPID | |||
KillSignal=SIGTERM | |||
[Install] | |||
WantedBy=multi-user.target cosmos-sdk-server.service | |||
Also=cosmos-sdk-server.service | |||
@ -0,0 +1,12 @@ | |||
{ | |||
"address": "1B1BE55F969F54064628A63B9559E7C21C925165", | |||
"priv_key": { | |||
"type": "ed25519", | |||
"data": "C70D6934B4F55F1B7BC33B56B9CA8A2061384AFC19E91E44B40C4BBA182953D1619D3678599971ED29C7529DDD4DA537B97129893598A17C82E3AC9A8BA95279" | |||
}, | |||
"pub_key": { | |||
"type": "ed25519", | |||
"data": "619D3678599971ED29C7529DDD4DA537B97129893598A17C82E3AC9A8BA95279" | |||
} | |||
} | |||
@ -0,0 +1,12 @@ | |||
{ | |||
"address": "1DA7C74F9C219229FD54CC9F7386D5A3839F0090", | |||
"priv_key": { | |||
"type": "ed25519", | |||
"data": "34BAE9E65CE8245FAD035A0E3EED9401BDE8785FFB3199ACCF8F5B5DDF7486A8352195DA90CB0B90C24295B90AEBA25A5A71BC61BAB2FE2387241D439698B7B8" | |||
}, | |||
"pub_key": { | |||
"type": "ed25519", | |||
"data": "352195DA90CB0B90C24295B90AEBA25A5A71BC61BAB2FE2387241D439698B7B8" | |||
} | |||
} | |||
@ -0,0 +1,36 @@ | |||
#!/bin/bash | |||
if [ $# -ne 3 ]; then | |||
echo "Usage: $0 <application> <template_source_dir> <SPEC_dir>" | |||
exit 1 | |||
fi | |||
app=$1 | |||
src=$2 | |||
dst=$3 | |||
# Find spectemplate | |||
if [ ! -f "$src/$app.spec" ]; then | |||
if [ ! -f "$src/app-template.spec" ]; then | |||
echo "Source template not found." | |||
exit 1 | |||
else | |||
srcfile="$src/app-template.spec" | |||
fi | |||
else | |||
srcfile="$src/$app.spec" | |||
fi | |||
# Copy spectemplate to SPECS | |||
cp "$srcfile" "$dst/$app.spec" | |||
# Apply any variables defined in .data | |||
if [ -f "$src/$app.data" ]; then | |||
srcdata="$src/$app.data" | |||
source "$srcdata" | |||
for var in `grep -v -e ^# -e ^\s*$ "$srcdata" | grep = | sed 's/\s*=.*$//'` | |||
do | |||
sed -i "s\\@${var}@\\${!var}\\g" "$dst/$app.spec" | |||
done | |||
fi | |||
@ -0,0 +1,5 @@ | |||
PACKAGE_SUMMARY="basecoin is a Proof-of-Stake cryptocurrency and framework" | |||
PACKAGE_URL="https://cosmos.network/" | |||
PACKAGE_ADDITIONAL_HEADER="Provides: basecli" | |||
PACKAGE_DESCRIPTION="Basecoin is an ABCI application designed to be used with the Tendermint consensus engine to form a Proof-of-Stake cryptocurrency. It also provides a general purpose framework for extending the feature-set of the cryptocurrency by implementing plugins." | |||
@ -1,67 +0,0 @@ | |||
Version: @VERSION@ | |||
Release: @BUILD_NUMBER@ | |||
%define __spec_install_post %{nil} | |||
%define debug_package %{nil} | |||
%define __os_install_post %{nil} | |||
Name: basecoin | |||
Summary: basecoin is a Proof-of-Stake cryptocurrency and framework | |||
License: Apache 2.0 | |||
URL: https://tendermint.com/ | |||
Packager: Greg Szabo | |||
Requires: tendermint >= 0.10.0 | |||
Provides: basecli | |||
#Requires(pre): useradd | |||
%description | |||
Basecoin is an ABCI application designed to be used with the Tendermint consensus engine to form a Proof-of-Stake cryptocurrency. It also provides a general purpose framework for extending the feature-set of the cryptocurrency by implementing plugins. | |||
%pre | |||
if ! %{__grep} -q '^%{name}:' /etc/passwd ; then | |||
useradd -k /dev/null -r -m -b %{_sysconfdir} %{name} | |||
chmod 755 %{_sysconfdir}/%{name} | |||
fi | |||
%prep | |||
# Nothing to do here. - It is done in the Makefile. | |||
%build | |||
# Nothing to do here. | |||
%install | |||
cd %{name}-%{version}-%{release} | |||
%{__cp} -a * %{buildroot} | |||
%post | |||
sudo -Hu %{name} basecoin init --home %{_sysconfdir}/%{name} 2B24DEE2364762300168DF19B6C18BCE2D399EA2 | |||
#The above command generates a genesis.json file that contains validators. This is wrong, the validator part should be empty. https://github.com/tendermint/basecoin/issues/124 | |||
sudo -Hu %{name} tendermint init --home %{_sysconfdir}/%{name}/tendermint | |||
#The above command might need some kind of additional option in the future. https://github.com/tendermint/tendermint/issues/542 | |||
chmod 755 %{_sysconfdir}/%{name}/tendermint | |||
#Temporary until https://github.com/tendermint/basecoin/issues/123 | |||
rm -f %{_sysconfdir}/%{name}/key.json | |||
rm -f %{_sysconfdir}/%{name}/key2.json | |||
systemctl daemon-reload | |||
%preun | |||
systemctl stop %{name} 2> /dev/null || : | |||
systemctl stop %{name}-service 2> /dev/null || : | |||
%postun | |||
systemctl daemon-reload | |||
%files | |||
%ghost %attr(0755, %{name}, %{name}) %dir %{_sysconfdir}/%{name} | |||
%ghost %attr(0755, %{name}, %{name}) %dir %{_sysconfdir}/%{name}/tendermint | |||
%{_bindir}/* | |||
%{_sysconfdir}/systemd/system/* | |||
%{_sysconfdir}/systemd/system-preset/* | |||
%dir %{_datadir}/%{name} | |||
%{_datadir}/%{name}/* | |||
%dir %{_defaultlicensedir}/%{name} | |||
%doc %{_defaultlicensedir}/%{name}/LICENSE | |||
@ -0,0 +1,5 @@ | |||
PACKAGE_SUMMARY="cosmos-sdk is a Proof-of-Stake framework" | |||
PACKAGE_URL="https://cosmos.network/" | |||
PACKAGE_ADDITIONAL_HEADER="Provides: basecoin basecli" | |||
PACKAGE_DESCRIPTION="Cosmos-SDK is a general purpose framework for the Tendermint consensus engine to form a Proof-of-Stake cryptocurrency." | |||
@ -0,0 +1,5 @@ | |||
PACKAGE_SUMMARY="ethermint enables ethereum as an ABCI application on tendermint and the COSMOS hub" | |||
PACKAGE_URL="https://tendermint.com/" | |||
PACKAGE_ADDITIONAL_HEADER="Provides: basecli" | |||
PACKAGE_DESCRIPTION="Ethermint enables ethereum to run as an ABCI application on tendermint and the COSMOS hub. This application allows you to get all the benefits of ethereum without having to run your own miners." | |||
@ -0,0 +1,5 @@ | |||
PACKAGE_SUMMARY="gaia - Tendermint Cosmos delegation game chain" | |||
PACKAGE_URL="https://cosmos.network/" | |||
PACKAGE_ADDITIONAL_HEADER="Provides: gaiacli" | |||
PACKAGE_DESCRIPTION="Gaia description comes later." | |||
@ -0,0 +1,5 @@ | |||
PACKAGE_SUMMARY="Trackomatron - Track invoices on the blockchain" | |||
PACKAGE_URL="https://tendermint.com/" | |||
PACKAGE_ADDITIONAL_HEADER="" | |||
PACKAGE_DESCRIPTION="This software is intended to create a space to easily send invoices between and within institutions. Firstly, the commands of trackmatron are separated into two broad categories: submitting information to the blockchain (transactions), and retrieving information from the blockchain (query)." | |||