<commit_before>---
- hosts: ds_website_{{ ENV }}
  user: ec2-user
  become_method: sudo

# Requires: BUILD_ID, ENV, and DOMAIN

  tasks:
    - name: remove old frontend backed up files
      become: true
      shell: "rm -rf /var/www-old"
      ignore_errors: yes

    - name: backup old frontend served files
      become: true
      shell: "mv /var/www /var/www-old" 
      ignore_errors: yes

    - name: copy frontend files
      become: true
      shell: "aws s3 cp s3://ds-website-assets/{{ ENV }}/{{ BUILD_ID }}/public/ /var/www --region us-gov-west-1 --recursive"

    - name: checkout config from git
      become: true
      git: repo=<EMAIL>:fedspendingtransparency/data-act-broker-config.git 
           dest=/data-act/config 
           accept_hostkey=true 
           force=yes 
           key_file="/home/ec2-user/.ssh/id_rsa"

    - name: add server name to nginx config
      become: true
      lineinfile:
        dest: /data-act/config/nginx/nginx_ds_website.conf
        regexp: '\s*server_name.*;'
        line: "\tserver_name {{ DOMAIN }};"
    
    - name: remove basic auth from prod
      become: true
      when: ENV == 'prod'
      lineinfile:
        dest: /data-act/config/nginx/nginx_ds_website.conf
        regexp: '\s*auth_basic "Basic Auth Check".*'
        state: absent
    
    - name: remove basic auth from prod
      become: true
      when: ENV == 'prod'
      lineinfile:
        dest: /data-act/config/nginx/nginx_ds_website.conf
        regexp: '\s*auth_basic_user_file /etc/nginx/.*'
        state: absent
    
    - name: remove caching from non-prod environments
      become: true
      when: ENV != 'prod'
      lineinfile:
        dest: /data-act/config/nginx/nginx_ds_website.conf
        regexp: '\s*add_header Cache-Control.*'
        state: absent
    
    - name: copy ENV config
      become: true
      shell: cp /data-act/config/nginx/nginx_ds_website.conf /etc/nginx/nginx.conf

    - name: modify SELinux sebool for httpd_can_network_connect
      become: true
      command: setsebool -P httpd_can_network_connect on

    - name: run restorecon on /var/www/
      become: true
      command: restorecon -R -v /var/www/

    - name: enable nginx service
      become: true
      systemd:
        name: nginx
        enabled: yes

    - name: restart nginx service
      become: true
      systemd:
        name: nginx
        state: restarted
      <commit_msg>systemd module is out-of-sync with our ansible<commit_after>---
- hosts: ds_website_{{ ENV }}
  user: ec2-user
  become_method: sudo

# Requires: BUILD_ID, ENV, and DOMAIN

  tasks:
    - name: remove old frontend backed up files
      become: true
      shell: "rm -rf /var/www-old"
      ignore_errors: yes

    - name: backup old frontend served files
      become: true
      shell: "mv /var/www /var/www-old" 
      ignore_errors: yes

    - name: copy frontend files
      become: true
      shell: "aws s3 cp s3://ds-website-assets/{{ ENV }}/{{ BUILD_ID }}/public/ /var/www --region us-gov-west-1 --recursive"

    - name: checkout config from git
      become: true
      git: repo=<EMAIL>:fedspendingtransparency/data-act-broker-config.git 
           dest=/data-act/config 
           accept_hostkey=true 
           force=yes 
           key_file="/home/ec2-user/.ssh/id_rsa"

    - name: add server name to nginx config
      become: true
      lineinfile:
        dest: /data-act/config/nginx/nginx_ds_website.conf
        regexp: '\s*server_name.*;'
        line: "\tserver_name {{ DOMAIN }};"
    
    - name: remove basic auth from prod
      become: true
      when: ENV == 'prod'
      lineinfile:
        dest: /data-act/config/nginx/nginx_ds_website.conf
        regexp: '\s*auth_basic "Basic Auth Check".*'
        state: absent
    
    - name: remove basic auth from prod
      become: true
      when: ENV == 'prod'
      lineinfile:
        dest: /data-act/config/nginx/nginx_ds_website.conf
        regexp: '\s*auth_basic_user_file /etc/nginx/.*'
        state: absent
    
    - name: remove caching from non-prod environments
      become: true
      when: ENV != 'prod'
      lineinfile:
        dest: /data-act/config/nginx/nginx_ds_website.conf
        regexp: '\s*add_header Cache-Control.*'
        state: absent
    
    - name: copy ENV config
      become: true
      shell: cp /data-act/config/nginx/nginx_ds_website.conf /etc/nginx/nginx.conf

    - name: modify SELinux sebool for httpd_can_network_connect
      become: true
      command: setsebool -P httpd_can_network_connect on

    - name: run restorecon on /var/www/
      become: true
      command: restorecon -R -v /var/www/

    - name: enable nginx service
      become: true
      shell: systemctl enable nginx

    - name: restart nginx service
      become: true
      shell: systemctl restart nginx
{'fraction_non_alphanumeric': 0.10449927431059507, 'fraction_numerical': 0.0020733982998133943, 'mean_word_length': 2.072611464968153, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 12, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2129818', 'n_tokens_mistral': 1626, 'n_tokens_neox': 1583, 'n_words': 418}