generated from terraform-ibm-modules/terraform-ibm-module-template
    
        
        - 
                Notifications
    You must be signed in to change notification settings 
- Fork 1
Adding ansible script for checking monitoring instance with enabled platform metrics #93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Open
      
      
            mukulpalit-ibm
  wants to merge
  6
  commits into
  main
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
ansible-script
  
      
      
   
  
    
  
  
  
 
  
      
    base: main
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
      
        
          +75
        
        
          −0
        
        
          
        
      
    
  
  
     Open
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            6 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      236ef8e
              
                Add ansible script to check existing instance with platform metrics e…
              
              
                mukulpalit-ibm 2a26981
              
                Add ansible script to check existing instance with platform metrics e…
              
              
                mukulpalit-ibm a20f6c4
              
                PR changes
              
              
                mukulpalit-ibm c719e64
              
                remove JQ
              
              
                mukulpalit-ibm ef22e92
              
                pre-commit
              
              
                mukulpalit-ibm c16ea6c
              
                Merge branch 'main' into ansible-script
              
              
                mukulpalit-ibm File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
        
          
  
    
      
          
            74 changes: 74 additions & 0 deletions
          
          74 
        
  solutions/fully-configurable/scripts/validate-pre-ansible-playbook.yaml
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| --- | ||
| - name: Find IBM Cloud Monitoring Instance with Platform Metrics | ||
| hosts: localhost | ||
| connection: local | ||
| gather_facts: false | ||
|  | ||
| tasks: | ||
| - name: Set conditional variable from environment | ||
| set_fact: | ||
| enable_platform_metrics: "{{ lookup('env', 'enable_platform_metrics') | default('false') | lower }}" | ||
| - name: Ensure enable_platform_metrics is a boolean | ||
| set_fact: | ||
| is_enabled: "{{ enable_platform_metrics | bool }}" | ||
|  | ||
| - name: Find IBM Cloud Monitoring Instance | ||
| block: | ||
| - name: get running ansible env variables | ||
| set_fact: | ||
| ibmcloud_api_key: "{{ lookup('env', 'ibmcloud_api_key') }}" # pragma: allowlist secret | ||
| target_instance_filter: "sysdig-monitor" | ||
|  | ||
| - name: Log in to IBM Cloud | ||
| ansible.builtin.shell: | | ||
| ibmcloud login --apikey "{{ ibmcloud_api_key }}" --no-region -q >/dev/null 2>&1 | ||
| register: ibmcloud_login_result | ||
| changed_when: false | ||
| failed_when: ibmcloud_login_result.rc != 0 or | ||
| 'FAILED' in ibmcloud_login_result.stderr or | ||
| 'Error' in ibmcloud_login_result.stderr | ||
|  | ||
| - name: Display IBM Cloud login success message | ||
| ansible.builtin.debug: | ||
| msg: "Authentication successful." | ||
| when: ibmcloud_login_result.rc == 0 | ||
|  | ||
| - name: List IBM Cloud service instances | ||
| ansible.builtin.shell: | | ||
| ibmcloud resource service-instances --service-name {{ target_instance_filter }} --output JSON | ||
| register: ibmcloud_instances | ||
| changed_when: false | ||
|  | ||
| - name: Filter for Cloud Monitoring instances with platform metrics | ||
| set_fact: | ||
| filtered_instances: "{{ ibmcloud_instances.stdout | from_json | json_query(query) }}" | ||
| vars: | ||
| query: "[?state=='active' && parameters.default_receiver==`true`].{Name: name, ID: guid, Region: region_id}" | ||
|  | ||
| - name: Fail if found IBM Cloud Monitoring instances with platform metrics | ||
| ansible.builtin.fail: | ||
| msg: | | ||
| Active IBM Cloud Monitoring instances with platform metrics enabled were found: | ||
| {{ filtered_instances }} | ||
| when: filtered_instances | length > 0 | ||
|  | ||
| - name: Inform if no IBM Cloud Monitoring instances were found | ||
| ansible.builtin.debug: | ||
| msg: "No active IBM Cloud Monitoring instances with platform metrics enabled were found." | ||
| when: filtered_instances | length == 0 | ||
| when: is_enabled | ||
| rescue: | ||
| - name: Fail with a specific error message | ||
| ansible.builtin.fail: | ||
| msg: "An unhandled error occurred in the primary block. Check previous task output for details." | ||
| always: | ||
| - name: Log out of IBM Cloud | ||
| ansible.builtin.shell: | | ||
| ibmcloud logout >/dev/null 2>&1 | ||
| changed_when: false | ||
| failed_when: false | ||
|  | ||
| - name: Skip due to environment variable | ||
| ansible.builtin.debug: | ||
| msg: "Skipping search for IBM Cloud Monitoring instances because 'enable_platform_metrics' is not set to 'true'." | ||
| when: not is_enabled | ||
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.