spyml

# SmartViewM365 WAR Deployment for SharePoint Integration
# This deploys the SharePoint UI component (NOT D2-REST, which is already running)

# Grant permissions for tomcat instance directory
- name: Set permissions for tomcat instance directory
  file:
    path: "{{ tomcat_instance_path }}"
    owner: "{{ tomcat_user }}"
    group: "{{ tomcat_group }}"
    mode: "0755"
    recurse: yes
  become: true

# Restore seLinux contexts for Tomcat instance
- name: Restore seLinux contexts for tomcat instance
  command: restorecon -R {{ tomcat_instance_path }}
  become: true
  no_log: true
  changed_when: false

# Clean any existing SmartViewM365 deployment before re-deploying
# This ensures a fresh deployment without old files interfering
- name: Cleanup before deploying SmartViewM365.war
  file:
    path: "{{ tomcat_instance_path }}/webapps/SmartViewM365.war"
    state: absent
  become: true

- name: Clean extracted SmartViewM365 folder
  file:
    path: "{{ tomcat_instance_path }}/webapps/SmartViewM365"
    state: absent
  become: true

# Download SmartViewM365 WAR from Artifactory
- name: Download SmartViewM365 WAR
  get_url:
    url: "{{ smartview_war_url }}"
    dest: "{{ tomcat_instance_path }}/webapps/SmartViewM365.war"
    validate_certs: no
    owner: "{{ tomcat_user }}"
    group: "{{ tomcat_group }}"
    mode: "0755"
  become: true

# Create Tomcat systemd service file for SmartViewM365
- name: Create Tomcat systemd service file
  template:
    src: tomcat.service.j2
    dest: /etc/systemd/system/{{ web_app_name }}.service
    mode: '0644'
  become: true

# Reload systemd
- name: Reload systemd
  systemd:
    daemon_reload: yes
  become: true

# Start Tomcat to extract the WAR file
- name: Start Tomcat service to extract WAR
  systemd:
    name: "{{ web_app_name }}"
    state: started
  become: true

# Wait for WAR to be extracted by Tomcat
- name: Wait for SmartViewM365 WAR to be extracted
  ansible.builtin.wait_for:
    path: "{{ tomcat_instance_path }}/webapps/SmartViewM365/manifests"
    state: present
    delay: 5
    timeout: 60
  become: true

# CRITICAL: Stop Tomcat before configuration (per PDF deployment guide)
- name: Stop Tomcat service for configuration
  systemd:
    name: "{{ web_app_name }}"
    state: stopped
  become: true

# Remove the WAR file to prevent redeployment
- name: Remove SmartViewM365.war file
  file:
    path: "{{ tomcat_instance_path }}/webapps/SmartViewM365.war"
    state: absent
  become: true

# Deploy launcher.json for SharePoint configuration (Linux)
- name: Deploy launcher.json for SharePoint
  template:
    src: launcher.json.j2
    dest: "{{ tomcat_instance_path }}/webapps/SmartViewM365/ui/launcher.json"
    owner: "{{ tomcat_user }}"
    group: "{{ tomcat_group }}"
    mode: "0644"
  become: true
  when: ansible_os_family == "RedHat" or ansible_os_family == "Debian"

# Automated Manifest Generation for SharePoint (Linux equivalent to setup.bat)
# Note: This project is SharePoint-only, Teams integration is not in scope

- name: Create temporary SharePoint manifest folder
  file:
    path: "{{ tomcat_instance_path }}/webapps/SmartViewM365/manifests/updated_sharepoint"
    state: directory
    owner: "{{ tomcat_user }}"
    group: "{{ tomcat_group }}"
    mode: "0755"
  become: true
  when: ansible_os_family == "RedHat" or ansible_os_family == "Debian"

- name: Copy base manifest to SharePoint folder
  copy:
    src: "{{ tomcat_instance_path }}/webapps/SmartViewM365/manifests/manifest/"
    dest: "{{ tomcat_instance_path }}/webapps/SmartViewM365/manifests/updated_sharepoint/"
    remote_src: yes
    owner: "{{ tomcat_user }}"
    group: "{{ tomcat_group }}"
    mode: "0755"
  become: true
  when: ansible_os_family == "RedHat" or ansible_os_family == "Debian"

- name: Update SharePoint manifest.json with configuration
  replace:
    path: "{{ tomcat_instance_path }}/webapps/SmartViewM365/manifests/updated_sharepoint/manifest.json"
    regexp: "{{ item.pattern }}"
    replace: "{{ item.value }}"
  loop:
    - { pattern: '<host>', value: '{{ smartview_host_name }}:{{ smartview_https_port }}' }
    - { pattern: '<app_id>', value: '{{ azure_client_id }}' }
    - { pattern: '<app_name>', value: 'Documentum' }
    - { pattern: '<apptype>', value: 'sharepoint' }
  become: true
  when: ansible_os_family == "RedHat" or ansible_os_family == "Debian"

- name: Create SharePoint download directory
  file:
    path: "{{ tomcat_instance_path }}/webapps/SmartViewM365/manifests/download/sharepoint"
    state: directory
    owner: "{{ tomcat_user }}"
    group: "{{ tomcat_group }}"
    mode: "0755"
  become: true
  when: ansible_os_family == "RedHat" or ansible_os_family == "Debian"

- name: Create SharePoint manifest ZIP
  community.general.archive:
    path: "{{ tomcat_instance_path }}/webapps/SmartViewM365/manifests/updated_sharepoint/*"
    dest: "{{ tomcat_instance_path }}/webapps/SmartViewM365/manifests/download/sharepoint/smartviewm365manifest.zip"
    format: zip
    owner: "{{ tomcat_user }}"
    group: "{{ tomcat_group }}"
  become: true
  when: ansible_os_family == "RedHat" or ansible_os_family == "Debian"

- name: Cleanup temporary SharePoint manifest folder
  file:
    path: "{{ tomcat_instance_path }}/webapps/SmartViewM365/manifests/updated_sharepoint"
    state: absent
  become: true
  when: ansible_os_family == "RedHat" or ansible_os_family == "Debian"

- name: "[Success] SharePoint manifest generated"
  debug:
    msg:
      - "✅ SharePoint manifest generation completed!"
      - "Manifest location: {{ tomcat_instance_path }}/webapps/SmartViewM365/manifests/download/sharepoint/smartviewm365manifest.zip"
      - "Upload this ZIP file to SharePoint admin center"
  when: ansible_os_family == "RedHat" or ansible_os_family == "Debian"

# Set webapps folder permissions
- name: Set permissions on webapps folder
  ansible.builtin.file:
    path: "{{ tomcat_instance_path }}/webapps"
    owner: "{{ tomcat_user }}"
    group: "{{ tomcat_group }}"
    mode: "0755"
    recurse: yes
  become: true

# Verify and Update log4j properties for SmartViewM365
- name: "[Log] Configuring Log4j for SmartViewM365"
  debug:
    msg: "Updating log4j configuration for SmartViewM365"

- name: Check if log4j2.properties exists
  stat:
    path: "{{ tomcat_instance_path }}/webapps/SmartViewM365/WEB-INF/classes/log4j2.properties"
  register: log4j_file

- name: Update log4j.properties file path
  ansible.builtin.replace:
    path: "{{ tomcat_instance_path }}/webapps/SmartViewM365/WEB-INF/classes/log4j2.properties"
    regexp: "^appender.R.fileName=.*"
    replace: "appender.R.fileName={{ tomcat_instance_path }}/logs/smartview-m365.log"
  become: true
  when: log4j_file.stat.exists

- name: Update log4j.properties file pattern
  ansible.builtin.replace:
    path: "{{ tomcat_instance_path }}/webapps/SmartViewM365/WEB-INF/classes/log4j2.properties"
    regexp: "^appender.R.filePattern=.*"
    replace: "appender.R.filePattern={{ tomcat_instance_path }}/logs/smartview-m365.log.%i"
  become: true
  when: log4j_file.stat.exists

- name: "[Warn] Log4j properties not found"
  debug:
    msg: "Warning: log4j2.properties not found in {{ tomcat_instance_path }}/webapps/SmartViewM365/WEB-INF/classes/"
  when: not log4j_file.stat.exists

# Start Tomcat service with configured SmartViewM365
- name: Start Tomcat service
  systemd:
    name: "{{ web_app_name }}"
    state: started
  become: true

# Wait for SmartViewM365 to be accessible
- name: "[Check] Wait for SmartViewM365 HTTP Port"
  wait_for:
    port: "{{ smartview_http_port }}"
    host: "127.0.0.1"
    state: started
    delay: 10
    timeout: 300
  become: true

- name: "[Check] Wait for SmartViewM365 HTTPS Port"
  wait_for:
    port: "{{ smartview_https_port }}"
    host: "127.0.0.1"
    state: started
    delay: 5
    timeout: 30
  become: true
  ignore_errors: true # HTTPS might not come up if certs are missing/invalid in dev

# Verify SmartViewM365 UI is accessible
- name: "[Check] Verify SmartViewM365 UI endpoint"
  uri:
    url: "https://127.0.0.1:{{ smartview_https_port }}/SmartViewM365/ui/"
    validate_certs: no
    status_code: [200, 302, 401]
    timeout: 30
  register: smartview_check
  retries: 3
  delay: 10
  until: smartview_check is succeeded
  ignore_errors: true

- name: "[Log] SmartViewM365 deployment status"
  debug:
    msg: "SmartViewM365 UI deployed successfully. Access at https://{{ ansible_fqdn }}:{{ smartview_https_port }}/SmartViewM365/ui/"
  when: smartview_check is succeeded

- name: "[Error] SmartViewM365 UI not accessible"
  debug:
    msg: "ERROR: SmartViewM365 UI is not responding. Check Tomcat logs at {{ tomcat_instance_path }}/logs/"
  when: smartview_check is failed

Comments

Popular posts from this blog

Arch Flow

m365