API yaml script to execute workflow

Last post 10-24-2019, 11:40 AM by TCarroll. 0 replies.
Sort Posts: Previous Next
  • API yaml script to execute workflow
    Posted: 10-24-2019, 11:40 AM

    I thought I would post this in case anyone needs a starting point. Would need minor changes to fit your envionement of course (Look for the uppercase words). This script executes a workflow that does a unix client install in our environment, but should be able to point to any workflow.

    Not the place to get into all of the Git/yaml/ansible specifics, but maybe someone can use this.

    Feedback welcome.

    ---
    
    #
    #
    # syntax: ansible-playbook SCRIPTNAME -e "target=HOSTNAME" -e "datacenter=DATACENTER"
    
    ###############################################################################
    #
    # Login 
    ###############################################################################
    - name: Run the playbook on the localhost
     hosts: localhost
     gather_facts: no
     tasks:
     - name: login
     uri:
     url: http://WEBSERVER:PORT/SearchSvc/CVWebService.svc/Login
     return_content: yes
     method: POST
     body: "{\"username\":\"USERNAME\",\"password\":\"ENC-PASSWORD\"}"
     force_basic_auth: yes
     status_code: 200
     body_format: json
     register: result
     no_log: true
    
    ###############################################################################
    #
    # Get token
    ###############################################################################
     - name: Parse token
     set_fact:
     api_token: "{{result.content|regex_search(tknrgx)|regex_replace('token=\"')|regex_replace('\"')}}"
     vars:
     tknrgx: '(token=\")\S*\s*\S*\"'
    
    ###############################################################################
    #
    # Main API
    ###############################################################################
     - name: Install Client
     uri:
     url: http://WEBSERVER:PORT/SearchSvc/CVWebService.svc/Workflow/WORKFLOWNAME/Action/Execute?outputOnly=true
     return_content: yes
     method: POST
     body: "{{lookup('template','templates/workflowbody.json.install')}}"
     force_basic_auth: yes
     headers:
     Authtoken: "{{api_token}}"
     status_code: 200
     timeout: 600 
     body_format: json
     register: resultapi
    
     - name: Print result
     debug:
     msg: "{{resultapi}}"
    

    Here is the template for the json body.
    {
     "Workflow_StartWorkflow": {
     "outputFormat": "1",
     "options": {
     "inputs": {
     "clientName": "{{ target }}",
     "hostName": "{{ target }}.DOMAIN.NAME"
     }
     }
     }
    }
    

The content of the forums, threads and posts reflects the thoughts and opinions of each author, and does not represent the thoughts, opinions, plans or strategies of Commvault Systems, Inc. ("Commvault") and Commvault undertakes no obligation to update, correct or modify any statements made in this forum. Any and all third party links, statements, comments, or feedback posted to, or otherwise provided by this forum, thread or post are not affiliated with, nor endorsed by, Commvault.
Commvault, Commvault and logo, the “CV” logo, Commvault Systems, Solving Forward, SIM, Singular Information Management, Simpana, Commvault Galaxy, Unified Data Management, QiNetix, Quick Recovery, QR, CommNet, GridStor, Vault Tracker, InnerVault, QuickSnap, QSnap, Recovery Director, CommServe, CommCell, SnapProtect, ROMS, and CommValue, are trademarks or registered trademarks of Commvault Systems, Inc. All other third party brands, products, service names, trademarks, or registered service marks are the property of and used to identify the products or services of their respective owners. All specifications are subject to change without notice.
Close
Copyright © 2019 Commvault | All Rights Reserved. | Legal | Privacy Policy