From 871f82540606de21597492ece4305af958ebe9b1 Mon Sep 17 00:00:00 2001 From: Nicolas Hicher Date: Fri, 8 Dec 2017 15:36:56 -0500 Subject: [PATCH] Refactoring ara role - split embedded and apache configuation in separate files - use systemd to launch and enable httpd or embedded server - remove unused handler Change-Id: I25c92b2b38125826087957fb8ce9320641cf86f0 --- README.rst | 13 +++- defaults/main.yml | 10 +-- handlers/main.yml | 7 +-- tasks/apache_server.yml | 64 +++++++++++++++++++ tasks/embedded_server.yaml | 37 +++++++++++ tasks/main.yml | 122 ++++--------------------------------- 6 files changed, 132 insertions(+), 121 deletions(-) create mode 100644 tasks/apache_server.yml create mode 100644 tasks/embedded_server.yaml diff --git a/README.rst b/README.rst index fcbbc7b..0d66bad 100644 --- a/README.rst +++ b/README.rst @@ -33,8 +33,19 @@ It provides installation and configuration of the web application under the Using the role -------------- -:: +You can get the role using the following commands: + +:: + mkdir roles + git clone https://git.openstack.org/openstack/ansible-role-ara roles/ara + +By default, the embedded server will be use, you have to edit defaults/main.yaml to set +use_apache_server to True + +Create a simple playbook to do the deployment: + +:: mkdir roles git clone https://git.openstack.org/openstack/ansible-role-ara roles/ara cat << EOF > playbook.yml diff --git a/defaults/main.yml b/defaults/main.yml index 5090166..a012522 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -21,13 +21,13 @@ default_wsgi_config_path: "/var/www/ara" # config_path: # Host to listen on for embedded server or apache -ara_host: "localhost" +ara_host: "{{ ansible_default_ipv4.address }}" # Port to listen on for embedded server or apache ara_port: "9191" -# Deploy with apache and mod_wsgi -mod_wsgi: false +# To deploy with apache server, set use_apache_server to True +# When use_apache_server is False, the deployment will use embedded +# server +use_apache_server: False -# Deploy with persistent embedded_webserver -embedded_server: true diff --git a/handlers/main.yml b/handlers/main.yml index 685f2b5..742464d 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -13,11 +13,8 @@ # License for the specific language governing permissions and limitations # under the License. -- name: Restart apache +- name: restart apache service: name: "{{ apache_service }}" state: "restarted" - enabled: yes - -- name: Reload systemctl - command: systemctl daemon-reload + become: true diff --git a/tasks/apache_server.yml b/tasks/apache_server.yml new file mode 100644 index 0000000..dc28de2 --- /dev/null +++ b/tasks/apache_server.yml @@ -0,0 +1,64 @@ +--- +- 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 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 Apache server is started + systemd: + state: started + name: "{{ apache_service }}" + enabled: true + + - name: Ensure the configuration is enabled + command: a2ensite ara + when: ansible_os_family == "Debian" + notify: + - restart apache + become: true diff --git a/tasks/embedded_server.yaml b/tasks/embedded_server.yaml new file mode 100644 index 0000000..d129d6c --- /dev/null +++ b/tasks/embedded_server.yaml @@ -0,0 +1,37 @@ +- 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: /usr/lib/systemd/system/ara.service + owner: root + group: root + mode: 0644 + + - name: Start and enable the embedded server service + systemd: + name: ara + state: started + enabled: yes + daemon_reload: yes + become: true diff --git a/tasks/main.yml b/tasks/main.yml index 2e6418f..0e0206c 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -24,136 +24,38 @@ name: "{{ item }}" state: "present" with_items: "{{ required_packages }}" + become: true - name: Install pip - easy_install: - name: pip + easy_install: + name: pip state: present + become: true - name: Install ARA with pip pip: name: ara state: present + become: true -- block: - - name: Install required dependencies for mod_wsgi - package: - name: "{{ item }}" - state: "present" - with_items: "{{ required_wsgi_packages }}" +- include_tasks: apache_server.yml + when: use_apache_server - - name: Get status of selinux - command: getenforce - register: selinux_status - when: ansible_os_family == "RedHat" +- include_tasks: embedded_server.yaml + when: not use_apache_server - - 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 - -- 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: Get ARA's installed location +- name: Get ARA installed location shell: python -c "import os,ara; print(os.path.dirname(ara.__file__))" register: ara_location changed_when: false -- name: Enable ARA's callback plugin +- name: Enable ARA callback plugin ini_file: dest: "{{ ara_config_path }}/ansible.cfg" section: defaults option: callback_plugins value: "{{ ara_location.stdout }}/plugins/callbacks" + become: true - name: Provide web application URL vars: