Jim Rigsbee
2020-02-13 05caf90207a6752f7b9b3bbd89c6f1f1c8c329ec
Add status reporting API to bastion

Add API that can store in JSON format data to
report the provisioning status. The API can also be
polled to determine the status.

Resolves issue #1025
5 files added
102 ■■■■■ changed files
ansible/roles/status-report-install/defaults/main.yml 2 ●●●●● patch | view | raw | blame | history
ansible/roles/status-report-install/tasks/main.yml 83 ●●●●● patch | view | raw | blame | history
ansible/roles/status-report-install/vars/RedHat.yml 2 ●●●●● patch | view | raw | blame | history
ansible/roles/status-report/defaults/main.yml 2 ●●●●● patch | view | raw | blame | history
ansible/roles/status-report/tasks/main.yml 13 ●●●●● patch | view | raw | blame | history
ansible/roles/status-report-install/defaults/main.yml
New file
@@ -0,0 +1,2 @@
---
bastion_dns_name: "bastion.{{ guid }}{{ subdomain_base_suffix }}"
ansible/roles/status-report-install/tasks/main.yml
New file
@@ -0,0 +1,83 @@
---
- name: Create application folder
  file:
    name: "/opt/status/src"
    state: directory
    owner: "{{ ansible_user }}"
- name: Retrieve application source files
  git:
    clone: yes
    force: yes
    dest: "/tmp/status"
    repo: "http://github.com/RedHatTraining/provisioner-api.git"
- name: Copy application files
  copy:
    dest: "/opt/status/src/{{ item }}"
    src: "/tmp/status/{{ item }}"
    owner: "{{ ansible_user }}"
    mode: 0644
    remote_src: true
  with_items:
    - requirements.txt
    - server.py
    - wsgi.py
- name: Install pip
  package:
    name: python36-pip
- name: Upgrade pip
  pip:
    name: pip
    state: latest
    executable: /usr/bin/pip3
- name: Install python virtualenv
  pip:
    name: virtualenv
    state: latest
    executable: /usr/bin/pip3
- name: Allow nginx to access non-standard port
  shell: |
    semanage port -a -t http_port_t -p tcp 30904
    semanage port -m -t http_port_t -p tcp 30904
- name: Stouts.wsgi virtual environment fix
  file:
    src: /usr/local/bin/virtualenv
    dest: /usr/bin/virtualenv
    owner: root
    group: root
    state: link
- name: Install python application as a service
  include_role:
    name: Stouts.wsgi
  vars:
    python_enabled: false
    wsgi_group: nginx
    wsgi_nginx_servernames: "{{ bastion_dns_name }}"
    wsgi_nginx_port: 30904
    wsgi_virtualenv_python: python3
    wsgi_applications:
    - name: status
      server: gunicorn
      module: wsgi
      pip_requirements: requirements.txt
- name: Create runtime folders
  file:
    name: "{{item}}"
    state: directory
    owner: "{{ansible_user}}"
    group: nginx
  with_items:
    - /opt/status/run
    - /opt/status/log
- name: Fix selinux context for nginx access
  shell: |
    semanage fcontext -a -t httpd_sys_rw_content_t "{{item}}(/.*)?"
    restorecon -R -v "{{item}}"
  with_items:
    - /opt/status/run
    - /opt/status/log
- name: Activate application service
  service:
    name: status-wsgi
    state: restarted
    enabled: yes
ansible/roles/status-report-install/vars/RedHat.yml
New file
@@ -0,0 +1,2 @@
---
wsgi_service: systemd
ansible/roles/status-report/defaults/main.yml
New file
@@ -0,0 +1,2 @@
---
report_status: false
ansible/roles/status-report/tasks/main.yml
New file
@@ -0,0 +1,13 @@
---
- name:
  set_fact:
    bastion_dns_name: "bastion.{{ guid }}{{ subdomain_base_suffix }}"
  when: bastion_dns_name is not defined
- name: Report provisioning status
  uri:
    url: "http://{{ bastion_dns_name }}:30904/api/provision/v1/report"
    method: POST
    body: "{{ status_json }}"
    status_code: 200
    body_format: json