diff --git a/README.md b/README.md deleted file mode 100644 index 21b0490..0000000 --- a/README.md +++ /dev/null @@ -1,41 +0,0 @@ -Ansible Role: ara -========= -Ansible role to install, configure ara on RHEL, Fedora, Centos, Debian and Ubuntu - -systemd is configured to start ara on boot, failures - -By default embedded server is used to host ara on localhost, if you prefer mod_wsgi then you can set the mod_wsgi variable in defaults/main.yml - -Example Playbook ----------------- - - - hosts: servers - roles: - - role: chaitanyaenr.ara - -License -------- - -Apache-2.0 - -Author Information ------------------- - -Naga Ravi Chaitanya Elluri - nelluri@redhat.com - -Copyright ------------------- - -Copyright 2016 Red Hat, Inc. - -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. diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..fcbbc7b --- /dev/null +++ b/README.rst @@ -0,0 +1,67 @@ +ansible-role-ara +================ + +Ansible role to install and configure ARA on Fedora, RHEL, Fedora as well as +Debian and Ubuntu. + +ARA_ (Ansible Run Analysis) records Ansible_ Playbook runs seamlessly to make +them easier to visualize, understand and troubleshoot. It integrates with +Ansible wherever you run it. + +.. _ARA: https://github.com/openstack/ara +.. _Ansible: https://www.ansible.com/ + +Note +---- + +Please note that this role is still a work in progress and in development. + +What the role does +------------------ + +By default, the role allows for the installation of ARA and the `configuration +of Ansible`_ to leverage the ARA callback. +It also allows for the configuration of the `different parameters`_ to customize +the behavior of ARA. + +It provides installation and configuration of the web application under the +`embedded webserver or apache+mod_wsgi`_. + +.. _configuration of Ansible: http://ara.readthedocs.io/en/latest/configuration.html#ansible +.. _different parameters: http://ara.readthedocs.io/en/latest/configuration.html#ara +.. _embedded webserver or apache+mod_wsgi: http://ara.readthedocs.io/en/latest/webserver.html + +Using the role +-------------- +:: + + mkdir roles + git clone https://git.openstack.org/openstack/ansible-role-ara roles/ara + cat << EOF > playbook.yml + - hosts: all + roles: + - ara + EOF + ansible-playbook playbook.yml + +Contributors +============ +See contributors on GitHub_. + +.. _GitHub: https://github.com/openstack/ansible-role-ara/graphs/contributors + +Copyright +========= +Copyright 2017 Red Hat, Inc. + +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. diff --git a/defaults/main.yml b/defaults/main.yml index b2049aa..5090166 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,10 +1,33 @@ --- +# Copyright 2017 Red Hat, Inc. All Rights Reserved. +# +# 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. -ara_host: localhost -ara_port: 9191 -default_embedded_config_path: ~/ansible.cfg -default_wsgi_config_path: /var/www/ara/ansible.cfg -# set config_path -#config_path: +# Default paths where an ansible.cfg file is expected +default_embedded_config_path: "{{ lookup('env','HOME') }}" +default_wsgi_config_path: "/var/www/ara" + +# Override the path where an ansible.cfg file will be used +# config_path: + +# Host to listen on for embedded server or apache +ara_host: "localhost" + +# Port to listen on for embedded server or apache +ara_port: "9191" + +# Deploy with apache and mod_wsgi mod_wsgi: false + +# Deploy with persistent embedded_webserver embedded_server: true diff --git a/handlers/main.yml b/handlers/main.yml index a66dfb4..685f2b5 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -1,2 +1,23 @@ --- -# handlers file for ara +# Copyright 2017 Red Hat, Inc. All Rights Reserved. +# +# 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. + +- name: Restart apache + service: + name: "{{ apache_service }}" + state: "restarted" + enabled: yes + +- name: Reload systemctl + command: systemctl daemon-reload diff --git a/meta/main.yml b/meta/main.yml index ee0bee8..4cd30f4 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -1,20 +1,37 @@ --- +# Copyright 2017 Red Hat, Inc. All Rights Reserved. +# +# 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. + galaxy_info: author: Naga Ravi Chaitanya Elluri - description: Installs ara - company: redhat + description: Installs and configure ARA + company: Red Hat license: Apache2 min_ansible_version: 2.1 platforms: - - name: EL - versions: - - all - - name: Fedora - versions: - - all - - name: Ubuntu - versions: - - all + - name: EL + versions: + - all + - name: Fedora + versions: + - all + - name: Ubuntu + versions: + - all + - name: Debian + versions: + - all galaxy_tags: - installer - application diff --git a/tasks/main.yml b/tasks/main.yml index 4d4d703..ecce018 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,112 +1,177 @@ --- -- name: include OS family/distribution specific variables +# Copyright 2017 Red Hat, Inc. All Rights Reserved. +# +# 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. + +- name: Include OS family/distribution specific variables include_vars: "{{ item }}" with_first_found: - "{{ ansible_distribution }}.yml" - "{{ ansible_os_family }}.yml" -- name: install required dependencies +- name: Install required dependencies package: name: "{{ item }}" state: "present" with_items: "{{ required_packages }}" -- name: install pip +- name: Install pip easy_install: name: pip state: present - when: ansible_pkg_mgr == 'yum' -- name: install ara +- name: Install ARA with pip pip: name: ara + state: present -- name: set ara_config_path when using mod_wsgi - set_fact: - ara_config_path: "{{ config_path | default(default_wsgi_config_path) }}" +- block: + - name: Install required dependencies for mod_wsgi + package: + name: "{{ item }}" + state: "present" + with_items: "{{ required_wsgi_packages }}" + + - name: Get status of selinux + command: getenforce + register: selinux_status + when: ansible_os_family == "RedHat" + + - name: Set selinux boolean to allow Apache to manage the files + seboolean: + name: httpd_unified + state: yes + when: + - ansible_os_family == "RedHat" + - selinux_status.stdout == "Enforcing" + + - name: Set ara_config_path when using mod_wsgi + set_fact: + ara_config_path: "{{ config_path | default(default_wsgi_config_path) }}" + + - name: Ensure configuration directory for Ansible and ARA exists + file: + path: "{{ ara_config_path }}" + owner: "{{ apache_user }}" + group: "{{ apache_group }}" + state: directory + recurse: yes + + - name: Create default configuration file if one does not exist + template: + src: templates/ansible.cfg.j2 + dest: "{{ ara_config_path }}/ansible.cfg" + force: no + + - name: Copy ARA’s WSGI script to the config path + shell: cp -p $(which ara-wsgi) {{ ara_config_path }} + + - name: Set up Apache configuration + template: + src: templates/ara.conf.j2 + dest: "{{ apache_config_path }}/ara.conf" + owner: root + group: root + mode: 0644 + notify: + - Restart Apache + + - name: Ensure the configuration is enabled + command: a2ensite ara + when: ansible_os_family == "Debian" + notify: + - Restart Apache + + - name: Flush handlers + meta: flush_handlers + + - name: Ensure apache is enabled + service: + name: "{{ apache_service }}" + enabled: yes when: mod_wsgi | bool -- name: set ara_config_path when using embedded_server - set_fact: - ara_config_path: "{{ config_path | default(default_embedded_config_path) }}" +- block: + - name: Set ara_config_path when using embedded_server + set_fact: + ara_config_path: "{{ config_path | default(default_embedded_config_path) }}" + + - name: Ensure configuration directory for ARA exists + file: + path: "{{ ara_config_path }}" + state: directory + recurse: yes + + - name: Create default configuration file if one does not exist + template: + src: templates/ansible.cfg.j2 + dest: "{{ ara_config_path }}/ansible.cfg" + force: no + + - name: Get the location of ara-manage + command: which ara-manage + register: ara_manage + changed_when: false + + - name: Copy systemd service template + template: + src: templates/ara-service.conf.j2 + dest: /etc/systemd/system/ara.service + owner: root + group: root + mode: 0644 + notify: + - Reload systemctl + + - name: Flush handlers + meta: flush_handlers + + - name: Start and enable the embedded server service + service: + name: ara + state: started + enabled: yes when: embedded_server | bool -- name: check if ara_config_path exists - stat: path="{{ ara_config_path }}" - register: file_status - -- name: create config file if it doesn't exist - copy: - src: files/ansible.cfg - dest: "{{ ara_config_path }}" - -- name: get ara install location +- name: Get ARA's installed location shell: python -c "import os,ara; print(os.path.dirname(ara.__file__))" register: ara_location + changed_when: false -- name: enable ara callback plugin +- name: Enable ARA's callback plugin ini_file: - dest: "{{ ara_config_path }}" + dest: "{{ ara_config_path }}/ansible.cfg" section: defaults option: callback_plugins value: "{{ ara_location.stdout }}/plugins/callbacks" -- block: - - name: create directory for ansible and ara - file: - path: /var/www/ara - owner: apache - group: apache - state: directory - recurse: yes +- name: Provide web application URL + vars: + msg: >- + ARA was installed succesfully ! + The web application should now be reachable at http://{{ ara_host }}:{{ ara_port }} ! + To customize the host and port on which the application listens to, override the defaults for the ara_host and ara_port variables. + Data from recorded playbooks will be available in the interface as soon as you run your first ansible-playbook command. + debug: + msg: "{{ msg.split('\n') }}" - - name: copy ARA’s WSGI script to the web directory - shell: cp -p $(which ara-wsgi) /var/www/ara/ +- name: Provide instructions + vars: + msg: >- + We've set up an ansible.cfg file for you inside {{ ara_config_path }}. + Make sure to have Ansible and ARA use it for everything to work properly. - - name: get status of selinux - shell: getenforce - register: selinux_status - - - name: set selinux boolean to allow apache to manage the files - seboolean: - name: httpd_unified - state: yes - when: selinux_status.stdout == "Enforcing" and ansible_os_family == "RedHat" - - - name: apache configuration - template: - src: templates/ara.conf.j2 - dest: "{{ apache_config_path }}/ara.conf" - owner: root - group: root - mode: 0644 - - - name: ensure the configuration is enabled - shell: a2ensite ara - when: ansible_os_family == "Ubuntu" - - - name: Restart apache - service: - name: "{{ apache_service }}" - state: "restarted" - enabled: yes - when: mod_wsgi | bool - -- block: - - name: copy systemd service template - template: - src: templates/ara-service.conf.j2 - dest: /etc/systemd/system/ara.service - owner: root - group: root - mode: 0644 - - - name: daemon reload - shell: systemctl daemon-reload - - - name: start and enable service - service: - name: ara - state: started - enabled: yes - when: embedded_server | bool + This can be done from using Ansible or the ARA CLI commands directly from that directory or by using the ANSIBLE_CONFIG environment variable, like so: + export ANSIBLE_CONFIG={{ ara_config_path }}/ansible.cfg + debug: + msg: "{{ msg.split('\n') }}" diff --git a/files/ansible.cfg b/templates/ansible.cfg.j2 similarity index 68% rename from files/ansible.cfg rename to templates/ansible.cfg.j2 index 30331d9..c348c52 100644 --- a/files/ansible.cfg +++ b/templates/ansible.cfg.j2 @@ -1,7 +1,7 @@ [defaults] # This directory is required to store temporary files for Ansible and ARA -local_tmp = /var/www/ara/.ansible/tmp +local_tmp = {{ ara_config_path }}/.ansible/tmp [ara] # This will default the database and logs location to be inside that directory. -dir = /var/www/ara/.ara +dir = {{ ara_config_path }}/.ara diff --git a/templates/ara-service.conf.j2 b/templates/ara-service.conf.j2 index 2c59eb0..af533d2 100644 --- a/templates/ara-service.conf.j2 +++ b/templates/ara-service.conf.j2 @@ -1,5 +1,5 @@ -[unit] -Description=ara +[Unit] +Description=ARA After=network.target [Service] @@ -8,7 +8,7 @@ TimeoutStartSec=0 Restart=on-failure RestartSec=10 RemainAfterExit=yes -ExecStart=/usr/bin/ara-manage runserver -h {{ ara_host }} -p {{ ara_port }} +ExecStart={{ ara_manage.stdout }} runserver -h {{ ara_host }} -p {{ ara_port }} [Install] WantedBy=multi-user.target diff --git a/templates/ara.conf.j2 b/templates/ara.conf.j2 index 61f22c8..f339183 100644 --- a/templates/ara.conf.j2 +++ b/templates/ara.conf.j2 @@ -1,4 +1,4 @@ - + ServerName {{ ara_host }} ErrorLog {{ apache_log_path }}/ara-error.log diff --git a/vars/Debian.yml b/vars/Debian.yml index 148ba49..cc74655 100644 --- a/vars/Debian.yml +++ b/vars/Debian.yml @@ -1,16 +1,31 @@ --- +# Copyright 2017 Red Hat, Inc. All Rights Reserved. +# +# 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. + required_packages: - gcc - python-dev - libffi-dev - libssl-dev - python-setuptools - - libxml2-devel - - libxslt-devel - - libselinux-python + - libxml2-dev + - libxslt-dev + required_wsgi_packages: - apache2 - libapache2-mod-wsgi + apache_service: apache2 apache_user: www-data apache_group: www-data diff --git a/vars/RedHat.yml b/vars/RedHat.yml index 17db240..87d37f5 100644 --- a/vars/RedHat.yml +++ b/vars/RedHat.yml @@ -1,4 +1,18 @@ --- +# Copyright 2017 Red Hat, Inc. All Rights Reserved. +# +# 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. + required_packages: - gcc - python-devel @@ -9,9 +23,11 @@ required_packages: - libxml2-devel - libxslt-devel - libselinux-python + required_wsgi_packages: - httpd - mod_wsgi + apache_service: httpd apache_user: apache apache_group: apache diff --git a/vars/main.yml b/vars/main.yml deleted file mode 100644 index 986916a..0000000 --- a/vars/main.yml +++ /dev/null @@ -1,2 +0,0 @@ ---- -# vars file for ara