diff --git a/README.md b/README.md index daecf96..f0332fa 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ virtualenv must be installed on the system. - monasca_log_level: Log level of the agent logs, default is WARN - pip_index_url: Index URL to use instead of the default for installing pip packages - run_mode: One of Deploy, Stop, Install, Start, or Use. The default is Deploy which will do Install, Configure, then Start. 'Use' can be set if the only desire is to use the monasca_agent_plugin module +- pip_extra_depedencies: The list with extra packages that should be installed via pip Optionally supply monasca_checks variable which is a dictionary with each entry consisting of a plugin name followed by the plugin config, typically with two sections init_config and instances. Refer to the specific monasca-agent plugin documentation diff --git a/defaults/main.yml b/defaults/main.yml index 119a00b..20a737e 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -3,9 +3,23 @@ monasca_checks: {} monasca_agent_system_only: False +monasca_agent_overwrite_config: True agent_reconfigure_script: /usr/local/bin/monasca-reconfigure +monasca_agent_check_frequency: 60 + +log_dir: /var/log +monasca_log_dir: "{{ log_dir }}/monasca" +monasca_agent_log_dir: "{{ monasca_log_dir }}/agent" skip_install: False -monasca_virtualenv_dir: /opt/monasca +monasca_agent_venv_dir: /opt/monasca-agent pip_conf_dir: ~/.pip + run_mode: Deploy +pbr_version: 1.8.1 + +monasca_agent_system_group: mon-agent +monasca_agent_system_user: mon-agent +monasca_group: monasca + +pip_extra_depedencies: [] diff --git a/handlers/main.yml b/handlers/main.yml index 053046d..aabcc82 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -1,5 +1,7 @@ --- # ©Copyright 2015 Hewlett-Packard Development Company, L.P. +- name: restart monasca-agent + service: name=monasca-agent state=restarted enabled=yes - name: run monasca-setup command: "{{agent_reconfigure_script}}" diff --git a/meta/main.yml b/meta/main.yml index b171e98..082c5cd 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -9,6 +9,9 @@ galaxy_info: - name: Ubuntu versions: - all + - name: RedHat + versions: + - all categories: - monitoring dependencies: [] diff --git a/tasks/apt-packages.yml b/tasks/apt-packages.yml new file mode 100644 index 0000000..95d87cd --- /dev/null +++ b/tasks/apt-packages.yml @@ -0,0 +1,4 @@ +- name: Install deps to avoid pip doing compilation or enable it + apt: name={{item}} state=present + with_items: dependencies + when: not skip_install diff --git a/tasks/configure.yml b/tasks/configure.yml index 6311fd8..338985f 100644 --- a/tasks/configure.yml +++ b/tasks/configure.yml @@ -1,24 +1,101 @@ --- # ©Copyright 2015 Hewlett-Packard Development Company, L.P. -- name: create conf.d dir and custom plugin dirs - file: path="{{item}}" state=directory owner=root group=root mode=755 +- name: Setup group + group: name="{{item}}" system=yes + with_items: + - "{{monasca_agent_system_group}}" + - "{{ monasca_group }}" + +- name: Setup user + user: + name: "{{ monasca_agent_system_user }}" + system: yes + group: "{{ monasca_agent_system_group }}" + groups: "{{ monasca_group }}" + +- name: Create reconfigure script + template: + dest="{{agent_reconfigure_script}}" + src=monasca-reconfigure.j2 + owner={{monasca_agent_system_user}} + group={{monasca_agent_system_group}} + mode=750 + +- name: Create conf.d dir and custom plugin dirs + file: path="{{item}}" state=directory owner={{monasca_agent_system_user}} group={{monasca_agent_system_group}} mode=750 with_items: - "{{monasca_conf_dir}}/agent/conf.d" - "{{monasca_agent_check_plugin_dir}}" - "{{monasca_agent_detection_plugin_dir}}" -- name: Create additional plugins config - template: dest="{{monasca_conf_dir}}/agent/conf.d/{{item.key}}.yaml" src=plugin.yaml.j2 owner=root group=root mode=644 +- name: Create log dir + file: + path={{monasca_agent_log_dir}} + state=directory + owner={{monasca_agent_system_user}} + group={{monasca_agent_system_group}} + mode="u+rwX,g+rX,o-rwx" + recurse=yes + +- name: Run monasca-setup to create all default config files + command: "{{ agent_reconfigure_script }}" + +- name: Check for existing plugins configs created by monasca-setup + stat: path="{{ monasca_conf_dir }}/agent/conf.d/{{ item.key }}.yaml" + register: confs + ignore_errors: yes with_dict: monasca_checks - notify: run monasca-setup -# Instead of running this directly by creating a file to run it changes such as user/pass will trigger a rerun. Also a user can run it manually -- name: Create reconfigure script - template: dest="{{agent_reconfigure_script}}" src=monasca-reconfigure.j2 owner=root group=root mode=750 - notify: run monasca-setup +- name: Create additional plugins config + template: + dest="{{monasca_conf_dir}}/agent/conf.d/{{item.item.key}}.yaml" + src=plugin.yaml.j2 + owner={{monasca_agent_system_user}} + group={{monasca_agent_system_group}} + mode=640 + with_items: confs.results + when: not item.stat.exists + notify: + - restart monasca-agent + +- name: Create config files fragments for existing configuration + template: + dest="{{monasca_conf_dir}}/agent/conf.d/{{item.item.key}}.yaml.2" + src=plugin.yaml.j2 + owner={{monasca_agent_system_user}} + group={{monasca_agent_system_group}} + mode=640 + with_items: confs.results + when: item.stat.exists + +- name: Assemble config from fragments + assemble: + src="{{ monasca_conf_dir }}/agent/conf.d/" + dest="{{ monasca_conf_dir }}/agent/conf.d/{{ item.item.key }}.yaml" + regexp="{{ item.item.key }}\.yaml.*" + owner={{monasca_agent_system_user}} + group={{monasca_agent_system_group}} + mode=640 + with_items: confs.results + notify: + - restart monasca-agent + +- name: Remove file fragments + file: path="{{monasca_conf_dir}}/agent/conf.d/{{item.item.key}}.yaml.2" state=absent + with_items: confs.results - meta: flush_handlers -- name: Enable Monasca-Agent - service: name=monasca-agent state=started enabled=yes +- name: Set proper attributes of files + file: + path="{{item}}" + state=directory + owner={{monasca_agent_system_user}} + group={{monasca_agent_system_group}} + mode="u+rwX,g+rX,o-rwx" + recurse=yes + with_items: + - "{{monasca_conf_dir}}/agent" + - "{{monasca_agent_log_dir}}" + - "{{monasca_agent_venv_dir}}" diff --git a/tasks/install.yml b/tasks/install.yml index 9326f69..b6b97a7 100644 --- a/tasks/install.yml +++ b/tasks/install.yml @@ -2,14 +2,28 @@ # ©Copyright 2015 Hewlett-Packard Development Company, L.P. - include: pip_index.yml + when: not skip_install -- name: Install deps to avoid pip doing compilation or enable it - apt: name={{item}} state=present - with_items: dependencies +- name: Gather OS Specific Variables + include_vars: "{{ item }}" + with_first_found: + - "{{ ansible_distribution }}-{{ ansible_distribution_version }}.yml" + - "{{ ansible_distribution }}.yml" + - "{{ ansible_os_family }}.yml" + - "defaults.yml" + +- include: apt-packages.yml + when: ansible_pkg_mgr == 'apt' +- include: yum_packages.yml + when: ansible_pkg_mgr == 'yum' - name: Upgrade pip in virtualenv pip: name=pip state=latest virtualenv="{{monasca_virtualenv_dir}}" +- name: Install pbr + pip: name=pbr version="{{ pbr_version }}" state=present virtualenv="{{ monasca_virtualenv_dir }}" + when: not skip_install + - name: pip install latest monasca-agent in a virtualenv pip: name=monasca-agent state=latest virtualenv="{{monasca_virtualenv_dir}}" notify: run monasca-setup @@ -19,3 +33,8 @@ pip: name=monasca-agent state=present version="{{monasca_agent_version}}" virtualenv="{{monasca_virtualenv_dir}}" notify: run monasca-setup when: monasca_agent_version is defined + + +- name: Install pip extra depedencies + pip: name="{{item.name}}" state=present version="{{item.version}}" virtualenv="{{monasca_virtualenv_dir}}" + with_items: "{{pip_extra_depedencies}}" diff --git a/tasks/pip_index.yml b/tasks/pip_index.yml index f4a5586..70514dc 100644 --- a/tasks/pip_index.yml +++ b/tasks/pip_index.yml @@ -1,10 +1,13 @@ --- # ©Copyright 2015 Hewlett-Packard Development Company, L.P. +- stat: path={{ pip_conf_dir }}/pip.conf + register: spc + - name: Create pip conf dir if pip index URL specified file: path={{ pip_conf_dir }} state=directory owner=root group=root mode=770 - when: pip_index_url is defined + when: pip_index_url is defined and not spc.exists - name: Use pip index URL if specified template: dest="{{ pip_conf_dir }}/pip.conf" src=pip.conf.j2 backup=yes owner=root group=root mode=660 - when: pip_index_url is defined + when: pip_index_url is defined and not spc.exists diff --git a/tasks/yum_packages.yml b/tasks/yum_packages.yml new file mode 100644 index 0000000..2fd121d --- /dev/null +++ b/tasks/yum_packages.yml @@ -0,0 +1,4 @@ +- name: Install deps to avoid pip doing compilation or enable it + yum: name={{item}} state=present + with_items: dependencies + when: not skip_install diff --git a/templates/monasca-reconfigure.j2 b/templates/monasca-reconfigure.j2 index 5c32474..b9482c2 100644 --- a/templates/monasca-reconfigure.j2 +++ b/templates/monasca-reconfigure.j2 @@ -10,4 +10,4 @@ {% if monasca_agent_check_frequency is defined %} --check_frequency '{{monasca_agent_check_frequency}}' {% endif %} \ {% if monasca_agent_system_only %} --system_only {% endif %} \ {% if monasca_log_level is defined %} --log_level '{{monasca_log_level}}' {% endif %} \ - --overwrite + {% if monasca_agent_overwrite_config %} --overwrite{% endif %} diff --git a/templates/plugin.yaml.j2 b/templates/plugin.yaml.j2 index ddd8ae1..b7ae23b 100644 --- a/templates/plugin.yaml.j2 +++ b/templates/plugin.yaml.j2 @@ -1 +1 @@ -{{item.value | to_nice_yaml}} +{{item.item.value | to_nice_yaml}} diff --git a/vars/Debian.yml b/vars/Debian.yml new file mode 100644 index 0000000..9f43e65 --- /dev/null +++ b/vars/Debian.yml @@ -0,0 +1,7 @@ +--- +dependencies: + - python-dev + - python-yaml + - build-essential + - libxml2-dev + - libxslt1-dev diff --git a/vars/RedHat.yml b/vars/RedHat.yml new file mode 100644 index 0000000..c01b747 --- /dev/null +++ b/vars/RedHat.yml @@ -0,0 +1,10 @@ +--- +dependencies: + - python-devel + - PyYAML + - gcc + - gcc-c++ + - make + - openssl-devel + - libxml2-devel + - libxslt-devel diff --git a/vars/main.yml b/vars/main.yml index 53757b7..78b77ee 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -1,12 +1,6 @@ --- # ©Copyright 2015 Hewlett-Packard Development Company, L.P. -dependencies: - - python-dev - - python-yaml - - build-essential - - libxml2-dev - - libxslt1-dev monasca_conf_dir: /etc/monasca monasca_agent_check_plugin_dir: /usr/lib/monasca/agent/custom_checks.d/ monasca_agent_detection_plugin_dir: /usr/lib/monasca/agent/custom_detect.d/