<commit_before>---

- name: install package dependencies
  become: true
  block:
    - name: install postgresql
      dnf:
        name:
          - postgresql12-server
          - httpd
          - python3-mod_wsgi


- name: httpd configuration
  become: true
  block:
    - name: httpd conf file
      copy:
        src: 001-kive.conf
        dest: /etc/httpd/conf.d/
    - name: kive web conf file
      template:
        src: kive_apache.conf.j2
        dest: /etc/kive/kive_apache.conf
        owner: kive
        group: kive
        mode: "640"
    - name: server environment variables via systemd
      blockinfile:
        path: /etc/systemd/system/httpd.service.d/override.conf
        create: true
        backup: true
        mode: "644"
        block: |
          [Service]
          EnvironmentFile=/etc/kive/kive_apache.conf
          Environment=APACHE_RUN_USER=kive
          Environment=APACHE_RUN_GROUP=kive
    - name: update httpd.conf
      loop:
        - from: "Listen 80$"
          to: "Listen {{ kive_listen_port }}"
        - from: "User apache$"
          to: "User {{ kive_httpd_user }}"
        - from: "Group apache$"
          to: "Group {{kive_httpd_group }}"
      replace:
        path: /etc/httpd/conf/httpd.conf
        regexp: "{{ item.from }}"
        replace: "{{ item.to }}"
    - name: apache log purge settings
      loop:
        - from: 'ErrorLog "logs/error_log"'
          to: ErrorLog "|/usr/sbin/rotatelogs -l -p /usr/sbin/purge_apache_logs /var/log/httpd/error_log.%Y-%m-%d-%H%M%S 15M
        - from: 'CustomLog "logs/access_log" combined'
          to: CustomLog "|/usr/sbin/rotatelogs -l -p /usr/sbin/purge_apache_logs /var/log/httpd/access_log.%Y-%m-%d-%H%M%S 15M" combined
      replace:
        path: /etc/httpd/conf/httpd.conf
        regexp: "{{ item.from }}"
        replace: "{{ item.to }}"
    - name: enable httpd
      systemd:
        name: httpd
        state: started
        enabled: true
    - name: ensure firewalld is running
      systemd:
        name: firewalld
        state: started
        enabled: true
    - name: firewall's internal interface
      firewalld:
        zone: internal
        interface: "{{ kive_internal_interface }}"
        permanent: yes
        immediate: yes
    - name: firewall's external interface
      firewalld:
        zone: external
        interface: "{{ kive_external_interface }}"
        permanent: yes
        immediate: yes
    - name: permit https service through firewall
      firewalld:
        zone: external
        service: https
        permanent: yes
        immediate: yes
        state: enabled
    - name: permit http service through firewall
      firewalld:
        zone: external
        service: http
        permanent: yes
        immediate: yes
        state: enabled


- name: configure postgres server
  become: true
  become_user: postgres
  block:
    - name: ensure database is initialized
      become: true
      become_user: root
      command:
        cmd: "/usr/pgsql-12/bin/postgresql-12-setup initdb"
        creates: "/var/lib/pgsql/12/data/PG_VERSION"
    - name: start database service
      become: true
      become_user: root
      systemd:
        name: "postgresql-12"
        state: started
        enabled: true
    - name: local database settings
      loop:
        - name: listen_addresses
          value: "*"
        - name: password_encryption
          value: scram-sha-256
      postgresql_set:
        name: "{{ item.name }}"
        value: "{{ item.value }}"
    - name: add kive entries to pg_hba.conf
      block:
        - postgresql_pg_hba:
            contype: local
            dest: "/var/lib/pgsql/12/data/pg_hba.conf"
            databases: all
            users: kive
            method: "scram-sha-256"
        - postgresql_pg_hba:
            contype: host
            dest: "/var/lib/pgsql/12/data/pg_hba.conf"
            databases: all
            users: kive
            source: "{{kive_db_host}}/24"
            method: "scram-sha-256"
    - name: restart database service
      become: true
      become_user: root
      systemd:
        name: "postgresql-12"
        state: restarted


- name: kive installation
  block:
    - name: build kive API
      become: true
      command:
        cmd: "{{ kive_venv }}/bin/python setup.py install"
        chdir: "{{ kive_root }}/api/"
        creates: "{{ kive_root }}/api/build/"
    - name: collect kive's static files
      become: true
      environment:
        KIVE_STATIC_ROOT: "{{ kive_static_root }}"
      command:
        cmd: "{{ kive_venv }}/bin/python manage.py collectstatic --no-input"
        chdir: "{{ kive_root }}/kive"
    - name: restart http server
      become: true
      systemd:
        name: httpd
        state: restarted


- name: set up log purging
  become: true
  block:
    - name: apache log purge script
      copy:
        src: purge_apache_logs
        dest: /usr/sbin
        mode: "755"
    - name: purge service files
      loop:
        - kive_purge.service
        - kive_purge.timer
        - kive_purge_synch.service
        - kive_purge_synch.timer
      copy:
        src: "{{ item }}"
        dest: /etc/systemd/system
    - name: purge config file
      template:
        src: kive_purge.conf.j2
        dest: /etc/kive/kive_purge.conf
        owner: kive
        group: kive
        mode: "640"
    - name: enable kive_purge units
      loop:
        - kive_purge.service
        - kive_purge.timer
        - kive_purge_synch.service
        - kive_purge_synch.timer
      systemd:
        name: "{{ item }}"
        enabled: true
    - name: start kive_purge timers
      loop:
        - kive_purge.timer
        - kive_purge_synch.timer
      systemd:
        name: "{{ item }}"
        state: started



- name: set up kive database
  block:
    - name: create kive database
      become: true
      become_user: postgres
      postgresql_db:
        name: kive
    - name: create kive database user
      become: true
      become_user: postgres
      postgresql_user:
        name: kive
        password: "{{ <PASSWORD> }}"
        db: kive
        priv: ALL
    - name: run django migrations
      environment:
          KIVE_DB_NAME: "{{ kive_db_name }}"
          KIVE_DB_USER: "{{ kive_db_user }}"
          KIVE_DB_HOST: "{{kive_db_host }}"
          KIVE_DB_PASSWORD: "{{ kive_db_password}}"
      become: true
      become_user: kive
      command:
        cmd: "{{ kive_venv }}/bin/python manage.py migrate"
        chdir: "{{ kive_root }}/kive"
<commit_msg>Add missing state fields to firewall interfaces.<commit_after>---

- name: install package dependencies
  become: true
  block:
    - name: install postgresql
      dnf:
        name:
          - postgresql12-server
          - httpd
          - python3-mod_wsgi


- name: httpd configuration
  become: true
  block:
    - name: httpd conf file
      copy:
        src: 001-kive.conf
        dest: /etc/httpd/conf.d/
    - name: kive web conf file
      template:
        src: kive_apache.conf.j2
        dest: /etc/kive/kive_apache.conf
        owner: kive
        group: kive
        mode: "640"
    - name: server environment variables via systemd
      blockinfile:
        path: /etc/systemd/system/httpd.service.d/override.conf
        create: true
        backup: true
        mode: "644"
        block: |
          [Service]
          EnvironmentFile=/etc/kive/kive_apache.conf
          Environment=APACHE_RUN_USER=kive
          Environment=APACHE_RUN_GROUP=kive
    - name: update httpd.conf
      loop:
        - from: "Listen 80$"
          to: "Listen {{ kive_listen_port }}"
        - from: "User apache$"
          to: "User {{ kive_httpd_user }}"
        - from: "Group apache$"
          to: "Group {{kive_httpd_group }}"
      replace:
        path: /etc/httpd/conf/httpd.conf
        regexp: "{{ item.from }}"
        replace: "{{ item.to }}"
    - name: apache log purge settings
      loop:
        - from: 'ErrorLog "logs/error_log"'
          to: ErrorLog "|/usr/sbin/rotatelogs -l -p /usr/sbin/purge_apache_logs /var/log/httpd/error_log.%Y-%m-%d-%H%M%S 15M
        - from: 'CustomLog "logs/access_log" combined'
          to: CustomLog "|/usr/sbin/rotatelogs -l -p /usr/sbin/purge_apache_logs /var/log/httpd/access_log.%Y-%m-%d-%H%M%S 15M" combined
      replace:
        path: /etc/httpd/conf/httpd.conf
        regexp: "{{ item.from }}"
        replace: "{{ item.to }}"
    - name: enable httpd
      systemd:
        name: httpd
        state: started
        enabled: true
    - name: ensure firewalld is running
      systemd:
        name: firewalld
        state: started
        enabled: true
    - name: firewall's internal interface
      firewalld:
        zone: internal
        interface: "{{ kive_internal_interface }}"
        permanent: yes
        immediate: yes
        state: enabled
    - name: firewall's external interface
      firewalld:
        zone: external
        interface: "{{ kive_external_interface }}"
        permanent: yes
        immediate: yes
        state: enabled
    - name: permit https service through firewall
      firewalld:
        zone: external
        service: https
        permanent: yes
        immediate: yes
        state: enabled
    - name: permit http service through firewall
      firewalld:
        zone: external
        service: http
        permanent: yes
        immediate: yes
        state: enabled


- name: configure postgres server
  become: true
  become_user: postgres
  block:
    - name: ensure database is initialized
      become: true
      become_user: root
      command:
        cmd: "/usr/pgsql-12/bin/postgresql-12-setup initdb"
        creates: "/var/lib/pgsql/12/data/PG_VERSION"
    - name: start database service
      become: true
      become_user: root
      systemd:
        name: "postgresql-12"
        state: started
        enabled: true
    - name: local database settings
      loop:
        - name: listen_addresses
          value: "*"
        - name: password_encryption
          value: scram-sha-256
      postgresql_set:
        name: "{{ item.name }}"
        value: "{{ item.value }}"
    - name: add kive entries to pg_hba.conf
      block:
        - postgresql_pg_hba:
            contype: local
            dest: "/var/lib/pgsql/12/data/pg_hba.conf"
            databases: all
            users: kive
            method: "scram-sha-256"
        - postgresql_pg_hba:
            contype: host
            dest: "/var/lib/pgsql/12/data/pg_hba.conf"
            databases: all
            users: kive
            source: "{{kive_db_host}}/24"
            method: "scram-sha-256"
    - name: restart database service
      become: true
      become_user: root
      systemd:
        name: "postgresql-12"
        state: restarted


- name: kive installation
  block:
    - name: build kive API
      become: true
      command:
        cmd: "{{ kive_venv }}/bin/python setup.py install"
        chdir: "{{ kive_root }}/api/"
        creates: "{{ kive_root }}/api/build/"
    - name: collect kive's static files
      become: true
      environment:
        KIVE_STATIC_ROOT: "{{ kive_static_root }}"
      command:
        cmd: "{{ kive_venv }}/bin/python manage.py collectstatic --no-input"
        chdir: "{{ kive_root }}/kive"
    - name: restart http server
      become: true
      systemd:
        name: httpd
        state: restarted


- name: set up log purging
  become: true
  block:
    - name: apache log purge script
      copy:
        src: purge_apache_logs
        dest: /usr/sbin
        mode: "755"
    - name: purge service files
      loop:
        - kive_purge.service
        - kive_purge.timer
        - kive_purge_synch.service
        - kive_purge_synch.timer
      copy:
        src: "{{ item }}"
        dest: /etc/systemd/system
    - name: purge config file
      template:
        src: kive_purge.conf.j2
        dest: /etc/kive/kive_purge.conf
        owner: kive
        group: kive
        mode: "640"
    - name: enable kive_purge units
      loop:
        - kive_purge.service
        - kive_purge.timer
        - kive_purge_synch.service
        - kive_purge_synch.timer
      systemd:
        name: "{{ item }}"
        enabled: true
    - name: start kive_purge timers
      loop:
        - kive_purge.timer
        - kive_purge_synch.timer
      systemd:
        name: "{{ item }}"
        state: started



- name: set up kive database
  block:
    - name: create kive database
      become: true
      become_user: postgres
      postgresql_db:
        name: kive
    - name: create kive database user
      become: true
      become_user: postgres
      postgresql_user:
        name: kive
        password: "{{ <PASSWORD> }}"
        db: kive
        priv: ALL
    - name: run django migrations
      environment:
          KIVE_DB_NAME: "{{ kive_db_name }}"
          KIVE_DB_USER: "{{ kive_db_user }}"
          KIVE_DB_HOST: "{{kive_db_host }}"
          KIVE_DB_PASSWORD: "{{ kive_db_password}}"
      become: true
      become_user: kive
      command:
        cmd: "{{ kive_venv }}/bin/python manage.py migrate"
        chdir: "{{ kive_root }}/kive"

{'fraction_non_alphanumeric': 0.10148007590132828, 'fraction_numerical': 0.007741935483870968, 'mean_word_length': 1.7472894078398666, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3288842', 'n_tokens_mistral': 4303, 'n_tokens_neox': 4264, 'n_words': 1018}