From bb6078b438de5eb4d842bbad069f1fcd358f61ea Mon Sep 17 00:00:00 2001 From: jurgenhaas <juergen@paragon-es.de> Date: Fri, 20 Jan 2017 13:01:01 +0100 Subject: [PATCH] Restructure role --- tasks/apache.yml | 21 ++++++ tasks/configure.yml | 60 ++++++++++++++++ tasks/haproxy.yml | 16 +++++ tasks/main.yml | 164 +++----------------------------------------- tasks/mysql.yml | 10 +++ tasks/prepare.yml | 36 ++++++++++ tasks/softnet.yml | 10 +++ tasks/varnish.yml | 8 +++ 8 files changed, 171 insertions(+), 154 deletions(-) create mode 100644 tasks/apache.yml create mode 100644 tasks/configure.yml create mode 100644 tasks/haproxy.yml create mode 100644 tasks/mysql.yml create mode 100644 tasks/prepare.yml create mode 100644 tasks/softnet.yml create mode 100644 tasks/varnish.yml diff --git a/tasks/apache.yml b/tasks/apache.yml new file mode 100644 index 0000000..d3a18da --- /dev/null +++ b/tasks/apache.yml @@ -0,0 +1,21 @@ +--- +# file: roles/netdata/tasks/apache.yml + +- name: "Enable Apache Status Module" + apache2_module: + name: 'status' + state: 'present' + notify: "Restart Apache" + +- name: "Apache Status Site" + template: + src: 'apache.conf' + dest: '/etc/apache2/sites-available/status{{ apache_conf_ext|default('.conf') }}' + owner: 'root' + group: 'root' + mode: 644 + notify: "Restart Apache" + +- name: "Enable Apache Status Site" + command: a2ensite status creates=/etc/apache2/sites-enabled/status{{ apache_conf_ext|default('.conf') }} + notify: "Restart Apache" diff --git a/tasks/configure.yml b/tasks/configure.yml new file mode 100644 index 0000000..30a8d85 --- /dev/null +++ b/tasks/configure.yml @@ -0,0 +1,60 @@ +--- +# file: roles/netdata/tasks/configure.yml + +- name: "Add User to Admins" + user: + name: 'netdata' + groups: 'adm' + append: yes + +- name: "Configure Registry" + ini_file: + dest: '/etc/netdata/netdata.conf' + create: yes + section: 'registry' + option: '{{ item.option }}' + value: '{{ item.value }}' + with_items: + - option: 'enabled' + value: '{{ (netdata_registry|default("pmon1") == inventory_hostname)|ternary("yes", "no") }}' + - option: 'registry to announce' + value: 'http://{{ netdata_registry|default("pmon1") }}:19999' + notify: + - "Restart NetData" + +- name: "Configure NetData" + template: + src: '{{ item }}' + dest: '/etc/netdata/{{ item }}' + owner: 'root' + group: 'root' + mode: 644 + backup: yes + with_items: + - 'health_alarm_notify.conf' + notify: + - "Restart NetData" + +- name: "Patch Startup Script" + lineinfile: + dest: '/etc/init.d/netdata' + regexp: 'killproc -p \$\{PIDFILE\} \$DAEMON_PATH/\$DAEMON' + line: ' killproc -p ${PIDFILE} $DAEMON_PATH/$DAEMON && sleep 1' + when: ansible_lsb.major_release == '12' + +- name: "Check if KSM is available" + stat: path='/sys/kernel/mm/ksm' + register: ksm + +# Note: copy module doesn't work here because parent directory /sys +# is not writable, not even by root +- name: "Configure KSM" + shell: echo {{ item.value }} >/sys/kernel/mm/ksm/{{ item.file }} + with_items: + - file: 'run' + value: '1' + - file: 'sleep_millisecs' + value: '1000' + when: ksm.stat.exists + notify: + - "Restart NetData" diff --git a/tasks/haproxy.yml b/tasks/haproxy.yml new file mode 100644 index 0000000..fd68345 --- /dev/null +++ b/tasks/haproxy.yml @@ -0,0 +1,16 @@ +--- +# file: roles/netdata/tasks/haproxy.yml + +- name: "Add NetData User to HaProxy Group" + user: + name: 'netdata' + groups: 'haproxy' + append: yes + +- name: "Configure HaProxy Plugin" + copy: + src: 'haproxy.conf' + dest: '/etc/netdata/python.d/haproxy.conf' + owner: 'netdata' + group: 'netdata' + mode: '660' diff --git a/tasks/main.yml b/tasks/main.yml index 97fc332..96b543f 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -7,168 +7,24 @@ - block: - - name: "Install required packages" - apt: - pkg={{ item }} - state=installed - update_cache=yes - with_items: - - zlib1g-dev - - gcc - - make - - git - - autoconf - - autogen - - automake - - pkg-config - - uuid-dev - - python-dev - - python-yaml - #FireQOS available from 15.04 - #- firehol - - - name: "Remove existing components" - file: - path: '{{ item }}' - state: 'absent' - with_items: - - '/opt/netdata' - - '/etc/netdata' - - '/etc/init.d/netdata' - - '/etc/logrotate.d/netdata' - when: netdata_force_reset - - - name: "Ensure Directory" - file: - path='/etc/netdata/python.d' - state='directory' + - include: prepare.yml - include: install.yml - - name: "Add User to Admins" - user: - name: 'netdata' - groups: 'adm' - append: yes - - - name: "Configure Registry" - ini_file: - dest='/etc/netdata/netdata.conf' - create=yes - section='registry' - option='{{ item.option }}' - value='{{ item.value }}' - with_items: - - option: 'enabled' - value: '{{ (netdata_registry|default("pmon1") == inventory_hostname)|ternary("yes", "no") }}' - - option: 'registry to announce' - value: 'http://{{ netdata_registry|default("pmon1") }}:19999' - notify: - - "Restart NetData" - - - name: "Configure NetData" - template: - src='{{ item }}' - dest='/etc/netdata/{{ item }}' - owner='root' - group='root' - mode=644 - backup=yes - with_items: - - 'health_alarm_notify.conf' - notify: - - "Restart NetData" - - - name: "Patch Startup Script" - lineinfile: - dest: '/etc/init.d/netdata' - regexp: 'killproc -p \$\{PIDFILE\} \$DAEMON_PATH/\$DAEMON' - line: ' killproc -p ${PIDFILE} $DAEMON_PATH/$DAEMON && sleep 1' - when: ansible_lsb.major_release == '12' - - - - block: - - - name: "Add NetData User to Varnish Group" - user: - name: 'netdata' - groups: 'varnish' - append: yes - - when: groups['varnishserver'] is defined and inventory_hostname in groups['varnishserver'] - - - block: - - - name: "Add NetData User to HaProxy Group" - user: - name: 'netdata' - groups: 'haproxy' - append: yes - - - name: "Configure HaProxy Plugin" - copy: - src: 'haproxy.conf' - dest: '/etc/netdata/python.d/haproxy.conf' - owner: 'netdata' - group: 'netdata' - mode: '660' - - when: groups['proxyserver'] is defined and inventory_hostname in groups['proxyserver'] - - - block: - - - name: "Enable Apache Status Module" - apache2_module: - name=status - state=present - notify: "Restart Apache" - - - name: "Apache Status Site" - template: - src=apache.conf - dest=/etc/apache2/sites-available/status{{ apache_conf_ext|default('.conf') }} - owner=root - group=root - mode=0644 - notify: "Restart Apache" - - - name: "Enable Apache Status Site" - command: a2ensite status creates=/etc/apache2/sites-enabled/status{{ apache_conf_ext|default('.conf') }} - notify: "Restart Apache" + - include: configure.yml + - include: apache.yml when: groups['webserver'] is defined and inventory_hostname in groups['webserver'] - - name: "Configure Plugin: MySQL" - replace: - dest: '/etc/netdata/python.d/mysql.conf' - regexp: '#[\s]*pass[\s]*:[\s]*''''' - replace: 'pass : ''{{ mysql_root_password|default("root") }}''' - notify: - - "Restart NetData" + - include: haproxy.yml + when: groups['proxyserver'] is defined and inventory_hostname in groups['proxyserver'] - - name: "Configure Alert: Softnet" - replace: - dest: '/etc/netdata/health.d/softnet.conf' - regexp: 'warn: \$this > \(\(\$status >= \$WARNING\) \? \(0\) : \(10\)\)' - replace: 'warn: $this > (($status >= $WARNING) ? (0) : (50))' - notify: - - "Restart NetData" + - include: mysql.yml + when: groups['dbserver-mysql'] is defined and inventory_hostname in groups['dbserver-mysql'] - - name: "Check if KSM is available" - stat: path='/sys/kernel/mm/ksm' - register: ksm + - include: softnet.yml - # Note: copy module doesn't work here because parent directory /sys - # is not writable, not even by root - - name: "Configure KSM" - shell: echo {{ item.value }} >/sys/kernel/mm/ksm/{{ item.file }} - with_items: - - file: 'run' - value: '1' - - file: 'sleep_millisecs' - value: '1000' - when: ksm.stat.exists - notify: - - "Restart NetData" + - include: varnish.yml + when: groups['varnishserver'] is defined and inventory_hostname in groups['varnishserver'] when: '"netdata" not in excluded_roles' diff --git a/tasks/mysql.yml b/tasks/mysql.yml new file mode 100644 index 0000000..fd40d73 --- /dev/null +++ b/tasks/mysql.yml @@ -0,0 +1,10 @@ +--- +# file: roles/netdata/tasks/mysql.yml + +- name: "Configure Plugin: MySQL" + replace: + dest: '/etc/netdata/python.d/mysql.conf' + regexp: '#[\s]*pass[\s]*:[\s]*''''' + replace: 'pass : ''{{ mysql_root_password|default("root") }}''' + notify: + - "Restart NetData" diff --git a/tasks/prepare.yml b/tasks/prepare.yml new file mode 100644 index 0000000..607f3f5 --- /dev/null +++ b/tasks/prepare.yml @@ -0,0 +1,36 @@ +--- +# file: roles/netdata/tasks/prepare.yml + +- name: "Install required packages" + apt: + pkg: '{{ item }}' + state: 'installed' + update_cache: yes + with_items: + - 'zlib1g-dev' + - 'gcc' + - 'make' + - 'git' + - 'autoconf' + - 'autogen' + - 'automake' + - 'pkg-config' + - 'uuid-dev' + - 'python-dev' + - 'python-yaml' + +- name: "Remove existing components" + file: + path: '{{ item }}' + state: 'absent' + with_items: + - '/opt/netdata' + - '/etc/netdata' + - '/etc/init.d/netdata' + - '/etc/logrotate.d/netdata' + when: netdata_force_reset + +- name: "Ensure Directory" + file: + path: '/etc/netdata/python.d' + state: 'directory' diff --git a/tasks/softnet.yml b/tasks/softnet.yml new file mode 100644 index 0000000..3fe4f6a --- /dev/null +++ b/tasks/softnet.yml @@ -0,0 +1,10 @@ +--- +# file: roles/netdata/tasks/softnet.yml + +- name: "Configure Alert: Softnet" + replace: + dest: '/etc/netdata/health.d/softnet.conf' + regexp: 'warn: \$this > \(\(\$status >= \$WARNING\) \? \(0\) : \(10\)\)' + replace: 'warn: $this > (($status >= $WARNING) ? (0) : (50))' + notify: + - "Restart NetData" diff --git a/tasks/varnish.yml b/tasks/varnish.yml new file mode 100644 index 0000000..e8ed255 --- /dev/null +++ b/tasks/varnish.yml @@ -0,0 +1,8 @@ +--- +# file: roles/netdata/tasks/varnish.yml + +- name: "Add NetData User to Varnish Group" + user: + name: 'netdata' + groups: 'varnish' + append: yes -- GitLab