diff --git a/deployment/CONFIGURATION.md b/deployment/CONFIGURATION.md index 348bfbfb..3ff6f74a 100644 --- a/deployment/CONFIGURATION.md +++ b/deployment/CONFIGURATION.md @@ -38,8 +38,10 @@ cp hosts.yml.example hosts.yml hosts: : ansible_user: + #syslog_server_port: "://:" : ansible_user: + #syslog_server_port: "://:" ``` The config above would install the Oracle on ``, UI on ``, and both Oracle and UI on ``. diff --git a/deployment/hosts.yml.example b/deployment/hosts.yml.example index 8b535d6a..142d2d04 100644 --- a/deployment/hosts.yml.example +++ b/deployment/hosts.yml.example @@ -10,3 +10,4 @@ sokol-kovan: hosts: 127.0.0.1: ansible_user: ubuntu + #syslog_server_port: "udp://127.0.0.1:514" diff --git a/deployment/molecule/default/tests/test_all.py b/deployment/molecule/default/tests/test_all.py index bcf2b47a..f26c6f33 100644 --- a/deployment/molecule/default/tests/test_all.py +++ b/deployment/molecule/default/tests/test_all.py @@ -1,4 +1,5 @@ import os +import pytest import testinfra.utils.ansible_runner testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( @@ -18,3 +19,12 @@ def test_docker_group(host): def test_user(host): assert host.user('poadocker').exists assert 'docker' in host.user('poadocker').groups + + +@pytest.mark.parametrize("filename", [ + ("/etc/rsyslog.d/30-docker.conf"), + ("/etc/rsyslog.d/35-docker-remote-logging.conf") +]) +def test_logging(host, filename): + assert host.file(filename).exists + assert host.file(filename).mode == 0o0644 diff --git a/deployment/molecule/default/tests/test_oracle.py b/deployment/molecule/default/tests/test_oracle.py index 64c25423..7046a85b 100644 --- a/deployment/molecule/default/tests/test_oracle.py +++ b/deployment/molecule/default/tests/test_oracle.py @@ -29,8 +29,13 @@ def test_services(host, service): assert host.service(service).is_running -def test_remote_logging(host): - assert host.file('/etc/rsyslog.d/35-remote-logging.conf').exists +@pytest.mark.parametrize("filename", [ + ("/etc/rsyslog.d/31-oracle-docker.conf"), + ("/etc/rsyslog.d/36-oracle-remote-logging.conf") +]) +def test_logging(host, filename): + assert host.file(filename).exists + assert host.file(filename).mode == 0o0644 def test_docker_config(host): diff --git a/deployment/roles/common/tasks/logging.yml b/deployment/roles/common/tasks/logging.yml new file mode 100644 index 00000000..45857f74 --- /dev/null +++ b/deployment/roles/common/tasks/logging.yml @@ -0,0 +1,29 @@ +- name: Set the local docker logs configuration file + template: + src: 30-docker.conf.j2 + dest: /etc/rsyslog.d/30-docker.conf + owner: root + group: root + mode: 0644 + +- name: Set the log configuration file to send docker logs to remote server + template: + src: 35-docker-remote-logging.conf.j2 + dest: /etc/rsyslog.d/35-docker-remote-logging.conf + owner: root + group: root + mode: 0644 + when: syslog_server_port is defined + +- name: Set the logrotate config file + template: + src: docker-logs.j2 + dest: /etc/logrotate.d/docker-logs + owner: root + group: root + mode: 0644 + +- name: restart rsyslog + service: + name: rsyslog + state: restarted diff --git a/deployment/roles/common/tasks/main.yml b/deployment/roles/common/tasks/main.yml index 091d1908..ddeaa628 100644 --- a/deployment/roles/common/tasks/main.yml +++ b/deployment/roles/common/tasks/main.yml @@ -1,2 +1,3 @@ - include_tasks: dependencies.yml - include_tasks: repo.yml +- include_tasks: logging.yml diff --git a/deployment/roles/common/tasks/repo.yml b/deployment/roles/common/tasks/repo.yml index 7c32ee5b..4f4f0644 100644 --- a/deployment/roles/common/tasks/repo.yml +++ b/deployment/roles/common/tasks/repo.yml @@ -2,5 +2,6 @@ git: repo: "{{ bridge_repo }}" dest: "{{ bridge_path }}" - force: yes + force: no + update: no version: "{{ bridge_repo_branch }}" diff --git a/deployment/roles/common/templates/30-docker.conf.j2 b/deployment/roles/common/templates/30-docker.conf.j2 new file mode 100644 index 00000000..f28484c1 --- /dev/null +++ b/deployment/roles/common/templates/30-docker.conf.j2 @@ -0,0 +1,6 @@ +$FileCreateMode 0644 + +if $programname startswith 'docker' then \ + /var/log/docker/no_tag/docker.log + +$FileCreateMode 0600 diff --git a/deployment/roles/oracle/templates/35-remote-logging.conf.j2 b/deployment/roles/common/templates/35-docker-remote-logging.conf.j2 similarity index 89% rename from deployment/roles/oracle/templates/35-remote-logging.conf.j2 rename to deployment/roles/common/templates/35-docker-remote-logging.conf.j2 index 08420b15..f7bb5ea4 100644 --- a/deployment/roles/oracle/templates/35-remote-logging.conf.j2 +++ b/deployment/roles/common/templates/35-docker-remote-logging.conf.j2 @@ -11,7 +11,7 @@ template(name="RemoteForwardFormat" type="list") { property(name="msg") } -if $programname startswith 'oracle_bridge_' or $programname startswith 'docker' then { +if $programname startswith 'docker' then { action( type="omfwd" protocol="{{ syslog_server_port.split(":")[0] }}" @@ -25,4 +25,4 @@ action( queue.Type="LinkedList" ResendLastMSGOnReconnect="on" ) -} \ No newline at end of file +} diff --git a/deployment/roles/oracle/templates/docker-logs.j2 b/deployment/roles/common/templates/docker-logs.j2 similarity index 100% rename from deployment/roles/oracle/templates/docker-logs.j2 rename to deployment/roles/common/templates/docker-logs.j2 diff --git a/deployment/roles/oracle/tasks/logging.yml b/deployment/roles/oracle/tasks/logging.yml index 52441d30..5cb60e03 100644 --- a/deployment/roles/oracle/tasks/logging.yml +++ b/deployment/roles/oracle/tasks/logging.yml @@ -19,29 +19,21 @@ - name: Set the local container logs configuration file template: - src: 30-docker.conf.j2 - dest: /etc/rsyslog.d/30-docker.conf + src: 31-oracle-docker.conf.j2 + dest: /etc/rsyslog.d/31-oracle-docker.conf owner: root group: root mode: 0644 - name: Set the log configuration file to send container logs to remote server template: - src: 35-remote-logging.conf.j2 - dest: /etc/rsyslog.d/35-remote-logging.conf + src: 36-oracle-remote-logging.conf.j2 + dest: /etc/rsyslog.d/36-oracle-remote-logging.conf owner: root group: root mode: 0644 when: syslog_server_port is defined -- name: Set the logrotate config file - template: - src: docker-logs.j2 - dest: /etc/logrotate.d/docker-logs - owner: root - group: root - mode: 0644 - - name: Discarding unwanted messages in rsyslog blockinfile: path: /etc/rsyslog.conf diff --git a/deployment/roles/oracle/tasks/main.yml b/deployment/roles/oracle/tasks/main.yml index 1183938b..bc876124 100644 --- a/deployment/roles/oracle/tasks/main.yml +++ b/deployment/roles/oracle/tasks/main.yml @@ -1,5 +1,5 @@ - include_tasks: pre_config.yml +- include_tasks: logging.yml - include_tasks: jumpbox.yml - include_tasks: post_config.yml -- include_tasks: logging.yml - include_tasks: servinstall.yml diff --git a/deployment/roles/oracle/templates/30-docker.conf.j2 b/deployment/roles/oracle/templates/31-oracle-docker.conf.j2 similarity index 73% rename from deployment/roles/oracle/templates/30-docker.conf.j2 rename to deployment/roles/oracle/templates/31-oracle-docker.conf.j2 index 34646d5e..dc98ce57 100644 --- a/deployment/roles/oracle/templates/30-docker.conf.j2 +++ b/deployment/roles/oracle/templates/31-oracle-docker.conf.j2 @@ -1,12 +1,11 @@ $FileCreateMode 0644 -template(name="DockerLogFileName" type="list") { +template(name="DockerLogFileName_Oracle" type="list") { constant(value="/var/log/docker/") property(name="syslogtag" securepath="replace" regex.type="ERE" regex.submatch="1" regex.expression="bridge_(.*)\\/[a-zA-Z0-9]+\\[") constant(value="/docker.log") } if $programname startswith 'oracle_bridge_' then \ - ?DockerLogFileName -else - /var/log/docker/no_tag/docker.log + ?DockerLogFileName_Oracle + $FileCreateMode 0600 diff --git a/deployment/roles/oracle/templates/36-oracle-remote-logging.conf.j2 b/deployment/roles/oracle/templates/36-oracle-remote-logging.conf.j2 new file mode 100644 index 00000000..f7bad3f3 --- /dev/null +++ b/deployment/roles/oracle/templates/36-oracle-remote-logging.conf.j2 @@ -0,0 +1,15 @@ +if $programname startswith 'oracle_bridge_' then { +action( + type="omfwd" + protocol="{{ syslog_server_port.split(":")[0] }}" + target="{{ (syslog_server_port.split(":")[1])[2:] }}" + port="{{ syslog_server_port.split(":")[2] }}" + template="RemoteForwardFormat" + queue.SpoolDirectory="/var/spool/rsyslog" + queue.FileName="remote" + queue.MaxDiskSpace="1g" + queue.SaveOnShutdown="on" + queue.Type="LinkedList" + ResendLastMSGOnReconnect="on" + ) +} diff --git a/deployment/roles/ui/tasks/logging.yml b/deployment/roles/ui/tasks/logging.yml new file mode 100644 index 00000000..affa292a --- /dev/null +++ b/deployment/roles/ui/tasks/logging.yml @@ -0,0 +1,40 @@ +- name: Slurp docker compose file + slurp: + src: "{{ bridge_path }}/ui/docker-compose.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 new docker-compose file + copy: + content: "{{ docker_compose_parsed | to_yaml }}" + dest: "{{ bridge_path }}/ui/docker-compose.yml" + +- name: Set the local container logs configuration file + template: + src: 32-ui-docker.conf.j2 + dest: /etc/rsyslog.d/32-ui-docker.conf + owner: root + group: root + mode: 0644 + +- name: Set the log configuration file to send container logs to remote server + template: + src: 37-ui-remote-logging.conf.j2 + dest: /etc/rsyslog.d/37-ui-remote-logging.conf + owner: root + group: root + mode: 0644 + when: syslog_server_port is defined + +- name: restart rsyslog + service: + name: rsyslog + state: restarted diff --git a/deployment/roles/ui/tasks/main.yml b/deployment/roles/ui/tasks/main.yml index 9606ad58..f082b17a 100644 --- a/deployment/roles/ui/tasks/main.yml +++ b/deployment/roles/ui/tasks/main.yml @@ -1,3 +1,4 @@ - include_tasks: pre_config.yml +- include_tasks: logging.yml - include_tasks: jumpbox.yml - include_tasks: servinstall.yml diff --git a/deployment/roles/ui/templates/32-ui-docker.conf.j2 b/deployment/roles/ui/templates/32-ui-docker.conf.j2 new file mode 100644 index 00000000..ca064f3c --- /dev/null +++ b/deployment/roles/ui/templates/32-ui-docker.conf.j2 @@ -0,0 +1,11 @@ +$FileCreateMode 0644 +template(name="DockerLogFileName_UI" type="list") { + constant(value="/var/log/docker/") + property(name="syslogtag" securepath="replace" regex.type="ERE" regex.submatch="1" regex.expression="ui_(.*)\\/[a-zA-Z0-9]+\\[") + constant(value="/docker.log") +} + +if $programname startswith 'ui_' then \ + ?DockerLogFileName_UI + +$FileCreateMode 0600 diff --git a/deployment/roles/ui/templates/37-ui-remote-logging.conf.j2 b/deployment/roles/ui/templates/37-ui-remote-logging.conf.j2 new file mode 100644 index 00000000..3869fcee --- /dev/null +++ b/deployment/roles/ui/templates/37-ui-remote-logging.conf.j2 @@ -0,0 +1,15 @@ +if $programname startswith 'ui_' then { +action( + type="omfwd" + protocol="{{ syslog_server_port.split(":")[0] }}" + target="{{ (syslog_server_port.split(":")[1])[2:] }}" + port="{{ syslog_server_port.split(":")[2] }}" + template="RemoteForwardFormat" + queue.SpoolDirectory="/var/spool/rsyslog" + queue.FileName="remote" + queue.MaxDiskSpace="1g" + queue.SaveOnShutdown="on" + queue.Type="LinkedList" + ResendLastMSGOnReconnect="on" + ) +}