More straightforward approach to configure logging for oracle services (#345)

This commit is contained in:
Alexander Kolotov 2020-06-08 15:02:03 +03:00 committed by GitHub
parent e7eb8ec758
commit da60edae4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 18 deletions

@ -0,0 +1,28 @@
#!/usr/bin/python3
from yaml import safe_load, safe_dump
from argparse import ArgumentParser
from os.path import basename
import sys
parser = ArgumentParser()
parser.add_argument('composefile', type=str, nargs=1, metavar='compose-file', help='docker-compose.yml')
parser.add_argument('-d', action='store_true', help='output result instead of writing the file', dest='debug')
if basename(sys.argv[0]) == "ipykernel_launcher.py":
args = parser.parse_args(['docker-compose.yml'])
else:
args = parser.parse_args()
file_to_operate = args.composefile[0]
with open(file_to_operate) as composefile:
composecnt=composefile.read()
yml = safe_load(composecnt)
for i in yml['services']:
yml['services'][i]['logging'] = {'driver': 'syslog','options': {'tag': '{{.Name}}/{{.ID}}'}}
if args.debug or (basename(sys.argv[0]) == "ipykernel_launcher.py"):
print(safe_dump(yml))
else:
with open(file_to_operate, 'w') as composefile:
safe_dump(yml, composefile, explicit_start=True)

@ -1,19 +1,5 @@
---
- name: Slurp docker compose file
slurp:
src: "{{ bridge_path }}/oracle/{{ file }}.yml"
register: docker_compose_slurp
- name: Parse docker compose file
set_fact:
docker_compose_parsed: "{{ docker_compose_slurp['content'] | b64decode | from_yaml }}"
- name: Set logger to remote server
set_fact:
docker_compose_parsed: "{{ docker_compose_parsed |combine({'services': {item: {'logging': {'driver': 'syslog','options': {'tag': '{{.Name}}/{{.ID}}'}}}}}, recursive=True) }}"
with_items: "{{ docker_compose_parsed.services }}"
- name: Write updated docker file
copy:
content: "{{ docker_compose_parsed | to_yaml }}"
dest: "{{ bridge_path }}/oracle/{{ file }}.yml"
- name: Change logging facility to forward logs to syslog
script: modify_to_use_syslog.py "{{ bridge_path }}/oracle/{{ file }}.yml"
args:
executable: python3