Skip to content
Snippets Groups Projects
2-scan.yml 2.94 KiB
Newer Older
  • Learn to ignore specific revisions
  • Marica Antonacci's avatar
    Marica Antonacci committed
    ---
    
    Gioacchino Vino's avatar
    Gioacchino Vino committed
    - name: Set SSH tunel
    
      command: ssh -o StrictHostKeyChecking=no -f -N -L localhost:9390:scans.cloud.infn.it:9390 jenkins@scans.cloud.infn.it 
    
    
    - debug: 
    
    Marica Antonacci's avatar
    Marica Antonacci committed
        var: paas_ci_test.endpoints_to_scan
    
    - name: Copy scan script
    
        src: files/scan.py
    
    Gioacchino Vino's avatar
    Gioacchino Vino committed
        dest: "{{ paas_ci_workdir + '/scan.py' }}"
    
    - name: Copy utilities module
      copy: 
        src: files/utilities.py
    
    Gioacchino Vino's avatar
    Gioacchino Vino committed
        dest: "{{ paas_ci_workdir + '/scan_utilities.py' }}"
    
    
    - name: Copy gvm_library module
      copy: 
        src: files/gvm_library.py
    
    Gioacchino Vino's avatar
    Gioacchino Vino committed
        dest: "{{ paas_ci_workdir + '/scan_gvm_library.py' }}"
    
    
    - name: Adding execution permission to scan script
      file: 
    
    Gioacchino Vino's avatar
    Gioacchino Vino committed
        dest: "{{ paas_ci_workdir + '/scan.py' }}"
    
    Gioacchino Vino's avatar
    Gioacchino Vino committed
    - name: Show dep json file
      debug:
    
    Gioacchino Vino's avatar
    Gioacchino Vino committed
        msg: "{{ lookup('file', item.path) }}"
      with_items: "{{ paas_ci_workdir + '/dep.json' }}"
    
    - name: Load depdep log
      command: cat "{{ paas_ci_workdir + '/dep.json' }}"
      register: dep_json
    
    - name: import depdep_log
      set_fact:
        imported_depdep_log: "{{ dep_json.stdout }}"
    
    - name: Show depdep log
      debug:
        var: imported_depdep_log
    
    Gioacchino Vino's avatar
    Gioacchino Vino committed
    - name: Show BEFORE paas_ci_test.endpoints_to_scan log
      debug:
        var: paas_ci_test.endpoints_to_scan
    
    - name: Fail if "bar" is undefined
      set_fact:
        paas_ci_test.endpoints_to_scan: "None"
      when: paas_ci_test.endpoints_to_scan is undefined
    
    - name: Show AFTER paas_ci_test.endpoints_to_scan log
      debug:
        var: paas_ci_test.endpoints_to_scan
    
    
    - name:  Run scan
    
    Gioacchino Vino's avatar
    Gioacchino Vino committed
      command: "{{ paas_ci_workdir + '/scan.py' }} --endpoint-keys {{ paas_ci_test.endpoints_to_scan }} --dep-json {{ paas_ci_workdir + '/dep.json'}} --output-dir {{ paas_ci_workdir }}" 
    
      register: scan_output
    
    
    Gioacchino Vino's avatar
    Gioacchino Vino committed
    - name: Scan logs
      debug:
    
    Gioacchino Vino's avatar
    Gioacchino Vino committed
        msg: "{{ lookup('file', item.path) }}"
    
    Gioacchino Vino's avatar
    Gioacchino Vino committed
      with_items: "{{ paas_ci_workdir + 'scan.log' }}"
    
    
    - name: Show scan output
      debug:
        msg: "{{ scan_output }}"
    
    
    - name: Find report files
      find:
    
    Gioacchino Vino's avatar
    Gioacchino Vino committed
        paths: "{{ paas_ci_workdir }}"
    
        patterns: '*infn.it-report.txt'
    
      register: report_files
    
    
    - name: read summary report file
    
    Gioacchino Vino's avatar
    Gioacchino Vino committed
      shell: cat "{{ paas_ci_workdir + '/summary-report.json' }}"
    
      register: summary_report 
    
    - name: import summary_report
    
      set_fact:
    
        summary_report_json: "{{ summary_report.stdout | from_json }}"
    
    - name: Show reports
    
    Gioacchino Vino's avatar
    Gioacchino Vino committed
        msg: "{{ lookup('file', item.path) }}"
      with_items: "{{ report_files.files }}"
    
      when: summary_report_json.global == 'NOK'
    
    Gioacchino Vino's avatar
    Gioacchino Vino committed
    - name: Load scans log
    
    Gioacchino Vino's avatar
    Gioacchino Vino committed
      command: cat "{{ paas_ci_workdir + '/scan.log' }}"
    
    Gioacchino Vino's avatar
    Gioacchino Vino committed
      register: scans_log
    
    Gioacchino Vino's avatar
    Gioacchino Vino committed
      when: summary_report_json.global == 'NOK'
    
    Gioacchino Vino's avatar
    Gioacchino Vino committed
    
    
    - name: import scans_log
      set_fact:
        imported_scans_log: "{{ scans_log.stdout }}"
    
    
    Gioacchino Vino's avatar
    Gioacchino Vino committed
    - name: Show scans log
      debug:
    
        var: imported_scans_log
    
      when: summary_report_json.global == 'NOK'
    
    - name: Detailed report summary
      debug:
    
        var: summary_report_json
    
    - name: Report Summary
    
      assert:
        that:
    
          - summary_report_json.global == 'OK'
        fail_msg: "SCAN FAILED - deployment: {{ summary_report_json.deployment }}"
        success_msg: "SCAN PASSED - deployment: {{ summary_report_json.deployment }}"