ansible-roles/smartgears/smartgears/tasks/smartgears-app.yml

194 lines
9.8 KiB
YAML

---
- name: Create a directory where to store all the smartgears related downloads to avoid cluttering the home directory
file: dest={{ smartgears_downloads_dir }} state=directory owner={{ smartgears_user }} group={{ smartgears_user }}
tags: [ 'smartgears', 'smartgears_distribution', 'tomcat', 'smartgears_download_dir', 'smartgears_downloads_dir', 'smartgears_conf' ]
- name: Remove the old smartgears-distribution files under the smartgears user home directory.
shell: rm -fr {{ smartgears_user_home }}/smartgears-distribution-* ; touch {{ smartgears_user_home }}/.smartgears_distribution_cleaned
args:
creates: '{{ smartgears_user_home }}/.smartgears_distribution_cleaned'
tags: [ 'smartgears', 'smartgears_distribution', 'tomcat' ]
- name: Get the smartgears distribution
become: True
become_user: '{{ smartgears_user }}'
maven_artifact: artifact_id={{ smartgears_name }} version={{ smartgears_distribution_version | default('latest') }} group_id={{ smartgears_group_id }} extension={{ smartgears_extension | default('tar.gz') }} repository_url={{ smartgears_url }} dest={{ smartgears_downloads_dir }}/{{ smartgears_file }}
with_items: '{{ tomcat_m_instances }}'
register: smartgears_download
when: not item.skip_smartgears
tags: [ 'smartgears', 'smartgears_distribution', 'tomcat']
- name: Remove the smartgears-distribution files
shell: find {{ smartgears_downloads_dir }} -maxdepth 1 -type d -name smartgears-distribution-* -exec rm -fr {} \;
ignore_errors: yes
when: ( smartgears_download | changed )
tags: [ 'smartgears', 'smartgears_distribution', 'tomcat']
- name: Unarchive the smartgears distribution
become: True
become_user: '{{ smartgears_user }}'
unarchive: remote_src=yes src={{ smartgears_downloads_dir }}/{{ smartgears_file }} dest={{ smartgears_downloads_dir }}
with_items: '{{ tomcat_m_instances }}'
when:
- not item.skip_smartgears
- ( smartgears_download | changed )
tags: [ 'smartgears', 'smartgears_distribution', 'tomcat' ]
- name: Check if the smartgears stop script exists
become: True
become_user: '{{ smartgears_user }}'
stat: path={{ smartgears_user_home }}/stopContainer.sh
when: smartgears_upgrade or ( smartgears_download | changed )
register: smartgears_stop_script
tags: [ 'smartgears', 'smartgears_distribution', 'tomcat', 'stop_smartgears_service' ]
- name: Stop the smartgears container before launching the upgrade script
become: True
become_user: '{{ smartgears_user }}'
shell: '{{ smartgears_user_home }}/stopContainer.sh'
when:
- smartgears_upgrade or ( smartgears_download | changed )
- smartgears_stop_script.stat.exists
tags: [ 'smartgears', 'smartgears_distribution', 'tomcat', 'stop_smartgears_service' ]
- name: Install the additional tomcat default file
template: src=tomcat-instance-default.j2 dest=/etc/default/tomcat-instance-{{ item.http_port }}.local
with_items: '{{ tomcat_m_instances }}'
when: not item.skip_smartgears
notify: Restart smartgears
tags: [ 'smartgears', 'smartgears_distribution', 'tomcat', 'smartgears_env' ]
- name: Set the additional tomcat default file as the smartgears user .bashrc
become: True
become_user: '{{ smartgears_user }}'
template: src=tomcat-instance-default.j2 dest={{ item.user_home }}/.bashrc mode=0444
with_items: '{{ tomcat_m_instances }}'
when: not item.skip_smartgears
tags: [ 'smartgears', 'smartgears_distribution', 'tomcat', 'smartgears_env' ]
- name: Install the smartgears app
become: True
become_user: '{{ smartgears_user }}'
shell: cd {{ smartgears_downloads_dir }} ; dest_dir=$( find . -type d -name smartgears-distribution-\* | tail -1 ) ; cd $dest_dir ; . /{{ item.user_home }}/.bashrc ; ./install -s tomcat
with_items: '{{ tomcat_m_instances }}'
when:
- ( smartgears_download | changed )
- not item.skip_smartgears
register: install_smartgears_app
notify: Restart smartgears
tags: [ 'smartgears', 'smartgears_distribution', 'tomcat' ]
- name: Create the directory where we put the smartgears configuration snippets
become: True
become_user: '{{ smartgears_user }}'
file: dest={{ smartgears_user_home }}/.containerxml state=directory
tags: [ 'smartgears', 'smartgears_distribution', 'smartgears_conf', 'tomcat' ]
- name: Install the token generator class
copy: src=TokenGenerator.class dest=/usr/local/lib/TokenGenerator.class owner=root group=root mode=0644
tags: [ 'smartgears', 'smartgears_distribution', 'smartgears_conf', 'tomcat' ]
- name: Install the smartgears logback configuration
become: True
become_user: '{{ smartgears_user }}'
template: src=logback.xml.j2 dest={{ smartgears_instance_path }}/lib/logback.xml
when: smartgears_logback_template
tags: [ 'smartgears', 'smartgears_distribution', 'smartgears_conf', 'tomcat', 'logback_conf' ]
- name: Remove some wrong symbolic links created by the install/upgrade script
file: dest={{ item }} state=absent
with_items:
- '{{ smartgears_install_path }}/lib/lib'
- '{{ smartgears_install_path }}/apps/webapps'
tags: [ 'smartgears', 'smartgears_distribution', 'smartgears_conf', 'tomcat' ]
- name: Install the script that fetches the scope tokens
template: src=get-scopes.j2 dest=/usr/local/bin/get-scopes owner=root group={{ smartgears_user }} mode=0750
with_items: '{{ tomcat_m_instances }}'
tags: [ 'smartgears', 'smartgears_distribution', 'smartgears_conf', 'tomcat' ]
- name: Install the file containing the scopes list
template: src=scopes.list.j2 dest=/usr/local/etc/scopes.list owner=root group={{ smartgears_user }} mode=0444
tags: [ 'smartgears', 'smartgears_distribution', 'smartgears_conf', 'tomcat' ]
- name: Get the real smartgears version from the container.xml file contained inside the distribution
shell: dest_dir=$( find {{ smartgears_downloads_dir }} -type d -name smartgears-distribution-\* | tail -1 ) ; cd $dest_dir ; grep "'SmartGearsDistribution' " container.xml | awk -F "'" '{print $4}'
register: smartgears_real_version
tags: [ 'smartgears', 'smartgears_distribution', 'tomcat', 'smartgears_conf' ]
- name: Print the smartgears version
debug:
msg: "The smartgears version is: {{ smartgears_real_version.stdout }}"
when: smartgears_real_version is defined
tags: [ 'smartgears', 'smartgears_distribution', 'tomcat', 'smartgears_conf' ]
# - name: Create a file with the
# copy: content={{ smartgears_real_version.stdout }} dest={{ smartgears_user_home }}/SMARTGEARS_VERSION owner=root group={{ smartgears_user }} mode=0444 force=yes
# when: smartgears_real_version is defined
# tags: [ 'smartgears', 'smartgears_distribution', 'smartgears_conf', 'tomcat' ]
# - name: Check if we have a smartgears version file
# stat: path={{ smartgears_user_home }}/SMARTGEARS_VERSION
# register: sm_version_file
# tags: [ 'smartgears', 'smartgears_distribution', 'tomcat', 'smartgears_conf' ]
# - name: Use the version file if we are not installing a new version
# command: cat {{ smartgears_user_home }}/SMARTGEARS_VERSION
# when:
# - sm_version_file.stat.exists
# - smartgears_download is not defined or not ( smartgears_download | changed )
# register: smartgears_real_version
# tags: [ 'smartgears', 'smartgears_distribution', 'tomcat', 'smartgears_conf' ]
- name: Set the real smartgears distribution version
set_fact: smartgears_real_distribution_version="{{ smartgears_real_version.stdout }}"
tags: [ 'smartgears', 'smartgears_distribution', 'tomcat', 'smartgears_conf' ]
- name: Put the smartgears version into a file
copy: content={{ smartgears_real_distribution_version }} dest={{ smartgears_user_home }}/SMARTGEARS_VERSION
tags: [ 'smartgears', 'smartgears_distribution', 'tomcat', 'smartgears_conf' ]
- name: Install the smartgears template configuration. First part
become: True
become_user: '{{ smartgears_user }}'
template: src=container.xml.j2 dest={{ smartgears_user_home }}/.containerxml/1-container.xml
with_items: '{{ tomcat_m_instances }}'
tags: [ 'smartgears', 'smartgears_distribution', 'smartgears_conf', 'tomcat' ]
- name: Install the smartgears template configuration file. Third part
become: True
become_user: '{{ smartgears_user }}'
template: src=container-end.xml.j2 dest={{ smartgears_user_home }}/.containerxml/3-container.xml
with_items: '{{ tomcat_m_instances }}'
tags: [ 'smartgears', 'smartgears_distribution', 'smartgears_conf', 'tomcat' ]
- name: Get the scope tokens from the authorization service and assemble the container.xml file when whe have an authorization token or we are upgrading
become: True
become_user: '{{ smartgears_user }}'
shell: /usr/local/bin/get-scopes {{ gcube_admin_token | default('') }}
when: gcube_admin_token is defined or ( smartgears_download | changed )
# register: smartgears_remove_state
notify: Restart smartgears
tags: [ 'smartgears', 'smartgears_distribution', 'smartgears_conf', 'tomcat' ]
# Don't needed anymore. The get-scopes script takes care of everything
# - name: Remove the smartgears application state if requested
# become: True
# become_user: '{{ smartgears_user }}'
# shell: . {{ smartgears_user_home }}/.bashrc ; cd {{ smartgears_user_home }}/SmartGears/scripts ; ./clean-container-state -s old_saved_scopes.xml
# when: ( smartgears_remove_state | changed )
# notify: Restart smartgears
# tags: [ 'smartgears', 'smartgears_distribution', 'smartgears_conf', 'tomcat' ]
- name: Force a smartgears restart
service: name='tomcat-instance-{{ smartgears_http_port }}' state=restarted
when: smartgears_force_restart is defined and smartgears_force_restart
tags: [ 'smartgears', 'smartgears_distribution', 'smartgears_conf', 'tomcat' ]
- name: Install the Nagios NRPE configuration for smartgears
template: src=smartgears-nrpe.cfg.j2 dest=/etc/nagios/nrpe.d/smartgears-nrpe.cfg owner=root group=root mode=444
notify: Reload NRPE server
when: nagios_enabled
tags: [ 'smartgears', 'smartgears_distribution', 'smartgears_nrpe', 'nagios', 'nagios_nrpe' ]